]> git.mxchange.org Git - flightgear.git/blob - src/Systems/system_mgr.cxx
eliminate some SGPropertyNode_ptr variables in classes
[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->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(config_props) ) {
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 }
67
68 FGSystemMgr::~FGSystemMgr ()
69 {
70 }
71
72 bool FGSystemMgr::build (SGPropertyNode* config_props)
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