1 // cockpitDisplayManager.cxx -- manage cockpit displays, typically
2 // rendered using a sub-camera or render-texture
4 // Copyright (C) 2012 James Turner zakalawe@mac.com
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.
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.
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.
24 #include "cockpitDisplayManager.hxx"
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>
31 #include <boost/foreach.hpp>
33 #include <Main/fg_props.hxx>
34 #include <Main/globals.hxx>
36 #include "agradar.hxx"
37 #include "NavDisplay.hxx"
38 #include "groundradar.hxx"
39 #include "wxradar.hxx"
44 CockpitDisplayManager::CockpitDisplayManager ()
48 CockpitDisplayManager::~CockpitDisplayManager ()
52 SGSubsystem::InitStatus CockpitDisplayManager::incrementalInit()
58 void CockpitDisplayManager::init()
60 SGPropertyNode_ptr config_props = new SGPropertyNode;
61 SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
63 SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
67 SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
68 SG_LOG( SG_COCKPIT, SG_INFO, "Reading cockpit displays from " << config.str() );
71 readProperties( config.str(), config_props );
72 if (!build(config_props)) {
74 "Detected an internal inconsistency in the instrumentation\n"
75 "system specification file. See earlier errors for details.");
77 } catch (const sg_exception& e) {
78 SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
79 << config.str() << ":" << e.getFormattedMessage() );
82 // bind() created instruments before init.
83 BOOST_FOREACH(std::string s, _displays) {
84 get_subsystem(s)->bind();
87 SGSubsystemGroup::init();
90 bool CockpitDisplayManager::build (SGPropertyNode* config_props)
92 for ( int i = 0; i < config_props->nChildren(); ++i ) {
93 SGPropertyNode *node = config_props->getChild(i);
94 std::string name = node->getName();
96 std::ostringstream subsystemname;
97 subsystemname << "instrument-" << i << '-'
98 << node->getStringValue("name", name.c_str());
99 int index = node->getIntValue("number", 0);
101 subsystemname << '['<< index << ']';
102 std::string id = subsystemname.str();
104 if ( name == "radar" ) {
105 set_subsystem( id, new wxRadarBg ( node ) );
107 } else if ( name == "groundradar" ) {
108 set_subsystem( id, new GroundRadar( node ) );
110 } else if ( name == "air-ground-radar" ) {
111 set_subsystem( id, new agRadar( node ) );
113 } else if ( name == "navigation-display" ) {
114 set_subsystem( id, new NavDisplay( node ) );
117 // probably a regular instrument
120 // only add to our list if we build a display
121 _displays.push_back(id);
126 } // of namespace flightgear