]> git.mxchange.org Git - flightgear.git/blob - src/Systems/system_mgr.cxx
1a93aa718f6b673b6ead997dec170de6001d0bb3
[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     set_subsystem( "electrical", new FGElectricalSystem );
28
29     config_props = new SGPropertyNode;
30
31     SGPropertyNode *path_n = fgGetNode("/sim/systems/path");
32
33     if (path_n) {
34         SGPath config( globals->get_fg_root() );
35         config.append( path_n->getStringValue() );
36
37         SG_LOG( SG_ALL, SG_INFO, "Reading systems from "
38                 << config.str() );
39         try {
40             readProperties( config.str(), config_props );
41
42             if ( build() ) {
43                 enabled = true;
44             } else {
45                 SG_LOG( SG_ALL, SG_ALERT,
46                         "Detected an internal inconsistancy in the systems");
47                 SG_LOG( SG_ALL, SG_ALERT,
48                         " system specification file.  See earlier errors for" );
49                 SG_LOG( SG_ALL, SG_ALERT,
50                         " details.");
51                 exit(-1);
52             }        
53         } catch (const sg_exception& exc) {
54             SG_LOG( SG_ALL, SG_ALERT, "Failed to load systems system model: "
55                     << config.str() );
56         }
57
58     } else {
59         SG_LOG( SG_ALL, SG_WARN,
60                 "No systems model specified for this model!");
61     }
62
63     delete config_props;
64 }
65
66 FGSystemMgr::~FGSystemMgr ()
67 {
68 }
69
70 bool FGSystemMgr::build ()
71 {
72     SGPropertyNode *node;
73     int i;
74
75     int count = config_props->nChildren();
76     for ( i = 0; i < count; ++i ) {
77         node = config_props->getChild(i);
78         string name = node->getName();
79         std::ostringstream temp;
80         temp << i;
81         if ( name == "pitot" ) {
82             set_subsystem( "system" + temp.str(), 
83                            new PitotSystem( node ) );
84         } else if ( name == "static" ) {
85             set_subsystem( "system" + temp.str(), 
86                            new StaticSystem( node ) );
87         } else if ( name == "vacuum" ) {
88             set_subsystem( "system" + temp.str(), 
89                            new VacuumSystem( node ) );
90         } else {
91             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
92                     << name );
93             return false;
94         }
95     }
96     return true;
97 }
98
99 // end of system_manager.cxx