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