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