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>
17 #include <simgear/props/props_io.hxx>
19 #include <Main/fg_props.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/util.hxx>
22 #include <Instrumentation/HUD/HUD.hxx>
24 #include "instrument_mgr.hxx"
26 #include "airspeed_indicator.hxx"
27 #include "altimeter.hxx"
28 #include "attitude_indicator.hxx"
33 #include "heading_indicator.hxx"
34 #include "heading_indicator_fg.hxx"
35 #include "heading_indicator_dg.hxx"
38 #include "mag_compass.hxx"
39 #include "marker_beacon.hxx"
40 #include "newnavradio.hxx"
41 #include "slip_skid_ball.hxx"
42 #include "transponder.hxx"
43 #include "turn_indicator.hxx"
44 #include "vertical_speed_indicator.hxx"
45 #include "inst_vertical_speed_indicator.hxx"
46 #include "od_gauge.hxx"
47 #include "wxradar.hxx"
49 #include "mk_viii.hxx"
51 #include "groundradar.hxx"
52 #include "agradar.hxx"
53 #include "rad_alt.hxx"
55 #include "NavDisplay.hxx"
57 FGInstrumentMgr::FGInstrumentMgr () :
60 set_subsystem("od_gauge", new FGODGauge);
62 globals->add_subsystem("hud", new HUD, SGSubsystemMgr::DISPLAY);
65 FGInstrumentMgr::~FGInstrumentMgr ()
69 void FGInstrumentMgr::init()
71 SGPropertyNode_ptr config_props = new SGPropertyNode;
72 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
74 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
78 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
79 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
82 readProperties( config.str(), config_props );
83 if (!build(config_props)) {
85 "Detected an internal inconsistency in the instrumentation\n"
86 "system specification file. See earlier errors for details.");
88 } catch (const sg_exception& e) {
89 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
90 << config.str() << ":" << e.getFormattedMessage() );
95 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
96 SGPropertyNode_ptr nd(new SGPropertyNode);
97 nd->setStringValue("name", "gps");
98 nd->setIntValue("number", 0);
99 _instruments.push_back("gps[0]");
100 set_subsystem("gps[0]", new GPS(nd));
103 // bind() created instruments before init.
104 for (unsigned int i=0; i<_instruments.size(); ++i) {
105 const std::string& nm(_instruments[i]);
106 SGSubsystem* instr = get_subsystem(nm);
110 SGSubsystemGroup::init();
113 void FGInstrumentMgr::reinit()
115 // delete all our instrument
116 for (unsigned int i=0; i<_instruments.size(); ++i) {
117 const std::string& nm(_instruments[i]);
118 SGSubsystem* instr = get_subsystem(nm);
120 remove_subsystem(nm);
127 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
129 for ( int i = 0; i < config_props->nChildren(); ++i ) {
130 SGPropertyNode *node = config_props->getChild(i);
131 string name = node->getName();
133 std::ostringstream subsystemname;
134 subsystemname << "instrument-" << i << '-'
135 << node->getStringValue("name", name.c_str());
136 int index = node->getIntValue("number", 0);
138 subsystemname << '['<< index << ']';
139 string id = subsystemname.str();
140 _instruments.push_back(id);
142 if ( name == "adf" ) {
143 set_subsystem( id, new ADF( node ), 0.15 );
145 } else if ( name == "airspeed-indicator" ) {
146 set_subsystem( id, new AirspeedIndicator( node ) );
148 } else if ( name == "altimeter" ) {
149 set_subsystem( id, new Altimeter( node ) );
151 } else if ( name == "attitude-indicator" ) {
152 set_subsystem( id, new AttitudeIndicator( node ) );
154 } else if ( name == "clock" ) {
155 set_subsystem( id, new Clock( node ), 0.25 );
157 } else if ( name == "dme" ) {
158 set_subsystem( id, new DME( node ), 1.0 );
160 } else if ( name == "encoder" ) {
161 set_subsystem( id, new Altimeter( node ) );
163 } else if ( name == "gps" ) {
164 set_subsystem( id, new GPS( node ) );
166 } else if ( name == "gsdi" ) {
167 set_subsystem( id, new GSDI( node ) );
169 } else if ( name == "heading-indicator" ) {
170 set_subsystem( id, new HeadingIndicator( node ) );
172 } else if ( name == "heading-indicator-fg" ) {
173 set_subsystem( id, new HeadingIndicatorFG( node ) );
175 } else if ( name == "heading-indicator-dg" ) {
176 set_subsystem( id, new HeadingIndicatorDG( node ) );
178 } else if ( name == "KR-87" ) {
179 set_subsystem( id, new FGKR_87( node ) );
181 } else if ( name == "KT-70" ) {
182 set_subsystem( id, new FGKT_70( node ) );
184 } else if ( name == "magnetic-compass" ) {
185 set_subsystem( id, new MagCompass( node ) );
187 } else if ( name == "marker-beacon" ) {
188 set_subsystem( id, new FGMarkerBeacon( node ) );
190 } else if ( name == "nav-radio" ) {
191 set_subsystem( id, Instrumentation::NavRadio::createInstance( node ) );
193 } else if ( name == "slip-skid-ball" ) {
194 set_subsystem( id, new SlipSkidBall( node ) );
196 } else if ( name == "transponder" ) {
197 set_subsystem( id, new Transponder( node ) );
199 } else if ( name == "turn-indicator" ) {
200 set_subsystem( id, new TurnIndicator( node ) );
202 } else if ( name == "vertical-speed-indicator" ) {
203 set_subsystem( id, new VerticalSpeedIndicator( node ) );
205 } else if ( name == "radar" ) {
206 set_subsystem( id, new wxRadarBg ( node ), 1);
208 } else if ( name == "inst-vertical-speed-indicator" ) {
209 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
211 } else if ( name == "tacan" ) {
212 set_subsystem( id, new TACAN( node ) );
214 } else if ( name == "mk-viii" ) {
215 set_subsystem( id, new MK_VIII( node ) );
217 } else if ( name == "master-reference-gyro" ) {
218 set_subsystem( id, new MasterReferenceGyro( node ) );
220 } else if ( name == "groundradar" ) {
221 set_subsystem( id, new GroundRadar( node ), 1 );
223 } else if ( name == "air-ground-radar" ) {
224 set_subsystem( id, new agRadar( node ),1);
226 } else if ( name == "radar-altimeter" ) {
227 set_subsystem( id, new radAlt( node ),1);
229 } else if ( name == "tcas" ) {
230 set_subsystem( id, new TCAS( node ) );
232 } else if ( name == "navigation-display" ) {
233 set_subsystem( id, new NavDisplay( node ) );
236 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
244 // end of instrument_manager.cxx