]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
better use unset() for unsetting ...
[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
18 #include <Main/fg_props.hxx>
19 #include <Main/globals.hxx>
20 #include <Main/util.hxx>
21 #include <Instrumentation/HUD/HUD.hxx>
22
23 #include "instrument_mgr.hxx"
24 #include "adf.hxx"
25 #include "airspeed_indicator.hxx"
26 #include "altimeter.hxx"
27 #include "attitude_indicator.hxx"
28 #include "clock.hxx"
29 #include "dme.hxx"
30 #include "gps.hxx"
31 #include "gsdi.hxx"
32 #include "heading_indicator.hxx"
33 #include "heading_indicator_fg.hxx"
34 #include "heading_indicator_dg.hxx"
35 #include "kr_87.hxx"
36 #include "kt_70.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"
47 #include "tacan.hxx"
48 #include "mk_viii.hxx"
49 #include "mrg.hxx"
50 #include "groundradar.hxx"
51 #include "agradar.hxx"
52 #include "rad_alt.hxx"
53
54 FGInstrumentMgr::FGInstrumentMgr ()
55 {
56     set_subsystem("od_gauge", new FGODGauge);
57     set_subsystem("hud", new HUD);
58
59     config_props = new SGPropertyNode;
60
61     SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
62
63     if (path_n) {
64         SGPath config( globals->get_fg_root() );
65         config.append( path_n->getStringValue() );
66
67         SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
68                 << config.str() );
69         try {
70             readProperties( config.str(), config_props );
71
72             if ( !build() ) {
73                 throw sg_throwable(string(
74                         "Detected an internal inconsistency in the instrumentation\n"
75                         "system specification file.  See earlier errors for details."));
76             }
77         } catch (const sg_exception&) {
78             SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: "
79                     << config.str() );
80         }
81
82     } else {
83         SG_LOG( SG_ALL, SG_WARN,
84                 "No instrumentation model specified for this model!");
85     }
86
87     delete config_props;
88 }
89
90 FGInstrumentMgr::~FGInstrumentMgr ()
91 {
92 }
93
94 bool FGInstrumentMgr::build ()
95 {
96     for ( int i = 0; i < config_props->nChildren(); ++i ) {
97         SGPropertyNode *node = config_props->getChild(i);
98         string name = node->getName();
99
100         std::ostringstream subsystemname;
101         subsystemname << "instrument-" << i << '-'
102                 << node->getStringValue("name", name.c_str());
103         int index = node->getIntValue("number", 0);
104         if (index > 0)
105             subsystemname << '['<< index << ']';
106         string id = subsystemname.str();
107
108
109         if ( name == "adf" ) {
110             set_subsystem( id, new ADF( node ), 0.15 );
111
112         } else if ( name == "airspeed-indicator" ) {
113             set_subsystem( id, new AirspeedIndicator( node ) );
114
115         } else if ( name == "altimeter" ) {
116             set_subsystem( id, new Altimeter( node ) );
117
118         } else if ( name == "attitude-indicator" ) {
119             set_subsystem( id, new AttitudeIndicator( node ) );
120
121         } else if ( name == "clock" ) {
122             set_subsystem( id, new Clock( node ), 0.25 );
123
124         } else if ( name == "dme" ) {
125             set_subsystem( id, new DME( node ), 1.0 );
126
127         } else if ( name == "encoder" ) {
128             set_subsystem( id, new Altimeter( node ) );
129
130         } else if ( name == "gps" ) {
131             set_subsystem( id, new GPS( node ), 0.45 );
132
133         } else if ( name == "gsdi" ) {
134             set_subsystem( id, new GSDI( node ) );
135
136         } else if ( name == "heading-indicator" ) {
137             set_subsystem( id, new HeadingIndicator( node ) );
138
139         } else if ( name == "heading-indicator-fg" ) {
140             set_subsystem( id, new HeadingIndicatorFG( node ) );
141
142         } else if ( name == "heading-indicator-dg" ) {
143             set_subsystem( id, new HeadingIndicatorDG( node ) );
144
145         } else if ( name == "KR-87" ) {
146             set_subsystem( id, new FGKR_87( node ) );
147
148         } else if ( name == "KT-70" ) {
149             set_subsystem( id, new FGKT_70( node ) );
150
151         } else if ( name == "magnetic-compass" ) {
152             set_subsystem( id, new MagCompass( node ) );
153
154         } else if ( name == "marker-beacon" ) {
155             set_subsystem( id, new FGMarkerBeacon( node ) );
156
157         } else if ( name == "nav-radio" ) {
158             set_subsystem( id, new FGNavRadio( node ) );
159
160         } else if ( name == "slip-skid-ball" ) {
161             set_subsystem( id, new SlipSkidBall( node ) );
162
163         } else if ( name == "transponder" ) {
164             set_subsystem( id, new Transponder( node ) );
165
166         } else if ( name == "turn-indicator" ) {
167             set_subsystem( id, new TurnIndicator( node ) );
168
169         } else if ( name == "vertical-speed-indicator" ) {
170             set_subsystem( id, new VerticalSpeedIndicator( node ) );
171
172         } else if ( name == "radar" ) {
173             set_subsystem( id, new wxRadarBg ( node ), 1);
174
175         } else if ( name == "inst-vertical-speed-indicator" ) {
176             set_subsystem( id, new InstVerticalSpeedIndicator( node ) );
177
178         } else if ( name == "tacan" ) {
179             set_subsystem( id, new TACAN( node ) );
180
181         } else if ( name == "mk-viii" ) {
182             set_subsystem( id, new MK_VIII( node ) );
183
184         } else if ( name == "master-reference-gyro" ) {
185             set_subsystem( id, new MasterReferenceGyro( node ) );
186
187         } else if ( name == "groundradar" ) {
188             set_subsystem( id, new GroundRadar( node ), 1 );
189
190         } else if ( name == "air-ground-radar" ) {
191             set_subsystem( id, new agRadar( node ),1);
192
193         } else if ( name == "radar-altimeter" ) {
194             set_subsystem( id, new radAlt( node ),1);
195
196         } else {
197             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
198                     << name );
199             return false;
200         }
201     }
202     return true;
203 }
204
205 // end of instrument_manager.cxx