]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/cockpitDisplayManager.cxx
Initial commit for mongoose httpd
[flightgear.git] / src / Cockpit / cockpitDisplayManager.cxx
1 // cockpitDisplayManager.cxx -- manage cockpit displays, typically
2 // rendered using a sub-camera or render-texture
3 //
4 // Copyright (C) 2012 James Turner  zakalawe@mac.com
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifdef HAVE_CONFIG_H
21 #  include <config.h>
22 #endif
23
24 #include "cockpitDisplayManager.hxx"
25
26 #include <simgear/structure/exception.hxx>
27 #include <simgear/misc/sg_path.hxx>
28 #include <simgear/sg_inlines.h>
29 #include <simgear/props/props_io.hxx>
30
31 #include <boost/foreach.hpp>
32
33 #include <Main/fg_props.hxx>
34 #include <Main/globals.hxx>
35
36 #include "agradar.hxx"
37 #include "NavDisplay.hxx"
38 #include "groundradar.hxx"
39 #include "wxradar.hxx"
40
41 namespace flightgear
42 {
43
44 CockpitDisplayManager::CockpitDisplayManager () 
45 {    
46 }
47
48 CockpitDisplayManager::~CockpitDisplayManager ()
49 {
50 }
51
52 SGSubsystem::InitStatus CockpitDisplayManager::incrementalInit()
53 {
54   init();
55   return INIT_DONE;
56 }
57
58 void CockpitDisplayManager::init()
59 {
60   SGPropertyNode_ptr config_props = new SGPropertyNode;
61   SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
62   if (!path_n) {
63     SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
64     return;
65   }
66
67   SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
68   SG_LOG( SG_COCKPIT, SG_INFO, "Reading cockpit displays from " << config.str() );
69
70   try {
71     readProperties( config.str(), config_props );
72     if (!build(config_props)) {
73       throw sg_exception(
74                     "Detected an internal inconsistency in the instrumentation\n"
75                     "system specification file.  See earlier errors for details.");
76     }
77   } catch (const sg_exception& e) {
78     SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
79                     << config.str() << ":" << e.getFormattedMessage() );
80   }
81
82   // bind() created instruments before init.
83   BOOST_FOREACH(std::string s, _displays) {
84       get_subsystem(s)->bind();
85   }
86   
87   SGSubsystemGroup::init();
88 }
89
90 bool CockpitDisplayManager::build (SGPropertyNode* config_props)
91 {
92     for ( int i = 0; i < config_props->nChildren(); ++i ) {
93         SGPropertyNode *node = config_props->getChild(i);
94         std::string name = node->getName();
95
96         std::ostringstream subsystemname;
97         subsystemname << "instrument-" << i << '-'
98                 << node->getStringValue("name", name.c_str());
99         int index = node->getIntValue("number", 0);
100         if (index > 0)
101             subsystemname << '['<< index << ']';
102         std::string id = subsystemname.str();
103       
104         if ( name == "radar" ) {
105             set_subsystem( id, new wxRadarBg ( node ) );
106
107         } else if ( name == "groundradar" ) {
108             set_subsystem( id, new GroundRadar( node ) );
109
110         } else if ( name == "air-ground-radar" ) {
111             set_subsystem( id, new agRadar( node ) );
112       
113         } else if ( name == "navigation-display" ) {
114             set_subsystem( id, new NavDisplay( node ) );
115             
116         } else {
117             // probably a regular instrument
118             continue;
119         }
120         // only add to our list if we build a display
121         _displays.push_back(id);
122     }
123     return true;
124 }
125
126 } // of namespace flightgear