1 // system_mgr.cxx - manage aircraft systems.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
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>
15 #include <Main/fg_props.hxx>
16 #include <Main/globals.hxx>
17 #include <Main/util.hxx>
23 #include "system_mgr.hxx"
24 #include "electrical.hxx"
30 FGSystemMgr::FGSystemMgr ()
32 SGPropertyNode_ptr config_props = new SGPropertyNode;
34 SGPropertyNode *path_n = fgGetNode("/sim/systems/path");
37 SGPath config( globals->get_fg_root() );
38 config.append( path_n->getStringValue() );
40 SG_LOG( SG_ALL, SG_INFO, "Reading systems from "
43 readProperties( config.str(), config_props );
45 if ( build(config_props) ) {
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,
56 } catch (const sg_exception&) {
57 SG_LOG( SG_ALL, SG_ALERT, "Failed to load systems system model: "
62 SG_LOG( SG_ALL, SG_WARN,
63 "No systems model specified for this model!");
68 FGSystemMgr::~FGSystemMgr ()
72 bool FGSystemMgr::build (SGPropertyNode* config_props)
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;
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 ) );
96 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
104 // end of system_manager.cxx