Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

SceneToFileCoreVisitor.cpp

Go to the documentation of this file.
00001 #include "SceneToFileCoreVisitor.h"
00002 #include "Scene.h"
00003 #include "X3DNode.h"
00004 #include "X3DTypesToSFString.h"
00005 
00006 #include <iostream>
00007 
00008 using namespace X3DTK;
00009 using namespace std;
00010 
00011 SceneToFileCoreVisitor::SceneToFileCoreVisitor()
00012 : CoreVisitor()
00013 {
00014   // Enter functions.
00015   defineNewEnterFunction<SceneToFileCoreVisitor, X3DNode>(&SceneToFileCoreVisitor::enterX3DNode);
00016   // Walk on functions.
00017   defineNewWalkOnFunction<SceneToFileCoreVisitor, X3DNode>(&SceneToFileCoreVisitor::walkOnX3DNode);
00018 
00019   // Leave functions.
00020   defineNewLeaveFunction<SceneToFileCoreVisitor, X3DNode>(&SceneToFileCoreVisitor::leaveX3DNode);
00021 
00022   // GlobalVariables assignation.
00023   globalVariables = GVManager::getInstanceOf<SceneToFileGlobalVariables>();
00024 }
00025 
00026 SceneToFileCoreVisitor::~SceneToFileCoreVisitor()
00027 {
00028 }
00029 
00030 void SceneToFileCoreVisitor::enterX3DNode(X3DNode *N) const
00031 {
00032   SFString attr;
00033   SFString USE = globalVariables->getUSE(N);
00034 
00035   globalVariables->newLine();
00036   globalVariables->pushCurrentLine();  
00037   
00038   if (USE != "")
00039   {
00040     attr += USE;
00041     globalVariables->pushHasUSE(true);
00042     globalVariables->writeCurrentLine("<" + N->getTypeName() + attr);
00043   }
00044   else
00045   {
00046     attr += globalVariables->getDEF(N);
00047     globalVariables->pushHasUSE(false);    
00048     globalVariables->writeCurrentLine("<" + N->getTypeName() + attr + N->writeAttributes());    
00049   } 
00050 
00051   globalVariables->addTab();
00052 }
00053 
00054 bool SceneToFileCoreVisitor::walkOnX3DNode(X3DNode *N, SFNode Child) const
00055 {
00056   //return true;
00057   return !(globalVariables->getHasUSE());  
00058 }
00059 
00060 void SceneToFileCoreVisitor::leaveX3DNode(X3DNode *N) const
00061 {
00062   globalVariables->removeTab();
00063   
00064   if (globalVariables->hasChild())
00065     globalVariables->writeOpeningLine("/>");  
00066   else
00067   {
00068     globalVariables->writeOpeningLine(">");
00069     globalVariables->newLine();
00070     globalVariables->writeCurrentLine("</" + N->getTypeName() + ">");
00071   }  
00072   
00073   globalVariables->popLine();
00074   globalVariables->popHasUSE();  
00075 }
00076 

Generated on Wed May 14 10:03:11 2003 for X3DToolKit by doxygen1.3