Пример #1
0
int CXXCircle::sortNodes(){
	if (theNodes.empty()) return 1;
	
	int initialNNodes = theNodes.size();
	//Deal with the special case that this circle has two nodes introduced that correspond to
	//arbitrarily chosen start and end points on a complete circuit
	if (initialNNodes == 2 &&
		theNodes.front().getFlag() == -1 &&
		theNodes.back().getFlag() == -1) {
		referenceUnitRadius = theNodes.begin()->getUnitRadius();
		theNodes.front().setAngle(0);
		theNodes.back().setFlag(2);
		theNodes.front().setAngle(2.*M_PI);
		theNodes.back().setFlag(1);
		return 0;
	}
    
    theNodes.remove_if(CXXCircleNode::shouldDelete);
	
    if (theNodes.size()%2) std::cout << "Seem to have non-even number of nodes (after trimming)\n";
	
	initialNNodes = theNodes.size();
    
    CXXCircleNode *startNode = 0;    
	//March round till we find an undeleted class2 node
    list<CXXCircleNode, CXX::CXXAlloc<CXXCircleNode> >::iterator nodesEnd = theNodes.end();
    for (list<CXXCircleNode, CXX::CXXAlloc<CXXCircleNode> >::iterator nodeIter = theNodes.begin();
         nodeIter != nodesEnd;
         ++nodeIter){
        CXXCircleNode &theNode(*nodeIter);
		if (theNode.isDeleted()==0) {
			if (theNode.getFlag()==2){
				startNode = &theNode;
			}
		}
	}
	if (startNode == 0) {
        if (theNodes.size()>0) std::cout << theNodes.size() << "nodes but no startpoint\n";
		theNodes.resize(0);
		return 0;
	}	
	referenceUnitRadius = startNode->getUnitRadius();
    
    nodesEnd = theNodes.end();
    for (list<CXXCircleNode, CXX::CXXAlloc<CXXCircleNode> >::iterator nodeIter = theNodes.begin();
         nodeIter != nodesEnd;
         ++nodeIter){
        CXXCircleNode &theNode(*nodeIter);
		if (&theNode == startNode) {
			theNode.setAngle(0.);
		}
		else  theNode.setReference(referenceUnitRadius);
	}			
	
    theNodes.sort(CXXCircleNode::angleLessThan);
	
	return 0;
}
Пример #2
0
	void CParserRelogin::Parse()
	{
		CXmlDocumentWrapper xml;
		xml.LoadXML(m_xml);

		CXmlNodeWrapper theNode(xml.AsNode());
		CString strResult = theNode.GetValue(_T("result"));
		if (strResult == _VB_SUCCESS)
			m_bLoginSuccess = TRUE;
		else
			m_bLoginSuccess = FALSE;

	}
Пример #3
0
int CXXCircle::newIdentifyArcs(){
	int nNodes = theNodes.size();
	
	//No arcs to upload if completely eaten
	if (getEaten() || nNodes==0) {
		theStarts.resize(0);
		theStops.resize(0);
		return 1;
	}	
	
	//If this is an intact orbit, then atomK will be zero, and the first two nodes are trivially the start and
	//Stop points
	mmdb::PAtom atomK(theNodes.begin()->getAtomK());
	if (!atomK && theNodes.size()>1){
		theStarts.push_back(&(*theNodes.begin()));
		theStops.push_back(&theNodes.back());
		return 0;
	}
	
    list<CXXCircleNode, CXX::CXXAlloc<CXXCircleNode> >::iterator nodesEnd = theNodes.end();
    for (list<CXXCircleNode, CXX::CXXAlloc<CXXCircleNode> >::iterator nodeIter = theNodes.begin();
         nodeIter != nodesEnd;
         ++nodeIter){
        CXXCircleNode &theNode(*nodeIter);

		//Tiptoe through the undeleted nodes
		if (theNode.isDeleted() == 0){
			if (theNode.getFlag() == 2){
				theStarts.push_back(&theNode);
			}
			else {
				theStops.push_back(&theNode);
			}
		}
	}
    if (theStarts.size() != theStops.size()) {
        std::cout << "uneven count of starts and stops\n";
        theStarts.resize(0);
    }
	return 0;
}
Пример #4
0
TMovieCue::TMovieCue(entry_ref &theRef, int16 id,  TCueChannel *parent, BRect bounds, uint32 startTime) : 
	TVisualCue(id, parent, bounds, startTime, "PictureCue")
{	
	// Init member variables 
	m_Editor		= NULL;
	m_File			= NULL;
	
	//
	// Attempt to load data file
	//
	
	BNode theNode(&theRef);
	if (theNode.InitCheck() != B_OK)
		return;
		
	BNodeInfo nodeInfo(&theNode);
	if (nodeInfo.InitCheck() != B_OK)
		return;

	// First, make sure we have a valid ref
	if ( IsVideo(nodeInfo) )
	{
		// 	Create a BMessage that includes the entry_ref to send to our open routine
		BMessage *theMessage = new BMessage(B_REFS_RECEIVED);
		theMessage->AddRef("refs", &theRef);
		
		bool retVal = LoadMovieFile(theMessage);
		
		// We are succesful.  Init the cue
		if (retVal)
		{
			Init();
		}
		// If we have an error, ask the user to locate a new data file
		else
		{
			ShowPanel();
		}
	}		
}
Пример #5
0
/**
 *  This method gets called when a tag needs to be sent out
 *
 *  @update  gess 3/25/98
 *  @param
 *  @return  result status
 */
nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsSubstring & aText,PRInt32 attrCount,PRBool aTagInError) {
  nsresult result=NS_OK;

  // adjust line number to what it will be after we finish writing this tag
  // XXXbz life here sucks.  We can't use the GetNewlineCount on the token,
  // because Text tokens in <style>, <script>, etc lie through their teeth.
  // On the other hand, the parser messes up newline counting in some token
  // types (bug 137315).  So our line numbers will disagree with the parser's
  // in some cases...
  // XXXbenjamn Shouldn't we be paying attention to the aCountLines BuildModel
  // parameter here?
  mLineNumber += aText.CountChar(PRUnichar('\n'));

  nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();
  NS_ASSERTION(0!=theAllocator,"Error: no allocator");
  if(0==theAllocator)
    return NS_ERROR_FAILURE;

  // Highlight all parts of all erroneous tags.
  if (mSyntaxHighlight && aTagInError) {
    CStartToken* theTagToken=
      static_cast<CStartToken*>
                 (theAllocator->CreateTokenOfType(eToken_start,
                                                     eHTMLTag_span,
                                                     NS_LITERAL_STRING("SPAN")));
    NS_ENSURE_TRUE(theTagToken, NS_ERROR_OUT_OF_MEMORY);
    mErrorNode.Init(theTagToken, theAllocator);
    AddAttrToNode(mErrorNode, theAllocator,
                  NS_LITERAL_STRING("class"),
                  NS_LITERAL_STRING("error"));
    mSink->OpenContainer(mErrorNode);
    IF_FREE(theTagToken, theAllocator);
#ifdef DUMP_TO_FILE
    if (gDumpFile) {
      fprintf(gDumpFile, "<span class=\"error\">");
    }
#endif
  }

  if (kBeforeText[aTagType][0] != 0) {
    NS_ConvertASCIItoUTF16 beforeText(kBeforeText[aTagType]);
    mITextToken.SetIndirectString(beforeText);
    nsCParserNode theNode(&mITextToken, 0/*stack token*/);
    mSink->AddLeaf(theNode);
  }
#ifdef DUMP_TO_FILE
  if (gDumpFile && kDumpFileBeforeText[aTagType][0])
    fprintf(gDumpFile, kDumpFileBeforeText[aTagType]);
#endif // DUMP_TO_FILE

  if (mSyntaxHighlight && aTagType != kText) {
    CStartToken* theTagToken=
      static_cast<CStartToken*>
                 (theAllocator->CreateTokenOfType(eToken_start,
                                                     eHTMLTag_span,
                                                     NS_LITERAL_STRING("SPAN")));
    NS_ENSURE_TRUE(theTagToken, NS_ERROR_OUT_OF_MEMORY);
    mStartNode.Init(theTagToken, theAllocator);
    AddAttrToNode(mStartNode, theAllocator,
                  NS_LITERAL_STRING("class"),
                  NS_ConvertASCIItoUTF16(kElementClasses[aTagType]));
    mSink->OpenContainer(mStartNode);  //emit <starttag>...
    IF_FREE(theTagToken, theAllocator);
#ifdef DUMP_TO_FILE
    if (gDumpFile) {
      fprintf(gDumpFile, "<span class=\"");
      fprintf(gDumpFile, kElementClasses[aTagType]);
      fprintf(gDumpFile, "\">");
    }
#endif // DUMP_TO_FILE
  }

  STOP_TIMER();

  mITextToken.SetIndirectString(aText);  //now emit the tag name...

  nsCParserNode theNode(&mITextToken, 0/*stack token*/);
  mSink->AddLeaf(theNode);
#ifdef DUMP_TO_FILE
  if (gDumpFile) {
    fputs(NS_ConvertUTF16toUTF8(aText).get(), gDumpFile);
  }
#endif // DUMP_TO_FILE

  if (mSyntaxHighlight && aTagType != kText) {
    mStartNode.ReleaseAll();
    mSink->CloseContainer(eHTMLTag_span);  //emit </endtag>...
#ifdef DUMP_TO_FILE
    if (gDumpFile)
      fprintf(gDumpFile, "</span>");
#endif //DUMP_TO_FILE
  }

  if(attrCount){
    result=WriteAttributes(aText, theAllocator, attrCount, aTagInError);
  }

  // Tokens are set in error if their ending > is not there, so don't output
  // the after-text
  if (!aTagInError && kAfterText[aTagType][0] != 0) {
    NS_ConvertASCIItoUTF16 afterText(kAfterText[aTagType]);
    mITextToken.SetIndirectString(afterText);
    nsCParserNode theNode(&mITextToken, 0/*stack token*/);
    mSink->AddLeaf(theNode);
  }
#ifdef DUMP_TO_FILE
  if (!aTagInError && gDumpFile && kDumpFileAfterText[aTagType][0])
    fprintf(gDumpFile, kDumpFileAfterText[aTagType]);
#endif // DUMP_TO_FILE

  if (mSyntaxHighlight && aTagInError) {
    mErrorNode.ReleaseAll();
    mSink->CloseContainer(eHTMLTag_span);  //emit </endtag>...
#ifdef DUMP_TO_FILE
    if (gDumpFile)
      fprintf(gDumpFile, "</span>");
#endif //DUMP_TO_FILE
  }

  START_TIMER();

  return result;
}
Пример #6
0
/**
  * The parser uses a code sandwich to wrap the parsing process. Before
  * the process begins, WillBuildModel() is called. Afterwards the parser
  * calls DidBuildModel().
  * @update gess5/18/98
  * @param  aFilename is the name of the file being parsed.
  * @return error code (almost always 0)
  */
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsITokenizer* aTokenizer,
                                          PRBool aCanInterrupt,
                                          PRBool aCountLines,
                                          const nsCString* aCharsetPtr)
{
  nsresult result=NS_OK;

  if(aTokenizer) {

    nsITokenizer*  oldTokenizer=mTokenizer;
    mTokenizer=aTokenizer;
    nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator();

    if(!mHasOpenRoot) {
      // For the stack-allocated tokens below, it's safe to pass a null
      // token allocator, because there are no attributes on the tokens.
      CStartToken htmlToken(NS_LITERAL_STRING("HTML"), eHTMLTag_html);
      nsCParserNode htmlNode(&htmlToken, 0/*stack token*/);
      mSink->OpenContainer(htmlNode);

      CStartToken headToken(NS_LITERAL_STRING("HEAD"), eHTMLTag_head);
      nsCParserNode headNode(&headToken, 0/*stack token*/);
      mSink->OpenContainer(headNode);

      CStartToken titleToken(NS_LITERAL_STRING("TITLE"), eHTMLTag_title);
      nsCParserNode titleNode(&titleToken, 0/*stack token*/);
      mSink->OpenContainer(titleNode);

      // Note that XUL will automatically add the prefix "Source of: "
      if (StringBeginsWith(mFilename, NS_LITERAL_STRING("data:")) &&
          mFilename.Length() > 50) {
        nsAutoString dataFilename(Substring(mFilename, 0, 50));
        dataFilename.AppendLiteral("...");
        CTextToken titleText(dataFilename);
        nsCParserNode titleTextNode(&titleText, 0/*stack token*/);
        mSink->AddLeaf(titleTextNode);
      } else {
        CTextToken titleText(mFilename);
        nsCParserNode titleTextNode(&titleText, 0/*stack token*/);
        mSink->AddLeaf(titleTextNode);
      }

      mSink->CloseContainer(eHTMLTag_title);

      if (theAllocator) {
        CStartToken* theToken=
          static_cast<CStartToken*>
                     (theAllocator->CreateTokenOfType(eToken_start,
                                                         eHTMLTag_link,
                                                         NS_LITERAL_STRING("LINK")));
        if (theToken) {
          nsCParserStartNode theNode(theToken, theAllocator);

          AddAttrToNode(theNode, theAllocator,
                        NS_LITERAL_STRING("rel"),
                        NS_LITERAL_STRING("stylesheet"));

          AddAttrToNode(theNode, theAllocator,
                        NS_LITERAL_STRING("type"),
                        NS_LITERAL_STRING("text/css"));

          AddAttrToNode(theNode, theAllocator,
                        NS_LITERAL_STRING("href"),
                        NS_LITERAL_STRING("resource://gre/res/viewsource.css"));

          mSink->AddLeaf(theNode);
        }
        IF_FREE(theToken, theAllocator);
      }

      result = mSink->CloseContainer(eHTMLTag_head);
      if(NS_SUCCEEDED(result)) {
        mHasOpenRoot = PR_TRUE;
      }
    }
    if (NS_SUCCEEDED(result) && !mHasOpenBody) {
      if (theAllocator) {
        CStartToken* bodyToken=
          static_cast<CStartToken*>
                     (theAllocator->CreateTokenOfType(eToken_start,
                                                         eHTMLTag_body,
                                                         NS_LITERAL_STRING("BODY")));
        if (bodyToken) {
          nsCParserStartNode bodyNode(bodyToken, theAllocator);

          AddAttrToNode(bodyNode, theAllocator,
                        NS_LITERAL_STRING("id"),
                        NS_ConvertASCIItoUTF16(kBodyId));

          if (mWrapLongLines) {
            AddAttrToNode(bodyNode, theAllocator,
                          NS_LITERAL_STRING("class"),
                          NS_ConvertASCIItoUTF16(kBodyClassWrap));
          }
          result = mSink->OpenContainer(bodyNode);
          if(NS_SUCCEEDED(result)) mHasOpenBody=PR_TRUE;
        }
        IF_FREE(bodyToken, theAllocator);

        if (NS_SUCCEEDED(result)) {
          CStartToken* preToken =
            static_cast<CStartToken*>
                       (theAllocator->CreateTokenOfType(eToken_start,
                                                           eHTMLTag_pre,
                                                           NS_LITERAL_STRING("PRE")));
          if (preToken) {
            nsCParserStartNode preNode(preToken, theAllocator);
            AddAttrToNode(preNode, theAllocator,
                          NS_LITERAL_STRING("id"),
                          NS_LITERAL_STRING("line1"));
            result = mSink->OpenContainer(preNode);
          } else {
            result = NS_ERROR_OUT_OF_MEMORY;
          }
          IF_FREE(preToken, theAllocator);
        }
      }
    }

    NS_ASSERTION(aCharsetPtr, "CViewSourceHTML::BuildModel expects a charset!");
    mCharset = *aCharsetPtr;

    NS_ASSERTION(aCanInterrupt, "CViewSourceHTML can't run scripts, so "
                 "document.write should not forbid interruptions. Why is "
                 "the parser telling us not to interrupt?");

    while(NS_SUCCEEDED(result)){
      CToken* theToken=mTokenizer->PopToken();
      if(theToken) {
        result=HandleToken(theToken);
        if(NS_SUCCEEDED(result)) {
          IF_FREE(theToken, mTokenizer->GetTokenAllocator());
          if (mSink->DidProcessAToken() == NS_ERROR_HTMLPARSER_INTERRUPTED) {
            result = NS_ERROR_HTMLPARSER_INTERRUPTED;
            break;
          }
        } else {
          mTokenizer->PushTokenFront(theToken);
        }
      }
      else break;
    }//while

    mTokenizer=oldTokenizer;
  }
  else result=NS_ERROR_HTMLPARSER_BADTOKENIZER;
  return result;
}
Пример #7
0
/*!
	@function	IndexedLineSetV2ToObject
	
	@abstract	Attempt to convert a VRML 2 IndexedLineSet node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	IndexedLineSetV2ToObject( PolyValue& ioNode )
{
	CQ3ObjectRef	theObject( Q3DisplayGroup_New() );
	ThrowIfNullQuesaOb_( theObject );
	
	// The VRML 2 spec says that lines are not lit.
	CQ3ObjectRef	theShader( Q3NULLIllumination_New() );
	ThrowIfNullQuesaOb_( theShader );
	Q3Group_AddObject( theObject.get(), theShader.get() );
	
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
	
	// Gather data from fields
	std::vector<TQ3Point3D>	thePoints;
	std::vector<TQ3ColorRGB>	theColors;
	PolyValue::IntVec		pointIndices;
	PolyValue::IntVec		colorIndices;
	
	GetNodeArray( theDict, "coord", "Coordinate", "point", thePoints );
	GetNodeArray( theDict, "color", "Color", "color", theColors );
	
	GetIntVecFromField( theDict, "coordIndex", pointIndices );
	GetIntVecFromField( theDict, "colorIndex", colorIndices );
	StandardizeIndexVector( pointIndices );
	StandardizeIndexVector( colorIndices );
	
	bool	isColorPerVertex = true;
	if (IsKeyPresent( theDict, "colorPerVertex" ))
	{
		PolyValue&	theNode( theDict[ "colorPerVertex" ] );
		if (theNode.GetType() == PolyValue::kDataTypeBool)
		{
			isColorPerVertex = theNode.GetBool();
		}
	}
	
	// Start building polylines
	std::vector<TQ3Vertex3D>	vertices;
	std::vector<CQ3ObjectRef>	vertAttSets;
	int	polylineNum = 0;
	
	for (unsigned int i = 0; i < pointIndices.size(); ++i)
	{
		if (pointIndices[i] < 0)
		{
			// FInish a PolyLine
			TQ3PolyLineData	polyData;
			polyData.numVertices = vertices.size();
			polyData.vertices = &vertices[0];
			polyData.segmentAttributeSet = NULL;
			CQ3ObjectRef	polyAtts;
			if ((not isColorPerVertex) and (not theColors.empty()))
			{
				TQ3ColorRGB	polyColor;
				if (colorIndices.empty())
				{
					polyColor = theColors[ polylineNum ];
				}
				else
				{
					polyColor = theColors[ colorIndices[polylineNum] ];
				}
				polyAtts = CQ3ObjectRef( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( polyAtts );
				Q3AttributeSet_Add( polyAtts.get(), kQ3AttributeTypeDiffuseColor,
					&polyColor );
				polyData.polyLineAttributeSet = polyAtts.get();
			}
			else
			{
				polyData.polyLineAttributeSet = NULL;
			}
			CQ3ObjectRef	polyLine( Q3PolyLine_New( &polyData ) );
			ThrowIfNullQuesaOb_( polyLine );
			Q3Group_AddObject( theObject.get(), polyLine.get() );
			vertices.clear();
			vertAttSets.clear();
			polylineNum += 1;
		}
		else
		{
			TQ3Vertex3D	aVertex;
			aVertex.point = thePoints[ pointIndices[i] ];
			if (isColorPerVertex and (not theColors.empty()))
			{
				TQ3ColorRGB	vertColor;
				if (colorIndices.empty())
				{
					vertColor = theColors[ pointIndices[i] ];
				}
				else
				{
					vertColor = theColors[ colorIndices[i] ];
				}
				CQ3ObjectRef	vertAtts( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( vertAtts );
				Q3AttributeSet_Add( vertAtts.get(), kQ3AttributeTypeDiffuseColor,
					&vertColor );
				vertAttSets.push_back( vertAtts );
				aVertex.attributeSet = vertAtts.get();
			}
			else
			{
				aVertex.attributeSet = NULL;
			}
			vertices.push_back( aVertex );
		}
	}
	
	if (polylineNum == 0)
	{
		// no sense returning an empty display group
		theObject = CQ3ObjectRef();
	}
	
	
	return theObject;
}