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.
14 #include <simgear/structure/exception.hxx>
15 #include <simgear/misc/sg_path.hxx>
16 #include <simgear/sg_inlines.h>
18 #include <Main/fg_props.hxx>
19 #include <Main/globals.hxx>
20 #include <Main/util.hxx>
21 #include <Instrumentation/HUD/HUD.hxx>
23 #include "instrument_mgr.hxx"
25 #include "airspeed_indicator.hxx"
26 #include "altimeter.hxx"
27 #include "attitude_indicator.hxx"
32 #include "heading_indicator.hxx"
33 #include "heading_indicator_fg.hxx"
34 #include "heading_indicator_dg.hxx"
37 #include "mag_compass.hxx"
38 #include "marker_beacon.hxx"
39 #include "navradio.hxx"
40 #include "slip_skid_ball.hxx"
41 #include "transponder.hxx"
42 #include "turn_indicator.hxx"
43 #include "vertical_speed_indicator.hxx"
44 #include "inst_vertical_speed_indicator.hxx"
45 #include "od_gauge.hxx"
46 #include "wxradar.hxx"
48 #include "mk_viii.hxx"
50 #include "groundradar.hxx"
52 FGInstrumentMgr::FGInstrumentMgr ()
54 set_subsystem("od_gauge", new FGODGauge);
55 set_subsystem("hud", new HUD);
57 config_props = new SGPropertyNode;
59 SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
62 SGPath config( globals->get_fg_root() );
63 config.append( path_n->getStringValue() );
65 SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
68 readProperties( config.str(), config_props );
71 throw sg_throwable(string(
72 "Detected an internal inconsistency in the instrumentation\n"
73 "system specification file. See earlier errors for details."));
75 } catch (const sg_exception& exc) {
76 SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: "
81 SG_LOG( SG_ALL, SG_WARN,
82 "No instrumentation model specified for this model!");
88 FGInstrumentMgr::~FGInstrumentMgr ()
92 bool FGInstrumentMgr::build ()
94 for ( int i = 0; i < config_props->nChildren(); ++i ) {
95 SGPropertyNode *node = config_props->getChild(i);
96 string name = node->getName();
98 std::ostringstream subsystemname;
99 subsystemname << "instrument-" << i << '-'
100 << node->getStringValue("name", name.c_str());
101 int index = node->getIntValue("number", 0);
103 subsystemname << '['<< index << ']';
104 string id = subsystemname.str();
107 if ( name == "adf" ) {
108 set_subsystem( id, new ADF( node ), 0.15 );
110 } else if ( name == "airspeed-indicator" ) {
111 set_subsystem( id, new AirspeedIndicator( node ) );
113 } else if ( name == "altimeter" ) {
114 set_subsystem( id, new Altimeter( node ) );
116 } else if ( name == "attitude-indicator" ) {
117 set_subsystem( id, new AttitudeIndicator( node ) );
119 } else if ( name == "clock" ) {
120 set_subsystem( id, new Clock( node ), 0.25 );
122 } else if ( name == "dme" ) {
123 set_subsystem( id, new DME( node ), 1.0 );
125 } else if ( name == "encoder" ) {
126 set_subsystem( id, new Altimeter( node ) );
128 } else if ( name == "gps" ) {
129 set_subsystem( id, new GPS( node ), 0.45 );
131 } else if ( name == "gsdi" ) {
132 set_subsystem( id, new GSDI( node ) );
134 } else if ( name == "heading-indicator" ) {
135 set_subsystem( id, new HeadingIndicator( node ) );
137 } else if ( name == "heading-indicator-fg" ) {
138 set_subsystem( id, new HeadingIndicatorFG( node ) );
140 } else if ( name == "heading-indicator-dg" ) {
141 set_subsystem( id, new HeadingIndicatorDG( node ) );
143 } else if ( name == "KR-87" ) {
144 set_subsystem( id, new FGKR_87( node ) );
146 } else if ( name == "KT-70" ) {
147 set_subsystem( id, new FGKT_70( node ) );
149 } else if ( name == "magnetic-compass" ) {
150 set_subsystem( id, new MagCompass( node ) );
152 } else if ( name == "marker-beacon" ) {
153 set_subsystem( id, new FGMarkerBeacon( node ) );
155 } else if ( name == "nav-radio" ) {
156 set_subsystem( id, new FGNavRadio( node ) );
158 } else if ( name == "slip-skid-ball" ) {
159 set_subsystem( id, new SlipSkidBall( node ) );
161 } else if ( name == "transponder" ) {
162 set_subsystem( id, new Transponder( node ) );
164 } else if ( name == "turn-indicator" ) {
165 set_subsystem( id, new TurnIndicator( node ) );
167 } else if ( name == "vertical-speed-indicator" ) {
168 set_subsystem( id, new VerticalSpeedIndicator( node ) );
170 } else if ( name == "radar" ) {
171 set_subsystem( id, new wxRadarBg ( node ), 0.5 );
173 } else if ( name == "inst-vertical-speed-indicator" ) {
174 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
176 } else if ( name == "tacan" ) {
177 set_subsystem( id, new TACAN( node ) );
179 } else if ( name == "mk-viii" ) {
180 set_subsystem( id, new MK_VIII( node ) );
182 } else if ( name == "master-reference-gyro" ) {
183 set_subsystem( id, new MasterReferenceGyro( node ) );
185 } else if ( name == "groundradar" ) {
186 set_subsystem( id, new GroundRadar( node ) );
189 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
197 // end of instrument_manager.cxx