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