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