#include "X3D_GLBuilderStateVariables.h" #include #include using namespace std; namespace X3DTK { namespace X3D { GLBuilderStateVariables::GLBuilderStateVariables() : StateVariables(), _root(0) { _cwd = (char *)malloc(65535); } GLBuilderStateVariables::~GLBuilderStateVariables() { free(_cwd); } void GLBuilderStateVariables::init() { _root = 0; _nodeStack.push_front(0); // Goes to the directory of the file. char *value = getcwd(_cwd, 65535); if (value == 0) { cx3d << "GLBuilderStateVariables::init: unable to get current working directory!" << endl; return; } } void GLBuilderStateVariables::finish() { // Returns to the initial directory. if ((_cwd != 0) && (chdir(_cwd) != 0)) cx3d << "GLBuilderStateVariables::finish: unable to set the current working directory to !" << _cwd << endl; _nodeStack.clear(); _nodeCoupleMap.clear(); } void GLBuilderStateVariables::addCoupleNode(SFNode N, GL::X3DNode *GN) { _nodeCoupleMap[N] = GN; // init root node. if (_root == 0) _root = GN; } void GLBuilderStateVariables::pushNode(GL::X3DNode *N) { GL::X3DNode *T = getTop(); if (T != 0) T->setChild(N); // filling the stack. _nodeStack.push_front(N); } void GLBuilderStateVariables::popNode() { _nodeStack.pop_front(); } GL::X3DNode *GLBuilderStateVariables::getNode(SFNode N) const { map::const_iterator it = _nodeCoupleMap.find(N); if (it != _nodeCoupleMap.end()) return (*it).second; return 0; } } }