]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/instrument_mgr.cxx
65e3c1e86c993e540683f8a1f3264fde95bb70b4
[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 "heading_indicator_fg.hxx"
34 #include "kr_87.hxx"
35 #include "kt_70.hxx"
36 #include "mag_compass.hxx"
37 #include "marker_beacon.hxx"
38 #include "navradio.hxx"
39 #include "slip_skid_ball.hxx"
40 #include "transponder.hxx"
41 #include "turn_indicator.hxx"
42 #include "vertical_speed_indicator.hxx"
43 #include "inst_vertical_speed_indicator.hxx" // (TJ)
44 #include "od_gauge.hxx"
45 #include "wxradar.hxx"
46 #include "tacan.hxx" 
47 #include "mk_viii.hxx"
48
49
50 FGInstrumentMgr::FGInstrumentMgr ()
51 {
52     set_subsystem("annunciator", new Annunciator);
53     set_subsystem("od_gauge", new FGODGauge, 1.0);
54
55     config_props = new SGPropertyNode;
56
57     SGPropertyNode *path_n = fgGetNode("/sim/instrumentation/path");
58
59     if (path_n) {
60         SGPath config( globals->get_fg_root() );
61         config.append( path_n->getStringValue() );
62
63         SG_LOG( SG_ALL, SG_INFO, "Reading instruments from "
64                 << config.str() );
65         try {
66             readProperties( config.str(), config_props );
67
68             if ( !build() ) {
69                 throw sg_throwable(string(
70                         "Detected an internal inconsistency in the instrumentation\n"
71                         "system specification file.  See earlier errors for details."));
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 == "heading-indicator-fg" ) {
129             set_subsystem( "instrument" + temp.str(), 
130                            new HeadingIndicatorFG( node ) );
131         } else if ( name == "KR-87" ) {
132             set_subsystem( "instrument" + temp.str(), 
133                            new FGKR_87( node ) );
134         } else if ( name == "KT-70" ) {
135             set_subsystem( "instrument" + temp.str(), 
136                            new FGKT_70( node ) );
137         } else if ( name == "magnetic-compass" ) {
138             set_subsystem( "instrument" + temp.str(), 
139                            new MagCompass( node ) );
140         } else if ( name == "marker-beacon" ) {
141             set_subsystem( "instrument" + temp.str(), 
142                            new FGMarkerBeacon( node ) );
143         } else if ( name == "nav-radio" ) {
144             set_subsystem( "instrument" + temp.str(), 
145                            new FGNavRadio( node ) );
146         } else if ( name == "slip-skid-ball" ) {
147             set_subsystem( "instrument" + temp.str(), 
148                            new SlipSkidBall( node ) );
149         } else if ( name == "transponder" ) {
150             set_subsystem( "instrument" + temp.str(), 
151                            new Transponder( node ) );
152         } else if ( name == "turn-indicator" ) {
153             set_subsystem( "instrument" + temp.str(), 
154                            new TurnIndicator( node ) );
155         } else if ( name == "vertical-speed-indicator" ) {
156             set_subsystem( "instrument" + temp.str(), 
157                            new VerticalSpeedIndicator( node ) );
158         } else if ( name == "wxradar" ) {
159             set_subsystem( "instrument" + temp.str(), 
160                            new wxRadarBg ( node ), 0.5 );
161         } else if ( name == "inst-vertical-speed-indicator" ) { // (TJ)
162             set_subsystem( "instrument" + temp.str(), 
163                            new InstVerticalSpeedIndicator( node ) );
164         } else if ( name == "tacan" ) { 
165             set_subsystem( "instrument" + temp.str(), 
166                            new TACAN( node ) );
167         } else if ( name == "mk-viii" ) { 
168             set_subsystem( "instrument" + temp.str(), 
169                            new MK_VIII( node ) );
170         } else {
171             SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " 
172                     << name );
173             return false;
174         }
175     }
176     return true;
177 }
178
179 // end of instrument_manager.cxx