#include "X3D_Creator.h" #include "X3D_X3DComponentCreator.h" #include "SFType.h" #include "SFComponent.h" #include "X3D_CoreCreator.h" #include "X3D_Geometry3DCreator.h" #include "X3D_GroupingCreator.h" #include "X3D_RenderingCreator.h" #include "X3D_ShapeCreator.h" #include "X3D_TexturingCreator.h" #include "X3D_InterpolationCreator.h" #include "X3D_LightingCreator.h" #include "X3D_NURBSCreator.h" #include "X3D_NetworkingCreator.h" #include "X3D_NavigationCreator.h" #include #include using namespace std; namespace X3DTK { namespace X3D { Creator::Creator() : X3DActor() { setComponentCreator(new X3D::CoreCreator()); setComponentCreator(new X3D::Geometry3DCreator()); setComponentCreator(new X3D::GroupingCreator()); setComponentCreator(new X3D::RenderingCreator()); setComponentCreator(new X3D::ShapeCreator()); setComponentCreator(new X3D::TexturingCreator()); setComponentCreator(new X3D::InterpolationCreator()); setComponentCreator(new X3D::LightingCreator()); setComponentCreator(new X3D::NURBSCreator()); setComponentCreator(new X3D::NetworkingCreator()); setComponentCreator(new X3D::NavigationCreator()); } Creator::~Creator() { if (autoDelete) for (list::iterator it = _componentList.begin(); it != _componentList.end(); ++it) { (*it)->removeOneActor(); if ((*it)->getActorNumber() == 0) delete *it; } } void Creator::setComponentCreator(X3DComponentCreator *component) { if (component->getComponent()->getSceneGraphName() != "X3D") { cx3d << "Creator::setComponentCreator: trying to insert the component creator of " << component->getComponent()->getName() << " of " << component->getComponent()->getSceneGraphName() << " scene graph that is not allowed!" << endl; return; } //replace the equivalent component. X3DComponentCreator *replacedComponent = 0; bool replaced = false; for (list::iterator it = _componentList.begin(); it != _componentList.end(); ++it) { if ((*it)->getName() == component->getName()) { replacedComponent = *it; *it = component; replacedComponent->removeOneActor(); component->addOneActor(); replaced = true; } } if (!replaced) { _componentList.push_back(component); component->addOneActor(); } else { // removing old functions present in the replacedComponent CreationDict componentCreationDict = replacedComponent->getCreationDict(); for (CreationDict::iterator it = componentCreationDict.begin(); it != componentCreationDict.end(); ++it) _creationDict.erase((*it).first); } //remove replaced component. if ((autoDelete) && (replacedComponent != 0) && (replacedComponent->getActorNumber() == 0)) delete replacedComponent; //adding new functions CreationDict componentCreationDict = component->getCreationDict(); for (CreationDict::const_iterator nf = componentCreationDict.begin(); nf != componentCreationDict.end(); ++nf) _creationDict[(*nf).first] = (*nf).second; } X3D::X3DNode *Creator::createFromName(const SFString &name) const { CreationDict::const_iterator it = _creationDict.find(name); if (it != _creationDict.end()) return static_cast((*it).second->create()); cx3d << "warning: " << name << " node not implemented!" << endl; return 0; } void Creator::reset() { //remove components if (autoDelete) for (list::iterator it = _componentList.begin(); it != _componentList.end(); ++it) { (*it)->removeOneActor(); if ((*it)->getActorNumber() == 0) delete *it; } _creationDict.clear(); _componentList.clear(); } SFString Creator::getComponentNameOf(const SFString &name) const { //iterating the list of component. for (list::const_iterator it = _componentList.begin(); it != _componentList.end(); ++it) { if ((*it)->contains(name)) return (*it)->getName(); } //not found! return ""; } CreationFunction *Creator::getCreationFunctionOf(const SFString &name) const { CreationFunction *CF = 0; for (list::const_iterator it = _componentList.begin(); it != _componentList.end(); ++it) { CF = (*it)->getCreationFunctionOf(name); if (CF != 0) break; } return CF; } Creator *joinCreator(Creator *N0, Creator *N1) { Creator *N = new Creator(); for (list::const_iterator i = N0->_componentList.begin(); i != N0->_componentList.end(); ++i) N->setComponentCreator(*i); for (list::const_iterator j = N1->_componentList.begin(); j != N1->_componentList.end(); ++j) N->setComponentCreator(*j); return N; } } }