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"
51 #include "agradar.hxx"
52 #include "rad_alt.hxx"
54 FGInstrumentMgr::FGInstrumentMgr () :
57 set_subsystem("od_gauge", new FGODGauge);
58 set_subsystem("hud", new HUD);
61 FGInstrumentMgr::~FGInstrumentMgr ()
65 void FGInstrumentMgr::init()
67 SGPropertyNode_ptr config_props = new SGPropertyNode;
68 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
70 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
74 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
75 SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
78 readProperties( config.str(), config_props );
79 if (!build(config_props)) {
81 "Detected an internal inconsistency in the instrumentation\n"
82 "system specification file. See earlier errors for details.");
84 } catch (const sg_exception&) {
85 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
91 SG_LOG(SG_INSTR, SG_INFO, "creating default GPS instrument");
92 SGPropertyNode_ptr nd(new SGPropertyNode);
93 nd->setStringValue("name", "gps");
94 nd->setIntValue("number", 0);
95 _instruments.push_back("gps[0]");
96 set_subsystem("gps[0]", new GPS(nd));
99 // bind() created instruments before init.
100 for (unsigned int i=0; i<_instruments.size(); ++i) {
101 const std::string& nm(_instruments[i]);
102 SGSubsystem* instr = get_subsystem(nm);
106 SGSubsystemGroup::init();
109 void FGInstrumentMgr::reinit()
111 // delete all our instrument
112 for (unsigned int i=0; i<_instruments.size(); ++i) {
113 const std::string& nm(_instruments[i]);
114 SGSubsystem* instr = get_subsystem(nm);
116 remove_subsystem(nm);
123 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
125 for ( int i = 0; i < config_props->nChildren(); ++i ) {
126 SGPropertyNode *node = config_props->getChild(i);
127 string name = node->getName();
129 std::ostringstream subsystemname;
130 subsystemname << "instrument-" << i << '-'
131 << node->getStringValue("name", name.c_str());
132 int index = node->getIntValue("number", 0);
134 subsystemname << '['<< index << ']';
135 string id = subsystemname.str();
136 _instruments.push_back(id);
138 if ( name == "adf" ) {
139 set_subsystem( id, new ADF( node ), 0.15 );
141 } else if ( name == "airspeed-indicator" ) {
142 set_subsystem( id, new AirspeedIndicator( node ) );
144 } else if ( name == "altimeter" ) {
145 set_subsystem( id, new Altimeter( node ) );
147 } else if ( name == "attitude-indicator" ) {
148 set_subsystem( id, new AttitudeIndicator( node ) );
150 } else if ( name == "clock" ) {
151 set_subsystem( id, new Clock( node ), 0.25 );
153 } else if ( name == "dme" ) {
154 set_subsystem( id, new DME( node ), 1.0 );
156 } else if ( name == "encoder" ) {
157 set_subsystem( id, new Altimeter( node ) );
159 } else if ( name == "gps" ) {
160 set_subsystem( id, new GPS( node ) );
162 } else if ( name == "gsdi" ) {
163 set_subsystem( id, new GSDI( node ) );
165 } else if ( name == "heading-indicator" ) {
166 set_subsystem( id, new HeadingIndicator( node ) );
168 } else if ( name == "heading-indicator-fg" ) {
169 set_subsystem( id, new HeadingIndicatorFG( node ) );
171 } else if ( name == "heading-indicator-dg" ) {
172 set_subsystem( id, new HeadingIndicatorDG( node ) );
174 } else if ( name == "KR-87" ) {
175 set_subsystem( id, new FGKR_87( node ) );
177 } else if ( name == "KT-70" ) {
178 set_subsystem( id, new FGKT_70( node ) );
180 } else if ( name == "magnetic-compass" ) {
181 set_subsystem( id, new MagCompass( node ) );
183 } else if ( name == "marker-beacon" ) {
184 set_subsystem( id, new FGMarkerBeacon( node ) );
186 } else if ( name == "nav-radio" ) {
187 set_subsystem( id, new FGNavRadio( node ) );
189 } else if ( name == "slip-skid-ball" ) {
190 set_subsystem( id, new SlipSkidBall( node ) );
192 } else if ( name == "transponder" ) {
193 set_subsystem( id, new Transponder( node ) );
195 } else if ( name == "turn-indicator" ) {
196 set_subsystem( id, new TurnIndicator( node ) );
198 } else if ( name == "vertical-speed-indicator" ) {
199 set_subsystem( id, new VerticalSpeedIndicator( node ) );
201 } else if ( name == "radar" ) {
202 set_subsystem( id, new wxRadarBg ( node ), 1);
204 } else if ( name == "inst-vertical-speed-indicator" ) {
205 set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
207 } else if ( name == "tacan" ) {
208 set_subsystem( id, new TACAN( node ) );
210 } else if ( name == "mk-viii" ) {
211 set_subsystem( id, new MK_VIII( node ) );
213 } else if ( name == "master-reference-gyro" ) {
214 set_subsystem( id, new MasterReferenceGyro( node ) );
216 } else if ( name == "groundradar" ) {
217 set_subsystem( id, new GroundRadar( node ), 1 );
219 } else if ( name == "air-ground-radar" ) {
220 set_subsystem( id, new agRadar( node ),1);
222 } else if ( name == "radar-altimeter" ) {
223 set_subsystem( id, new radAlt( node ),1);
226 SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
234 // end of instrument_manager.cxx