]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
- remove evil exit()
[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                 throw sg_throwable(string(
69                         "Detected an internal inconsistency in the instrumentation\n"
70                         "system specification file.  See earlier errors for details."));
71             }
72         } catch (const sg_exception& exc) {
73             SG_LOG( SG_ALL, SG_ALERT, "Failed to load instrumentation system model: "
74                     << config.str() );
75         }
76
77     } else {
78         SG_LOG( SG_ALL, SG_WARN,
79                 "No instrumentation model specified for this model!");
80     }
81
82     delete config_props;
83 }
84
85 FGInstrumentMgr::~FGInstrumentMgr ()
86 {
87 }
88
89 bool FGInstrumentMgr::build ()
90 {
91     SGPropertyNode *node;
92     int i;
93
94     int count = config_props->nChildren();
95     for ( i = 0; i < count; ++i ) {
96         node = config_props->getChild(i);
97         string name = node->getName();
98         std::ostringstream temp;
99         temp << i;
100         if ( name == "adf" ) {
101             set_subsystem( "instrument" + temp.str(), 
102                            new ADF( node ), 0.15 );
103         } else if ( name == "airspeed-indicator" ) {
104             set_subsystem( "instrument" + temp.str(), 
105                            new AirspeedIndicator( node ) );
106         } else if ( name == "altimeter" ) {
107             set_subsystem( "instrument" + temp.str(), 
108                            new Altimeter( node ) );
109         } else if ( name == "attitude-indicator" ) {
110             set_subsystem( "instrument" + temp.str(), 
111                            new AttitudeIndicator( node ) );
112         } else if ( name == "clock" ) {
113             set_subsystem( "instrument" + temp.str(), 
114                            new Clock( node ), 0.25 );
115         } else if ( name == "dme" ) {
116             set_subsystem( "instrument" + temp.str(), 
117                            new DME( node ), 1.0 );
118         } else if ( name == "encoder" ) {
119             set_subsystem( "instrument" + temp.str(), 
120                            new Encoder( node ) );
121         } else if ( name == "gps" ) {
122             set_subsystem( "instrument" + temp.str(), 
123                            new GPS( node ), 0.45 );
124         } else if ( name == "heading-indicator" ) {
125             set_subsystem( "instrument" + temp.str(), 
126                            new HeadingIndicator( node ) );
127         } else if ( name == "KR-87" ) {
128             set_subsystem( "instrument" + temp.str(), 
129                            new FGKR_87( node ) );
130         } else if ( name == "KT-70" ) {
131             set_subsystem( "instrument" + temp.str(), 
132                            new FGKT_70( node ) );
133         } else if ( name == "magnetic-compass" ) {
134             set_subsystem( "instrument" + temp.str(), 
135                            new MagCompass( node ) );
136         } else if ( name == "marker-beacon" ) {
137             set_subsystem( "instrument" + temp.str(), 
138                            new FGMarkerBeacon( node ) );
139         } else if ( name == "nav-radio" ) {
140             set_subsystem( "instrument" + temp.str(), 
141                            new FGNavRadio( node ) );
142         } else if ( name == "slip-skid-ball" ) {
143             set_subsystem( "instrument" + temp.str(), 
144                            new SlipSkidBall( node ) );
145         } else if ( name == "transponder" ) {
146             set_subsystem( "instrument" + temp.str(), 
147                            new Transponder( node ) );
148         } else if ( name == "turn-indicator" ) {
149             set_subsystem( "instrument" + temp.str(), 
150                            new TurnIndicator( node ) );
151         } else if ( name == "vertical-speed-indicator" ) {
152             set_subsystem( "instrument" + temp.str(), 
153                            new VerticalSpeedIndicator( node ) );
154         } else if ( name == "wxradar" ) {
155             set_subsystem( "instrument" + temp.str(), 
156                            new wxRadarBg ( node ), 0.5 );
157         } else if ( name == "inst-vertical-speed-indicator" ) { // (TJ)
158             set_subsystem( "instrument" + temp.str(), 
159                            new InstVerticalSpeedIndicator( node ) );
160         } else if ( name == "tacan" ) { 
161             set_subsystem( "instrument" + temp.str(), 
162                            new TACAN( node ) );
163         } else if ( name == "mk-viii" ) { 
164             set_subsystem( "instrument" + temp.str(), 
165                            new MK_VIII( node ) );
166         } else {
167             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
168                     << name );
169             return false;
170         }
171     }
172     return true;
173 }
174
175 // end of instrument_manager.cxx