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