]> git.mxchange.org Git - flightgear.git/blob - src/Systems/system_mgr.cxx
Turn the electrical system into a non-hardcoded system like all the other
[flightgear.git] / src / Systems / system_mgr.cxx
1 // system_mgr.cxx - manage aircraft systems.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <simgear/structure/exception.hxx>
7 #include <simgear/misc/sg_path.hxx>
8 #include <simgear/sg_inlines.h>
9
10 #include <Main/fg_props.hxx>
11 #include <Main/globals.hxx>
12 #include <Main/util.hxx>
13
14 #include <iostream>
15 #include <string>
16 #include <sstream>
17
18 #include "system_mgr.hxx"
19 #include "electrical.hxx"
20 #include "pitot.hxx"
21 #include "static.hxx"
22 #include "vacuum.hxx"
23
24
25 FGSystemMgr::FGSystemMgr ()
26 {
27     config_props = new SGPropertyNode;
28
29     SGPropertyNode *path_n = fgGetNode("/sim/systems/path");
30
31     if (path_n) {
32         SGPath config( globals->get_fg_root() );
33         config.append( path_n->getStringValue() );
34
35         SG_LOG( SG_ALL, SG_INFO, "Reading systems from "
36                 << config.str() );
37         try {
38             readProperties( config.str(), config_props );
39
40             if ( build() ) {
41                 enabled = true;
42             } else {
43                 SG_LOG( SG_ALL, SG_ALERT,
44                         "Detected an internal inconsistancy in the systems");
45                 SG_LOG( SG_ALL, SG_ALERT,
46                         " system specification file.  See earlier errors for" );
47                 SG_LOG( SG_ALL, SG_ALERT,
48                         " details.");
49                 exit(-1);
50             }        
51         } catch (const sg_exception& exc) {
52             SG_LOG( SG_ALL, SG_ALERT, "Failed to load systems system model: "
53                     << config.str() );
54         }
55
56     } else {
57         SG_LOG( SG_ALL, SG_WARN,
58                 "No systems model specified for this model!");
59     }
60
61     delete config_props;
62 }
63
64 FGSystemMgr::~FGSystemMgr ()
65 {
66 }
67
68 bool FGSystemMgr::build ()
69 {
70     SGPropertyNode *node;
71     int i;
72
73     int count = config_props->nChildren();
74     for ( i = 0; i < count; ++i ) {
75         node = config_props->getChild(i);
76         string name = node->getName();
77         std::ostringstream temp;
78         temp << i;
79         if ( name == "electrical" ) {
80             set_subsystem( "electrical" + temp.str(),
81                            new FGElectricalSystem( node ) );
82         } else if ( name == "pitot" ) {
83             set_subsystem( "system" + temp.str(), 
84                            new PitotSystem( node ) );
85         } else if ( name == "static" ) {
86             set_subsystem( "system" + temp.str(), 
87                            new StaticSystem( node ) );
88         } else if ( name == "vacuum" ) {
89             set_subsystem( "system" + temp.str(), 
90                            new VacuumSystem( node ) );
91         } else {
92             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
93                     << name );
94             return false;
95         }
96     }
97     return true;
98 }
99
100 // end of system_manager.cxx