]> git.mxchange.org Git - flightgear.git/commitdiff
Reset - instruments can be re-inited now (reloads XML files)
authorJames Turner <zakalawe@mac.com>
Sun, 4 Jul 2010 22:03:05 +0000 (23:03 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 1 Aug 2010 18:04:31 +0000 (19:04 +0100)
src/Instrumentation/gps.cxx
src/Instrumentation/instrument_mgr.cxx
src/Instrumentation/instrument_mgr.hxx

index afee154f3f5815dcd0a752e448e2442284ccaab8..06647d4ad20596645b24717d72093a0f3b5a7655 100644 (file)
@@ -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<SGPropertyNode*>::iterator it;
     for (it = _parents.begin(); it != _parents.end(); ++it) {
index 27f5e39485624dffd3caa9860ed9db301112242d..646d3fba0bdf0b49070966d1e3e93388e6aa5c24 100644 (file)
@@ -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 );
index b5856ef979de8e0da90be5ff5e4183db7e1a6ede..d7c9b2a07b66ef2474f4b6dcd7f402b30a7ba66d 100644 (file)
@@ -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<std::string> _instruments;
 };
 
 #endif // __INSTRUMENT_MGR_HXX