diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 4d299fbab..86ae8c23b 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -28,8 +28,7 @@ SG_USING_STD(vector); FGModelMgr::FGModelMgr () : _models(fgGetNode("/models", true)), - _listener(new Listener(this)), - _selector(new ssgSelector) + _listener(new Listener(this)) { _models->addChangeListener(_listener); @@ -69,6 +68,7 @@ FGModelMgr::add_model (SGPropertyNode * node) Instance * instance = new Instance; SGModelPlacement *model = new SGModelPlacement; instance->model = model; + instance->node = node; ssgBranch *object = sgLoad3DModel( globals->get_fg_root(), node->getStringValue("path", @@ -198,6 +198,7 @@ FGModelMgr::draw () FGModelMgr::Instance::Instance () : model(0), + node(0), lon_deg_node(0), lat_deg_node(0), elev_ft_node(0), @@ -234,4 +235,28 @@ FGModelMgr::Listener::childAdded(SGPropertyNode * parent, SGPropertyNode * child } } +void +FGModelMgr::Listener::childRemoved(SGPropertyNode * parent, SGPropertyNode * child) +{ + if (strcmp(parent->getName(), "models") || strcmp(child->getName(), "model")) + return; + + // search instance by node and remove it from scenegraph + vector::iterator it = _mgr->_instances.begin(); + vector::iterator end = _mgr->_instances.end(); + + for (; it != end; ++it) { + Instance *instance = *it; + if (instance->node != child) + continue; + + _mgr->_instances.erase(it); + globals->get_scenery()->get_scene_graph() + ->removeKid(instance->model->getSceneGraph()); + + delete instance; + break; + } +} + // end of modelmgr.cxx diff --git a/src/Model/modelmgr.hxx b/src/Model/modelmgr.hxx index 0bb286b5d..b1956e3f6 100644 --- a/src/Model/modelmgr.hxx +++ b/src/Model/modelmgr.hxx @@ -18,7 +18,6 @@ SG_USING_STD(vector); // Don't pull in headers, since we don't need them here. -class ssgSelector; class SGPropertyNode; class SGModelPlacement; @@ -48,6 +47,7 @@ public: Instance (); virtual ~Instance (); SGModelPlacement * model; + SGPropertyNode_ptr node; SGPropertyNode_ptr lon_deg_node; SGPropertyNode_ptr lat_deg_node; SGPropertyNode_ptr elev_ft_node; @@ -99,6 +99,7 @@ private: public: Listener(FGModelMgr *mgr) : _mgr(mgr) {} virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child); + virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child); private: FGModelMgr * _mgr; @@ -109,8 +110,6 @@ private: vector _instances; - ssgSharedPtr _selector; - }; #endif // __MODELMGR_HXX