]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
Fixes for include-file flattening - condition.hxx no longer pulls in props or props_io
[flightgear.git] / src / Instrumentation / instrument_mgr.cxx
1 // instrument_mgr.cxx - manage aircraft instruments.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #ifdef HAVE_CONFIG_H
7 #  include <config.h>
8 #endif
9
10 #include <iostream>
11 #include <string>
12 #include <sstream>
13
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>
18
19 #include <Main/fg_props.hxx>
20 #include <Main/globals.hxx>
21 #include <Main/util.hxx>
22 #include <Instrumentation/HUD/HUD.hxx>
23
24 #include "instrument_mgr.hxx"
25 #include "adf.hxx"
26 #include "airspeed_indicator.hxx"
27 #include "altimeter.hxx"
28 #include "attitude_indicator.hxx"
29 #include "clock.hxx"
30 #include "dme.hxx"
31 #include "gps.hxx"
32 #include "gsdi.hxx"
33 #include "heading_indicator.hxx"
34 #include "heading_indicator_fg.hxx"
35 #include "heading_indicator_dg.hxx"
36 #include "kr_87.hxx"
37 #include "kt_70.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"
48 #include "tacan.hxx"
49 #include "mk_viii.hxx"
50 #include "mrg.hxx"
51 #include "groundradar.hxx"
52 #include "agradar.hxx"
53 #include "rad_alt.hxx"
54 #include "tcas.hxx"
55
56 FGInstrumentMgr::FGInstrumentMgr () :
57   _explicitGps(false)
58 {
59     set_subsystem("od_gauge", new FGODGauge);
60     
61     globals->add_subsystem("hud", new HUD, SGSubsystemMgr::DISPLAY);
62 }
63
64 FGInstrumentMgr::~FGInstrumentMgr ()
65 {
66 }
67
68 void FGInstrumentMgr::init()
69 {
70   SGPropertyNode_ptr config_props = new SGPropertyNode;
71   SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
72   if (!path_n) {
73     SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
74     return;
75   }
76
77   SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
78   SG_LOG( SG_COCKPIT, SG_INFO, "Reading instruments from " << config.str() );
79
80   try {
81     readProperties( config.str(), config_props );
82     if (!build(config_props)) {
83       throw sg_error(
84                     "Detected an internal inconsistency in the instrumentation\n"
85                     "system specification file.  See earlier errors for details.");
86     }
87   } catch (const sg_exception&) {
88     SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
89                     << config.str() );
90   }
91
92
93   if (!_explicitGps) {
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));
100   }
101
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);
106     instr->bind();
107   }
108
109   SGSubsystemGroup::init();
110 }
111
112 void FGInstrumentMgr::reinit()
113 {  
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);
118     instr->unbind();
119     remove_subsystem(nm);
120     delete instr;
121   }
122   
123   init();
124 }
125
126 bool FGInstrumentMgr::build (SGPropertyNode* config_props)
127 {
128     for ( int i = 0; i < config_props->nChildren(); ++i ) {
129         SGPropertyNode *node = config_props->getChild(i);
130         string name = node->getName();
131
132         std::ostringstream subsystemname;
133         subsystemname << "instrument-" << i << '-'
134                 << node->getStringValue("name", name.c_str());
135         int index = node->getIntValue("number", 0);
136         if (index > 0)
137             subsystemname << '['<< index << ']';
138         string id = subsystemname.str();
139         _instruments.push_back(id);
140
141         if ( name == "adf" ) {
142             set_subsystem( id, new ADF( node ), 0.15 );
143
144         } else if ( name == "airspeed-indicator" ) {
145             set_subsystem( id, new AirspeedIndicator( node ) );
146
147         } else if ( name == "altimeter" ) {
148             set_subsystem( id, new Altimeter( node ) );
149
150         } else if ( name == "attitude-indicator" ) {
151             set_subsystem( id, new AttitudeIndicator( node ) );
152
153         } else if ( name == "clock" ) {
154             set_subsystem( id, new Clock( node ), 0.25 );
155
156         } else if ( name == "dme" ) {
157             set_subsystem( id, new DME( node ), 1.0 );
158
159         } else if ( name == "encoder" ) {
160             set_subsystem( id, new Altimeter( node ) );
161
162         } else if ( name == "gps" ) {
163             set_subsystem( id, new GPS( node ) );
164             _explicitGps = true;
165         } else if ( name == "gsdi" ) {
166             set_subsystem( id, new GSDI( node ) );
167
168         } else if ( name == "heading-indicator" ) {
169             set_subsystem( id, new HeadingIndicator( node ) );
170
171         } else if ( name == "heading-indicator-fg" ) {
172             set_subsystem( id, new HeadingIndicatorFG( node ) );
173
174         } else if ( name == "heading-indicator-dg" ) {
175             set_subsystem( id, new HeadingIndicatorDG( node ) );
176
177         } else if ( name == "KR-87" ) {
178             set_subsystem( id, new FGKR_87( node ) );
179
180         } else if ( name == "KT-70" ) {
181             set_subsystem( id, new FGKT_70( node ) );
182
183         } else if ( name == "magnetic-compass" ) {
184             set_subsystem( id, new MagCompass( node ) );
185
186         } else if ( name == "marker-beacon" ) {
187             set_subsystem( id, new FGMarkerBeacon( node ) );
188
189         } else if ( name == "nav-radio" ) {
190             set_subsystem( id, new FGNavRadio( node ) );
191
192         } else if ( name == "slip-skid-ball" ) {
193             set_subsystem( id, new SlipSkidBall( node ) );
194
195         } else if ( name == "transponder" ) {
196             set_subsystem( id, new Transponder( node ) );
197
198         } else if ( name == "turn-indicator" ) {
199             set_subsystem( id, new TurnIndicator( node ) );
200
201         } else if ( name == "vertical-speed-indicator" ) {
202             set_subsystem( id, new VerticalSpeedIndicator( node ) );
203
204         } else if ( name == "radar" ) {
205             set_subsystem( id, new wxRadarBg ( node ), 1);
206
207         } else if ( name == "inst-vertical-speed-indicator" ) {
208             set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
209
210         } else if ( name == "tacan" ) {
211             set_subsystem( id, new TACAN( node ) );
212
213         } else if ( name == "mk-viii" ) {
214             set_subsystem( id, new MK_VIII( node ) );
215
216         } else if ( name == "master-reference-gyro" ) {
217             set_subsystem( id, new MasterReferenceGyro( node ) );
218
219         } else if ( name == "groundradar" ) {
220             set_subsystem( id, new GroundRadar( node ), 1 );
221
222         } else if ( name == "air-ground-radar" ) {
223             set_subsystem( id, new agRadar( node ),1);
224
225         } else if ( name == "radar-altimeter" ) {
226             set_subsystem( id, new radAlt( node ),1);
227
228         } else if ( name == "tcas" ) {
229             set_subsystem( id, new TCAS( node ) );
230
231         } else {
232             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
233                     << name );
234             return false;
235         }
236     }
237     return true;
238 }
239
240 // end of instrument_manager.cxx