1
0
Fork 0

- remove unused ssgSelector

- add function to remove models
This commit is contained in:
mfranz 2006-03-20 17:32:56 +00:00
parent f3cdd7d44a
commit 3b977ee40e
2 changed files with 29 additions and 5 deletions

View file

@ -28,8 +28,7 @@ SG_USING_STD(vector);
FGModelMgr::FGModelMgr () FGModelMgr::FGModelMgr ()
: _models(fgGetNode("/models", true)), : _models(fgGetNode("/models", true)),
_listener(new Listener(this)), _listener(new Listener(this))
_selector(new ssgSelector)
{ {
_models->addChangeListener(_listener); _models->addChangeListener(_listener);
@ -69,6 +68,7 @@ FGModelMgr::add_model (SGPropertyNode * node)
Instance * instance = new Instance; Instance * instance = new Instance;
SGModelPlacement *model = new SGModelPlacement; SGModelPlacement *model = new SGModelPlacement;
instance->model = model; instance->model = model;
instance->node = node;
ssgBranch *object ssgBranch *object
= sgLoad3DModel( globals->get_fg_root(), = sgLoad3DModel( globals->get_fg_root(),
node->getStringValue("path", node->getStringValue("path",
@ -198,6 +198,7 @@ FGModelMgr::draw ()
FGModelMgr::Instance::Instance () FGModelMgr::Instance::Instance ()
: model(0), : model(0),
node(0),
lon_deg_node(0), lon_deg_node(0),
lat_deg_node(0), lat_deg_node(0),
elev_ft_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<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 // end of modelmgr.cxx

View file

@ -18,7 +18,6 @@
SG_USING_STD(vector); SG_USING_STD(vector);
// Don't pull in headers, since we don't need them here. // Don't pull in headers, since we don't need them here.
class ssgSelector;
class SGPropertyNode; class SGPropertyNode;
class SGModelPlacement; class SGModelPlacement;
@ -48,6 +47,7 @@ public:
Instance (); Instance ();
virtual ~Instance (); virtual ~Instance ();
SGModelPlacement * model; SGModelPlacement * model;
SGPropertyNode_ptr node;
SGPropertyNode_ptr lon_deg_node; SGPropertyNode_ptr lon_deg_node;
SGPropertyNode_ptr lat_deg_node; SGPropertyNode_ptr lat_deg_node;
SGPropertyNode_ptr elev_ft_node; SGPropertyNode_ptr elev_ft_node;
@ -99,6 +99,7 @@ private:
public: public:
Listener(FGModelMgr *mgr) : _mgr(mgr) {} Listener(FGModelMgr *mgr) : _mgr(mgr) {}
virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child); virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
private: private:
FGModelMgr * _mgr; FGModelMgr * _mgr;
@ -109,8 +110,6 @@ private:
vector<Instance *> _instances; vector<Instance *> _instances;
ssgSharedPtr<ssgSelector> _selector;
}; };
#endif // __MODELMGR_HXX #endif // __MODELMGR_HXX