00001 #include "SceneToFileGlobalVariables.h"
00002 #include "X3DAbstractNode.h"
00003
00004 using namespace X3DTK;
00005 using namespace std;
00006
00007 SceneToFileGlobalVariables::SceneToFileGlobalVariables()
00008 : GlobalVariables(), _lineNumber(-1), _tab(" ")
00009 {
00010 }
00011
00012 SceneToFileGlobalVariables::~SceneToFileGlobalVariables()
00013 {
00014 }
00015
00016 void SceneToFileGlobalVariables::pushHasUSE(bool value)
00017 {
00018 _hasUSEStack.push_front(value);
00019 }
00020
00021 void SceneToFileGlobalVariables::newLine()
00022 {
00023 ++_lineNumber;
00024 SFString l;
00025 _output.push_back(SFString(_tab));
00026 }
00027
00028 void SceneToFileGlobalVariables::pushCurrentLine()
00029 {
00030 _lineStack.push_front(_lineNumber);
00031 }
00032
00033 void SceneToFileGlobalVariables::writeCurrentLine(const SFString &string)
00034 {
00035 _output.back() += string;
00036 }
00037
00038 void SceneToFileGlobalVariables::writeOpeningLine(const SFString &string)
00039 {
00040 _output[_lineStack.front()] += string;
00041 }
00042
00043 void SceneToFileGlobalVariables::addTab()
00044 {
00045 _tab += " ";
00046 }
00047
00048 void SceneToFileGlobalVariables::removeTab()
00049 {
00050 _tab.erase(0, 2);
00051 }
00052
00053 bool SceneToFileGlobalVariables::hasChild()
00054 {
00055 return (_lineNumber == _lineStack.front());
00056 }
00057
00058 void SceneToFileGlobalVariables::popHasUSE()
00059 {
00060 _hasUSEStack.pop_front();
00061 }
00062
00063 void SceneToFileGlobalVariables::popLine()
00064 {
00065 _lineStack.pop_front();
00066 }
00067
00068 SFString SceneToFileGlobalVariables::getDEF(const SFNode &N)
00069 {
00070
00071 SFString DEF = X3DAbstractNode::DEFDict.getNameOfNode(N);
00072 if (DEF == "")
00073 return "";
00074
00075
00076
00077 bool found = false;
00078 for (list<SFString>::const_iterator it = _DEFList.begin(); it != _DEFList.end(); ++it)
00079 if (*it == DEF)
00080 {
00081 found = true;
00082 break;
00083 }
00084
00085 if (!found)
00086 {
00087 _DEFList.push_back(DEF);
00088 return SFString(" DEF=\"") + DEF + "\"";
00089 }
00090 return "";
00091 }
00092
00093 SFString SceneToFileGlobalVariables::getUSE(const SFNode &N) const
00094 {
00095
00096 SFString DEF = X3DAbstractNode::DEFDict.getNameOfNode(N);
00097 if (DEF == "")
00098 return "";
00099
00100 bool found = false;
00101 for (list<SFString>::const_iterator it = _DEFList.begin(); it != _DEFList.end(); ++it)
00102 if (*it == DEF)
00103 {
00104 found = true;
00105 break;
00106 }
00107
00108 if (found)
00109 return SFString(" USE=\"") + DEF + "\"";
00110
00111 return "";
00112 }