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