From 7aba4333a261df723fcbe9eaf86c16af89372595 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 4 Jul 2010 23:03:05 +0100 Subject: [PATCH] Reset - instruments can be re-inited now (reloads XML files) --- src/Instrumentation/gps.cxx | 6 +- src/Instrumentation/instrument_mgr.cxx | 77 +++++++++++++++----------- src/Instrumentation/instrument_mgr.hxx | 9 ++- 3 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index afee154f3..06647d4ad 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -145,10 +145,10 @@ public: DeprecatedPropListener(SGPropertyNode* gps) { _parents.insert(gps); - SGPropertyNode* wp = gps->getChild("wp"); + SGPropertyNode* wp = gps->getChild("wp", 0, true); _parents.insert(wp); - _parents.insert(wp->getChild("wp", 0)); - _parents.insert(wp->getChild("wp", 1)); + _parents.insert(wp->getChild("wp", 0, true)); + _parents.insert(wp->getChild("wp", 1, true)); std::set::iterator it; for (it = _parents.begin(); it != _parents.end(); ++it) { diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index 27f5e3948..646d3fba0 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -56,45 +56,60 @@ FGInstrumentMgr::FGInstrumentMgr () : { set_subsystem("od_gauge", new FGODGauge); set_subsystem("hud", new HUD); +} - SGPropertyNode_ptr config_props = new SGPropertyNode; - - SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path"); - - if (path_n) { - SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); - - SG_LOG( SG_ALL, SG_INFO, "Reading instruments from " - << config.str() ); - try { - readProperties( config.str(), config_props ); +FGInstrumentMgr::~FGInstrumentMgr () +{ +} - if ( !build(config_props) ) { - throw sg_error( +void FGInstrumentMgr::init() +{ + SGPropertyNode_ptr config_props = new SGPropertyNode; + SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path"); + if (!path_n) { + SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!"); + return; + } + + SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); + SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() ); + + try { + readProperties( config.str(), config_props ); + if (!build(config_props)) { + throw sg_error( "Detected an internal inconsistency in the instrumentation\n" "system specification file. See earlier errors for details."); - } - } catch (const sg_exception&) { - SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: " + } + } catch (const sg_exception&) { + SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: " << config.str() ); - } + } - } else { - SG_LOG( SG_ALL, SG_WARN, - "No instrumentation model specified for this model!"); - } - if (!_explicitGps) { - SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument"); - SGPropertyNode_ptr nd(new SGPropertyNode); - nd->setStringValue("name", "gps"); - nd->setIntValue("number", 0); - set_subsystem("gps[0]", new GPS(nd)); - } + if (!_explicitGps) { + SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument"); + SGPropertyNode_ptr nd(new SGPropertyNode); + nd->setStringValue("name", "gps"); + nd->setIntValue("number", 0); + set_subsystem("gps[0]", new GPS(nd)); + } + + SGSubsystemGroup::init(); } -FGInstrumentMgr::~FGInstrumentMgr () -{ +void FGInstrumentMgr::reinit() +{ +// delete all our instrument + for (unsigned int i=0; i<_instruments.size(); ++i) { + const std::string& nm(_instruments[i]); + SGSubsystem* instr = get_subsystem(nm); + instr->unbind(); + remove_subsystem(nm); + delete instr; + } + + init(); } bool FGInstrumentMgr::build (SGPropertyNode* config_props) @@ -110,7 +125,7 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props) if (index > 0) subsystemname << '['<< index << ']'; string id = subsystemname.str(); - + _instruments.push_back(id); if ( name == "adf" ) { set_subsystem( id, new ADF( node ), 0.15 ); diff --git a/src/Instrumentation/instrument_mgr.hxx b/src/Instrumentation/instrument_mgr.hxx index b5856ef97..d7c9b2a07 100644 --- a/src/Instrumentation/instrument_mgr.hxx +++ b/src/Instrumentation/instrument_mgr.hxx @@ -31,10 +31,15 @@ public: FGInstrumentMgr (); virtual ~FGInstrumentMgr (); - bool build (SGPropertyNode* config_props); - + + virtual void init(); + virtual void reinit(); private: + bool build (SGPropertyNode* config_props); + bool _explicitGps; + + std::vector _instruments; }; #endif // __INSTRUMENT_MGR_HXX -- 2.39.5