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