1 // instrument_mgr.cxx - manage aircraft instruments.
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>
14 #include <Main/fg_props.hxx>
15 #include <Main/globals.hxx>
16 #include <Main/util.hxx>
18 #include "instrument_mgr.hxx"
20 #include "airspeed_indicator.hxx"
21 #include "altimeter.hxx"
22 #include "annunciator.hxx"
23 #include "attitude_indicator.hxx"
27 #include "heading_indicator.hxx"
29 #include "mag_compass.hxx"
30 #include "slip_skid_ball.hxx"
31 #include "turn_indicator.hxx"
32 #include "vertical_speed_indicator.hxx"
35 FGInstrumentMgr::FGInstrumentMgr ()
37 //set_subsystem("asi", new AirspeedIndicator(0));
38 //set_subsystem("asi-backup", new AirspeedIndicator(1, 1, 1));
39 set_subsystem("annunciator", new Annunciator);
40 //set_subsystem("ai", new AttitudeIndicator);
41 //set_subsystem("alt", new Altimeter);
42 //set_subsystem("ti", new TurnIndicator);
43 //set_subsystem("ball", new SlipSkidBall);
44 //set_subsystem("hi", new HeadingIndicator);
45 //set_subsystem("vsi", new VerticalSpeedIndicator);
46 //set_subsystem("compass", new MagCompass);
47 //set_subsystem("dme", new DME, 1.0);
48 //set_subsystem("adf", new ADF, 0.15);
49 //set_subsystem("gps", new GPS, 0.45);
50 //set_subsystem("clock", new Clock, 0.25);
51 //set_subsystem("nhi", new NewHeadingIndicator);
53 config_props = new SGPropertyNode;
55 SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
58 SGPath config( globals->get_fg_root() );
59 config.append( path_n->getStringValue() );
61 SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
64 readProperties( config.str(), config_props );
69 SG_LOG( SG_ALL, SG_ALERT,
70 "Detected an internal inconsistancy in the instrumentation");
71 SG_LOG( SG_ALL, SG_ALERT,
72 " system specification file. See earlier errors for" );
73 SG_LOG( SG_ALL, SG_ALERT,
77 } catch (const sg_exception& exc) {
78 SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: "
83 SG_LOG( SG_ALL, SG_WARN,
84 "No instrumentation model specified for this model!");
90 FGInstrumentMgr::~FGInstrumentMgr ()
94 bool FGInstrumentMgr::build ()
99 int count = config_props->nChildren();
100 for ( i = 0; i < count; ++i ) {
101 node = config_props->getChild(i);
102 string name = node->getName();
103 std::ostringstream temp;
105 if ( name == "adf" ) {
106 set_subsystem( "instrument" + temp.str(),
107 new ADF( node ), 0.15 );
108 } else if ( name == "airspeed-indicator" ) {
109 set_subsystem( "instrument" + temp.str(),
110 new AirspeedIndicator( node ) );
111 } else if ( name == "altimeter" ) {
112 set_subsystem( "instrument" + temp.str(),
113 new Altimeter( node ) );
114 } else if ( name == "attitude-indicator" ) {
115 set_subsystem( "instrument" + temp.str(),
116 new AttitudeIndicator( node ) );
117 } else if ( name == "clock" ) {
118 set_subsystem( "instrument" + temp.str(),
119 new Clock( node ), 0.25 );
120 } else if ( name == "dme" ) {
121 set_subsystem( "instrument" + temp.str(),
122 new DME( node ), 1.0 );
123 } else if ( name == "heading-indicator" ) {
124 set_subsystem( "instrument" + temp.str(),
125 new HeadingIndicator( node ) );
126 } else if ( name == "KR-87" ) {
127 set_subsystem( "instrument" + temp.str(),
128 new FGKR_87( node ) );
129 } else if ( name == "magnetic-compass" ) {
130 set_subsystem( "instrument" + temp.str(),
131 new MagCompass( node ) );
132 } else if ( name == "slip-skid-ball" ) {
133 set_subsystem( "instrument" + temp.str(),
134 new SlipSkidBall( node ) );
135 } else if ( name == "turn-indicator" ) {
136 set_subsystem( "instrument" + temp.str(),
137 new TurnIndicator( node ) );
138 } else if ( name == "vertical-speed-indicator" ) {
139 set_subsystem( "instrument" + temp.str(),
140 new VerticalSpeedIndicator( node ) );
141 } else if ( name == "gps" ) {
142 set_subsystem( "instrument" + temp.str(),
143 new GPS( node ), 0.45 );
145 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
153 // end of instrument_manager.cxx