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