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