//---------------------------------------------------------------------------------------------------------------------- void RibExport::WorldEnd() { --m_tabs; WriteTabs(); m_ribFile<<"WorldEnd "<<std::endl; --m_worldCount; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::TransformEnd() { --m_tabs; WriteTabs(); m_ribFile<<"TransformEnd "<<std::endl; --m_transformCount; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::AttributeBegin() { WriteTabs(); m_ribFile<<"AttributeBegin "<<std::endl; ++m_tabs; ++m_attribCount; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::AttributeEnd() { --m_tabs; WriteTabs(); m_ribFile<<"AttributeEnd "<<std::endl; m_attribCount--; }
//---------------------------------------------------------------------------// // WriteOpen // //---------------------------------------------------------------------------// void CNodeFile::WriteNode(const string &sName, const string &sAttribs, bool bValue) { WriteTabs(m_Nodes.size()); char pBuffer[512]; sprintf_s(pBuffer, 512, "<%s %s>%d</%s>\r\n", sName.c_str(), sAttribs.c_str(), bValue ? 1 : 0, sName.c_str()); m_OutFile.WriteLn(pBuffer); }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::WriteToFile( std::string _string ) { WriteTabs(); m_ribFile<<_string<<std::endl; }
//---------------------------------------------------------------------------// // WriteOpen // //---------------------------------------------------------------------------// void CNodeFile::WriteOpenNode(const string &sName, const string &sAttribs) { WriteTabs(m_Nodes.size()); string sLine = "<" + sName + " " + sAttribs + ">\r\n"; m_OutFile.WriteLn(sLine.c_str()); m_Nodes.push(sName); }
nsresult nsLoggingSink::OpenNode(const char* aKind, const nsIParserNode& aNode) { WriteTabs(mOutput,++mLevel); PR_fprintf(mOutput,"<open container="); nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); if ((nodeType >= eHTMLTag_unknown) && (nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) { const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType); PR_fprintf(mOutput, "\"%s\"", NS_ConvertUTF16toUTF8(tag).get()); } else { char* text = nsnull; GetNewCString(aNode.GetText(), &text); if(text) { PR_fprintf(mOutput, "\"%s\"", text); nsMemory::Free(text); } } if (WillWriteAttributes(aNode)) { PR_fprintf(mOutput, ">\n"); WriteAttributes(aNode); PR_fprintf(mOutput, "</open>\n"); } else { PR_fprintf(mOutput, ">\n"); } return NS_OK; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::WorldBegin() { WriteTabs(); m_ribFile<<"WorldBegin "<<std::endl; ++m_tabs; ++m_worldCount; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::TransformBegin() { WriteTabs(); m_ribFile<<"TransformBegin "<<std::endl; ++m_tabs; ++m_transformCount; }
//---------------------------------------------------------------------------// // WriteOpen // //---------------------------------------------------------------------------// void CNodeFile::WriteCloseNode() { string sName = m_Nodes.top(); m_Nodes.pop(); WriteTabs(m_Nodes.size()); string sLine = "</" + sName + ">\r\n"; m_OutFile.WriteLn(sLine.c_str()); }
nsresult nsLoggingSink::WriteAttributes(const nsIParserNode& aNode) { WriteTabs(mOutput,1+mLevel); nsAutoString tmp; PRInt32 ac = aNode.GetAttributeCount(); for (PRInt32 i = 0; i < ac; ++i) { char* key=nsnull; char* value=nsnull; const nsAString& k = aNode.GetKeyAt(i); const nsAString& v = aNode.GetValueAt(i); GetNewCString(k, &key); if(key) { PR_fprintf(mOutput, " <attr key=\"%s\" value=\"", key); nsMemory::Free(key); } tmp.Truncate(); tmp.Append(v); if(!tmp.IsEmpty()) { PRUnichar first = tmp.First(); if ((first == '"') || (first == '\'')) { if (tmp.Last() == first) { tmp.Cut(0, 1); PRInt32 pos = tmp.Length() - 1; if (pos >= 0) { tmp.Cut(pos, 1); } } else { // Mismatched quotes - leave them in } } GetNewCString(tmp, &value); if(value) { PR_fprintf(mOutput, "%s\"/>\n", value); WriteTabs(mOutput,1+mLevel); nsMemory::Free(value); } } } WriteTabs(mOutput,1+mLevel); return NS_OK; }
nsresult nsLoggingSink::LeafNode(const nsIParserNode& aNode) { WriteTabs(mOutput,1+mLevel); nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); if ((nodeType >= eHTMLTag_unknown) && (nodeType <= nsHTMLTag(NS_HTML_TAG_MAX))) { const PRUnichar* tag = nsHTMLTags::GetStringValue(nodeType); if(tag) PR_fprintf(mOutput, "<leaf tag=\"%s\"", NS_ConvertUTF16toUTF8(tag).get()); else PR_fprintf(mOutput, "<leaf tag=\"???\""); if (WillWriteAttributes(aNode)) { PR_fprintf(mOutput, ">\n"); WriteAttributes(aNode); PR_fprintf(mOutput, "</leaf>\n"); } else { PR_fprintf(mOutput, "/>\n"); } } else { PRInt32 pos; nsAutoString tmp; char* str = nsnull; switch (nodeType) { case eHTMLTag_whitespace: case eHTMLTag_text: GetNewCString(aNode.GetText(), &str); if(str) { PR_fprintf(mOutput, "<text value=\"%s\"/>\n", str); nsMemory::Free(str); } break; case eHTMLTag_newline: PR_fprintf(mOutput, "<newline/>\n"); break; case eHTMLTag_entity: tmp.Append(aNode.GetText()); tmp.Cut(0, 1); pos = tmp.Length() - 1; if (pos >= 0) { tmp.Cut(pos, 1); } PR_fprintf(mOutput, "<entity value=\"%s\"/>\n", NS_LossyConvertUTF16toASCII(tmp).get()); break; default: NS_NOTREACHED("unsupported leaf node type"); }//switch } return NS_OK; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Hyperboloid( const Real _p1, const Real _p2, const Real _sweep ) { WriteTabs(); m_ribFile<<"Hyperboloid "<<_p1<<" "<<_p2<<" "<<_sweep<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Disk( const Real _height, const Real _radius, const Real _sweep ) { WriteTabs(); m_ribFile<<"Disk "<<_height<<" "<<_radius<<" "<<_sweep<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Scale( const Real _x, const Real _y, const Real _z ) { WriteTabs(); m_ribFile<<"Scale "<<_x<<" "<<_y<<" "<<_z<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Translate( const Real _x, const Real _y, const Real _z ) { WriteTabs(); m_ribFile<<"Translate "<<_x<<" "<<_y<<" "<<_z<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Paraboloid( const Real _topRad, const Real _zMin, const Real _zMax, const Real _sweep ) { WriteTabs(); m_ribFile<<"Paraboloid "<<_topRad<<" "<<_zMin<<" "<<_zMax<<" "<<_sweep<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Rotate( const Real _angle, const Real _x, const Real _y, const Real _z ) { WriteTabs(); m_ribFile<<"Rotate "<<_angle<<" "<<_x<<" "<<_y<<" "<<_z<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Sphere( const Real _radius, const Real _zMin, const Real _zMax, const Real _sweep ) { WriteTabs(); m_ribFile<<"Sphere "<<_radius<<" "<<_zMin<<" "<<_zMax<<" "<<_sweep<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Cylinder( const Real _radius, const Real _zMin, const Real _zMax, const Real _sweep ) { WriteTabs(); m_ribFile<<"Cylinder "<<_radius<<" "<<_zMin<<" "<<_zMax<<" "<<_sweep<<std::endl; }
//---------------------------------------------------------------------------------------------------------------------- void RibExport::Torus( const Real _major, const Real _minor, const Real _phiMin, const Real _phiMax, const Real _sweep ) { WriteTabs(); m_ribFile<<"Torus "<<_major<<" "<<_minor<<" "<<_phiMin<<" "<<_phiMax<<" "<<_sweep<<std::endl; }
NS_IMETHODIMP nsLoggingSink::WillBuildModel() { WriteTabs(mOutput,++mLevel); PR_fprintf(mOutput, "<begin>\n"); //proxy the call to the real sink if you have one. if(mSink) { mSink->WillBuildModel(); } return NS_OK; }
NS_IMETHODIMP nsLoggingSink::OpenHead() { WriteTabs(mOutput,++mLevel); PR_fprintf(mOutput,"<open container=head>\n"); nsresult theResult=NS_OK; //then proxy the call to the real sink if you have one. if(mSink) { theResult=mSink->OpenHead(); } return theResult; }
NS_IMETHODIMP nsLoggingSink::DidBuildModel() { WriteTabs(mOutput,--mLevel); PR_fprintf(mOutput, "</begin>\n"); //proxy the call to the real sink if you have one. nsresult theResult=NS_OK; if(mSink) { theResult=mSink->DidBuildModel(); } return theResult; }
nsresult nsLoggingSink::CloseNode(const char* aKind) { WriteTabs(mOutput,mLevel--); PR_fprintf(mOutput, "<close container=\"%s\">\n", aKind); return NS_OK; }
/* ================ rvGEWorkspace::WriteWindow Writes the contents of the given window to the file ================ */ bool rvGEWorkspace::WriteWindow(idFile *file, int depth, idWindow *window) { idStr out; rvGEWindowWrapper *wrapper; int i; wrapper = rvGEWindowWrapper::GetWrapper(window); if (!wrapper) { return true; } if (wrapper->IsDeleted()) { return true; } // Window def header WriteTabs(file, depth - 1); out = wrapper->WindowTypeToString(wrapper->GetWindowType()); out.Append(" "); file->Write(out, out.Length()); out = window->GetName(); file->Write(out, out.Length()); file->Write("\r\n", 2); WriteTabs(file, depth - 1); out = "{\r\n"; file->Write(out, out.Length()); file->ForceFlush(); for (i = 0; i < wrapper->GetStateDict().GetNumKeyVals(); i ++) { const idKeyValue *key = wrapper->GetStateDict().GetKeyVal(i); // Dont write name to the files if (!key->GetKey().Icmp("name")) { continue; } WriteTabs(file, depth); out = key->GetKey(); out.Append("\t"); file->Write(out, out.Length()); const char *p; for (p = key->GetValue().c_str(); *p; p ++) { switch (*p) { case '\n': file->Write("\\n", 2); break; default: file->Write(p, 1); break; } } file->Write("\r\n", 2); } for (i = 0; i < wrapper->GetVariableDict().GetNumKeyVals(); i ++) { const idKeyValue *key = wrapper->GetVariableDict().GetKeyVal(i); WriteTabs(file, depth); out = key->GetKey(); out.Append("\t"); out.Append(key->GetValue()); out.Append("\r\n"); file->Write(out, out.Length()); } if (wrapper->GetScriptDict().GetNumKeyVals()) { file->Write("\r\n", 2); } for (i = 0; i < wrapper->GetScriptDict().GetNumKeyVals(); i ++) { const idKeyValue *key = wrapper->GetScriptDict().GetKeyVal(i); WriteTabs(file, depth); file->Write(key->GetKey(), key->GetKey().Length()); file->Write(" ", 1); idLexer src(key->GetValue(), key->GetValue().Length(), "", LEXFL_ALLOWMULTICHARLITERALS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWBACKSLASHSTRINGCONCAT); src.ParseBracedSectionExact(out, depth + 1); file->Write(out, out.Length()); file->Write("\r\n", 2); file->Write("\r\n", 2); } for (i = 0; i < wrapper->GetChildCount(); i ++) { idWindow *child = wrapper->GetChild(i); WriteWindow(file, depth + 1, child); } // Window def footer WriteTabs(file, depth - 1); out = "}\r\n"; file->Write(out, out.Length()); file->ForceFlush(); return true; }