FGModelMgr::FGModelMgr ()
: _models(fgGetNode("/models", true)),
- _listener(new Listener(this)),
- _selector(new ssgSelector)
+ _listener(new Listener(this))
{
_models->addChangeListener(_listener);
Instance * instance = new Instance;
SGModelPlacement *model = new SGModelPlacement;
instance->model = model;
+ instance->node = node;
ssgBranch *object
= sgLoad3DModel( globals->get_fg_root(),
node->getStringValue("path",
FGModelMgr::Instance::Instance ()
: model(0),
+ node(0),
lon_deg_node(0),
lat_deg_node(0),
elev_ft_node(0),
}
}
+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<Instance *>::iterator it = _mgr->_instances.begin();
+ vector<Instance *>::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
SG_USING_STD(vector);
// Don't pull in headers, since we don't need them here.
-class ssgSelector;
class SGPropertyNode;
class SGModelPlacement;
Instance ();
virtual ~Instance ();
SGModelPlacement * model;
+ SGPropertyNode_ptr node;
SGPropertyNode_ptr lon_deg_node;
SGPropertyNode_ptr lat_deg_node;
SGPropertyNode_ptr elev_ft_node;
public:
Listener(FGModelMgr *mgr) : _mgr(mgr) {}
virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
+ virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
private:
FGModelMgr * _mgr;
vector<Instance *> _instances;
- ssgSharedPtr<ssgSelector> _selector;
-
};
#endif // __MODELMGR_HXX