| 1 | // cockpitDisplayManager.cxx -- manage cockpit displays, typically |
| 2 | // rendered using a sub-camera or render-texture |
| 3 | // |
| 4 | // Copyright (C) 2012 James Turner [email protected] |
| 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 | #include <config.h> |
| 21 | |
| 22 | #include "cockpitDisplayManager.hxx" |
| 23 | |
| 24 | #include <simgear/structure/exception.hxx> |
| 25 | #include <simgear/misc/sg_path.hxx> |
| 26 | #include <simgear/sg_inlines.h> |
| 27 | #include <simgear/props/props_io.hxx> |
| 28 | #include <simgear/debug/ErrorReportingCallback.hxx> |
| 29 | |
| 30 | #include <Main/fg_props.hxx> |
| 31 | #include <Main/globals.hxx> |
| 32 | |
| 33 | #include "agradar.hxx" |
| 34 | #include "NavDisplay.hxx" |
| 35 | #include "groundradar.hxx" |
| 36 | #include "wxradar.hxx" |
| 37 | |
| 38 | namespace flightgear |
| 39 | { |
| 40 | |
| 41 | CockpitDisplayManager::CockpitDisplayManager () |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | CockpitDisplayManager::~CockpitDisplayManager () |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | SGSubsystem::InitStatus CockpitDisplayManager::incrementalInit() |
| 50 | { |
| 51 | init(); |
| 52 | return INIT_DONE; |
| 53 | } |
| 54 | |
| 55 | void CockpitDisplayManager::init() |
| 56 | { |
| 57 | SGPropertyNode_ptr config_props = new SGPropertyNode; |
| 58 | SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path"); |
| 59 | if (!path_n) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); |
| 64 | if (!config.exists()) { |
| 65 | simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems, |
| 66 | "CockpitDisplaysManager: Missing instrumentation file", config); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | SG_LOG( SG_COCKPIT, SG_INFO, "Reading cockpit displays from " << config ); |
| 71 | |
| 72 | try { |
| 73 | readProperties( config, config_props ); |
| 74 | if (!build(config_props)) { |
| 75 | throw sg_exception( |
| 76 | "Detected an internal inconsistency in the instrumentation\n" |
| 77 | "system specification file. See earlier errors for details."); |
| 78 | } |
| 79 | } catch (const sg_exception& e) { |
| 80 | simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems, |
| 81 | "Failed to load cockpit displays system:" + e.getFormattedMessage(), |
| 82 | e.getLocation()); |
| 83 | } |
| 84 | |
| 85 | SGSubsystemGroup::init(); |
| 86 | } |
| 87 | |
| 88 | bool CockpitDisplayManager::build (SGPropertyNode* config_props) |
| 89 | { |
| 90 | for ( int i = 0; i < config_props->nChildren(); ++i ) { |
| 91 | SGPropertyNode *node = config_props->getChild(i); |
| 92 | std::string name = node->getNameString(); |
| 93 | |
| 94 | std::ostringstream subsystemname; |
| 95 | subsystemname << "instrument-" << i << '-' |
| 96 | << node->getStringValue("name", name.c_str()); |
| 97 | int index = node->getIntValue("number", 0); |
| 98 | if (index > 0) |
| 99 | subsystemname << '['<< index << ']'; |
| 100 | std::string id = subsystemname.str(); |
| 101 | |
| 102 | if ( name == "radar" ) { |
| 103 | set_subsystem( id, new wxRadarBg ( node ) ); |
| 104 | |
| 105 | } else if ( name == "groundradar" ) { |
| 106 | set_subsystem( id, new GroundRadar( node ) ); |
| 107 | |
| 108 | } else if ( name == "air-ground-radar" ) { |
| 109 | set_subsystem( id, new agRadar( node ) ); |
| 110 | |
| 111 | } else if ( name == "navigation-display" ) { |
| 112 | set_subsystem( id, new NavDisplay( node ) ); |
| 113 | |
| 114 | } else { |
| 115 | // probably a regular instrument |
| 116 | continue; |
| 117 | } |
| 118 | // only add to our list if we build a display |
| 119 | _displays.push_back(id); |
| 120 | } |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | // Register the subsystem. |
| 126 | SGSubsystemMgr::Registrant<CockpitDisplayManager> registrantCockpitDisplayManager( |
| 127 | SGSubsystemMgr::DISPLAY); |
| 128 | |
| 129 | } // of namespace flightgear |