]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
01de836b388c440def7f4d7a84fd1fd44225f963
[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
47
48 FGInstrumentMgr::FGInstrumentMgr ()
49 {
50     set_subsystem("annunciator", new Annunciator);
51     set_subsystem("od_gauge", new FGODGauge, 1.0);
52
53     config_props = new SGPropertyNode;
54
55     SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
56
57     if (path_n) {
58         SGPath config( globals->get_fg_root() );
59         config.append( path_n->getStringValue() );
60
61         SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
62                 << config.str() );
63         try {
64             readProperties( config.str(), config_props );
65
66             if ( build() ) {
67                 enabled = true;
68             } else {
69                 SG_LOG( SG_ALL, SG_ALERT,
70                         "Detected an internal inconsistency in the instrumentation");
71                 SG_LOG( SG_ALL, SG_ALERT,
72                         " system specification file.  See earlier errors for" );
73                 SG_LOG( SG_ALL, SG_ALERT,
74                         " details.");
75                 exit(-1);
76             }
77         } catch (const sg_exception& exc) {
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     SGPropertyNode *node;
97     int i;
98
99     int count = config_props->nChildren();
100     for ( i = 0; i < count; ++i ) {
101         node = config_props->getChild(i);
102         string name = node->getName();
103         std::ostringstream temp;
104         temp << i;
105         if ( name == "adf" ) {
106             set_subsystem( "instrument" + temp.str(), 
107                            new ADF( node ), 0.15 );
108         } else if ( name == "airspeed-indicator" ) {
109             set_subsystem( "instrument" + temp.str(), 
110                            new AirspeedIndicator( node ) );
111         } else if ( name == "altimeter" ) {
112             set_subsystem( "instrument" + temp.str(), 
113                            new Altimeter( node ) );
114         } else if ( name == "attitude-indicator" ) {
115             set_subsystem( "instrument" + temp.str(), 
116                            new AttitudeIndicator( node ) );
117         } else if ( name == "clock" ) {
118             set_subsystem( "instrument" + temp.str(), 
119                            new Clock( node ), 0.25 );
120         } else if ( name == "dme" ) {
121             set_subsystem( "instrument" + temp.str(), 
122                            new DME( node ), 1.0 );
123         } else if ( name == "encoder" ) {
124             set_subsystem( "instrument" + temp.str(), 
125                            new Encoder( node ) );
126         } else if ( name == "gps" ) {
127             set_subsystem( "instrument" + temp.str(), 
128                            new GPS( node ), 0.45 );
129         } else if ( name == "heading-indicator" ) {
130             set_subsystem( "instrument" + temp.str(), 
131                            new HeadingIndicator( node ) );
132         } else if ( name == "KR-87" ) {
133             set_subsystem( "instrument" + temp.str(), 
134                            new FGKR_87( node ) );
135         } else if ( name == "KT-70" ) {
136             set_subsystem( "instrument" + temp.str(), 
137                            new FGKT_70( node ) );
138         } else if ( name == "magnetic-compass" ) {
139             set_subsystem( "instrument" + temp.str(), 
140                            new MagCompass( node ) );
141         } else if ( name == "marker-beacon" ) {
142             set_subsystem( "instrument" + temp.str(), 
143                            new FGMarkerBeacon( node ) );
144         } else if ( name == "nav-radio" ) {
145             set_subsystem( "instrument" + temp.str(), 
146                            new FGNavRadio( node ) );
147         } else if ( name == "slip-skid-ball" ) {
148             set_subsystem( "instrument" + temp.str(), 
149                            new SlipSkidBall( node ) );
150         } else if ( name == "transponder" ) {
151             set_subsystem( "instrument" + temp.str(), 
152                            new Transponder( node ) );
153         } else if ( name == "turn-indicator" ) {
154             set_subsystem( "instrument" + temp.str(), 
155                            new TurnIndicator( node ) );
156         } else if ( name == "vertical-speed-indicator" ) {
157             set_subsystem( "instrument" + temp.str(), 
158                            new VerticalSpeedIndicator( node ) );
159         } else if ( name == "wxradar" ) {
160             set_subsystem( "instrument" + temp.str(), 
161                            new wxRadarBg ( node ), 0.5 );
162         } else if ( name == "inst-vertical-speed-indicator" ) { // (TJ)
163             set_subsystem( "instrument" + temp.str(), 
164                            new InstVerticalSpeedIndicator( node ) );
165         } else if ( name == "tacan" ) { 
166             set_subsystem( "instrument" + temp.str(), 
167                            new TACAN( node ) );
168         } else {
169             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
170                     << name );
171             return false;
172         }
173     }
174     return true;
175 }
176
177 // end of instrument_manager.cxx