]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/electrical.cxx
Merge commit 'refs/merge-requests/1552' of git@gitorious.org:fg/flightgear into next
[flightgear.git] / src / Systems / electrical.cxx
index 025a46ae30d82f3d96b4412c4cc39c70d4bdbea3..d711b4dcac67487a4fc9133e6a1c92feb33bcc29 100644 (file)
 #  include <config.h>
 #endif
 
+#include <cstring>
+
 #include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/props/props_io.hxx>
 
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
@@ -333,30 +337,11 @@ bool FGElectricalConnector::get_state() {
 
 
 FGElectricalSystem::FGElectricalSystem ( SGPropertyNode *node ) :
-    name("electrical"),
-    num(0),
-    path(""),
+    name(node->getStringValue("name", "electrical")),
+    num(node->getIntValue("number", 0)),
+    path(node->getStringValue("path")),
     enabled(false)
 {
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "name" ) {
-            name = cval;
-        } else if ( cname == "number" ) {
-            num = child->getIntValue();
-        } else if ( cname == "path" ) {
-            path = cval;
-        } else {
-            SG_LOG( SG_SYSTEMS, SG_WARN,
-                    "Error in electrical system config logic" );
-            if ( name.length() ) {
-                SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name );
-            }
-        }
-    }
 }
 
 
@@ -365,7 +350,7 @@ FGElectricalSystem::~FGElectricalSystem () {
 
 
 void FGElectricalSystem::init () {
-    config_props = new SGPropertyNode;
+    SGPropertyNode_ptr config_props = new SGPropertyNode;
 
     _volts_out = fgGetNode( "/systems/electrical/volts", true );
     _amps_out = fgGetNode( "/systems/electrical/amps", true );
@@ -388,17 +373,16 @@ void FGElectricalSystem::init () {
     }
 
     if ( path.length() ) {
-        SGPath config( globals->get_fg_root() );
-        config.append( path );
-
+        SGPath config = globals->resolve_aircraft_path(path);
+        
         // load an obsolete xml configuration
-        SG_LOG( SG_ALL, SG_ALERT,
-                "Reading xml electrical system model from "
+        SG_LOG( SG_ALL, SG_WARN,
+                "Reading deprecated xml electrical system model from\n    "
                 << config.str() );
         try {
             readProperties( config.str(), config_props );
 
-            if ( build() ) {
+            if ( build(config_props) ) {
                 enabled = true;
             } else {
                 SG_LOG( SG_ALL, SG_ALERT,
@@ -409,7 +393,7 @@ void FGElectricalSystem::init () {
                         "details.");
                 exit(-1);
             }        
-        } catch (const sg_exception& exc) {
+        } catch (const sg_exception&) {
             SG_LOG( SG_ALL, SG_ALERT,
                     "Failed to load electrical system model: "
                     << config.str() );
@@ -423,7 +407,6 @@ void FGElectricalSystem::init () {
         _amps_out->setDoubleValue(0);
     }
 
-    delete config_props;
 }
 
 
@@ -472,7 +455,8 @@ void FGElectricalSystem::update (double dt) {
                               " " );
 
             if ( node->apply_load( load, dt ) < 0.0 ) {
-                cout << "Error drawing more current than available!" << endl;
+                SG_LOG(SG_ALL, SG_ALERT,
+                       "Error drawing more current than available!");
             }
         }     
     }
@@ -491,7 +475,8 @@ void FGElectricalSystem::update (double dt) {
                               " " );
 
             if ( node->apply_load( load, dt ) < 0.0 ) {
-                cout << "Error drawing more current than available!" << endl;
+                SG_LOG(SG_ALL, SG_ALERT,
+                       "Error drawing more current than available!");
             }
         }     
     }
@@ -511,7 +496,8 @@ void FGElectricalSystem::update (double dt) {
             // cout << "battery load = " << load << endl;
 
             if ( node->apply_load( load, dt ) < 0.0 ) {
-                cout << "Error drawing more current than available!" << endl;
+                SG_LOG(SG_ALL, SG_ALERT,
+                       "Error drawing more current than available!");
             }
         }     
     }
@@ -567,7 +553,7 @@ void FGElectricalSystem::update (double dt) {
 }
 
 
-bool FGElectricalSystem::build () {
+bool FGElectricalSystem::build (SGPropertyNode* config_props) {
     SGPropertyNode *node;
     int i;