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