]> git.mxchange.org Git - flightgear.git/blob - src/Systems/system_mgr.cxx
- rename fgcommand "set-mouse" to "set-cursor"
[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
14 #include <Main/fg_props.hxx>
15 #include <Main/globals.hxx>
16 #include <Main/util.hxx>
17
18 #include <iostream>
19 #include <string>
20 #include <sstream>
21
22 #include "system_mgr.hxx"
23 #include "electrical.hxx"
24 #include "pitot.hxx"
25 #include "static.hxx"
26 #include "vacuum.hxx"
27
28
29 FGSystemMgr::FGSystemMgr ()
30 {
31     config_props = new SGPropertyNode;
32
33     SGPropertyNode *path_n = fgGetNode("/sim/systems/path");
34
35     if (path_n) {
36         SGPath config( globals->get_fg_root() );
37         config.append( 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() ) {
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& exc) {
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     delete config_props;
66 }
67
68 FGSystemMgr::~FGSystemMgr ()
69 {
70 }
71
72 bool FGSystemMgr::build ()
73 {
74     SGPropertyNode *node;
75     int i;
76
77     int count = config_props->nChildren();
78     for ( i = 0; i < count; ++i ) {
79         node = config_props->getChild(i);
80         string name = node->getName();
81         std::ostringstream temp;
82         temp << i;
83         if ( name == "electrical" ) {
84             set_subsystem( "electrical" + temp.str(),
85                            new FGElectricalSystem( node ) );
86         } else if ( name == "pitot" ) {
87             set_subsystem( "system" + temp.str(), 
88                            new PitotSystem( node ) );
89         } else if ( name == "static" ) {
90             set_subsystem( "system" + temp.str(), 
91                            new StaticSystem( node ) );
92         } else if ( name == "vacuum" ) {
93             set_subsystem( "system" + temp.str(), 
94                            new VacuumSystem( node ) );
95         } else {
96             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
97                     << name );
98             return false;
99         }
100     }
101     return true;
102 }
103
104 // end of system_manager.cxx