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