From 4994973ef4d5a079acf76267b525313c15376478 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 26 Sep 2012 20:30:24 +0100 Subject: [PATCH] Separate instruments from cockpit displays. --- src/Canvas/canvas.hxx | 2 +- src/Cockpit/CMakeLists.txt | 14 ++ .../NavDisplay.cxx | 4 +- .../NavDisplay.hxx | 0 src/{Instrumentation => Cockpit}/agradar.cxx | 0 src/{Instrumentation => Cockpit}/agradar.hxx | 0 src/Cockpit/cockpitDisplayManager.cxx | 126 ++++++++++++++++++ src/Cockpit/cockpitDisplayManager.hxx | 54 ++++++++ .../groundradar.cxx | 0 .../groundradar.hxx | 5 +- src/{Instrumentation => Cockpit}/od_gauge.cxx | 0 src/{Instrumentation => Cockpit}/od_gauge.hxx | 0 .../render_area_2d.cxx | 0 .../render_area_2d.hxx | 0 src/{Instrumentation => Cockpit}/wxradar.cxx | 3 +- src/{Instrumentation => Cockpit}/wxradar.hxx | 0 src/Instrumentation/CMakeLists.txt | 12 -- src/Instrumentation/dclgps.hxx | 3 +- src/Instrumentation/instrument_mgr.cxx | 31 ++--- src/Instrumentation/rad_alt.hxx | 2 +- src/Main/fg_init.cxx | 2 + 21 files changed, 219 insertions(+), 39 deletions(-) rename src/{Instrumentation => Cockpit}/NavDisplay.cxx (99%) rename src/{Instrumentation => Cockpit}/NavDisplay.hxx (100%) rename src/{Instrumentation => Cockpit}/agradar.cxx (100%) rename src/{Instrumentation => Cockpit}/agradar.hxx (100%) create mode 100644 src/Cockpit/cockpitDisplayManager.cxx create mode 100644 src/Cockpit/cockpitDisplayManager.hxx rename src/{Instrumentation => Cockpit}/groundradar.cxx (100%) rename src/{Instrumentation => Cockpit}/groundradar.hxx (99%) rename src/{Instrumentation => Cockpit}/od_gauge.cxx (100%) rename src/{Instrumentation => Cockpit}/od_gauge.hxx (100%) rename src/{Instrumentation => Cockpit}/render_area_2d.cxx (100%) rename src/{Instrumentation => Cockpit}/render_area_2d.hxx (100%) rename src/{Instrumentation => Cockpit}/wxradar.cxx (99%) rename src/{Instrumentation => Cockpit}/wxradar.hxx (100%) diff --git a/src/Canvas/canvas.hxx b/src/Canvas/canvas.hxx index 25cd8e816..207145299 100644 --- a/src/Canvas/canvas.hxx +++ b/src/Canvas/canvas.hxx @@ -23,7 +23,7 @@ #include "property_based_element.hxx" #include -#include +#include #include #include diff --git a/src/Cockpit/CMakeLists.txt b/src/Cockpit/CMakeLists.txt index d68022e77..42b03bac2 100644 --- a/src/Cockpit/CMakeLists.txt +++ b/src/Cockpit/CMakeLists.txt @@ -1,15 +1,29 @@ include(FlightGearComponent) set(SOURCES + cockpitDisplayManager.cxx panel.cxx panel_io.cxx built_in/FGMagRibbon.cxx + agradar.cxx + groundradar.cxx + od_gauge.cxx + render_area_2d.cxx + wxradar.cxx + NavDisplay.cxx ) set(HEADERS + cockpitDisplayManager.hxx panel.hxx panel_io.hxx built_in/FGMagRibbon.hxx + agradar.hxx + groundradar.hxx + od_gauge.hxx + render_area_2d.hxx + wxradar.hxx + NavDisplay.hxx ) diff --git a/src/Instrumentation/NavDisplay.cxx b/src/Cockpit/NavDisplay.cxx similarity index 99% rename from src/Instrumentation/NavDisplay.cxx rename to src/Cockpit/NavDisplay.cxx index ecf9bdfc5..15452a2e9 100644 --- a/src/Instrumentation/NavDisplay.cxx +++ b/src/Cockpit/NavDisplay.cxx @@ -63,7 +63,7 @@ using std::string; #include
#include
-#include +#include "panel.hxx" #include #include #include @@ -71,8 +71,6 @@ using std::string; #include #include #include - -#include "instrument_mgr.hxx" #include "od_gauge.hxx" static const char *DEFAULT_FONT = "typewriter.txf"; diff --git a/src/Instrumentation/NavDisplay.hxx b/src/Cockpit/NavDisplay.hxx similarity index 100% rename from src/Instrumentation/NavDisplay.hxx rename to src/Cockpit/NavDisplay.hxx diff --git a/src/Instrumentation/agradar.cxx b/src/Cockpit/agradar.cxx similarity index 100% rename from src/Instrumentation/agradar.cxx rename to src/Cockpit/agradar.cxx diff --git a/src/Instrumentation/agradar.hxx b/src/Cockpit/agradar.hxx similarity index 100% rename from src/Instrumentation/agradar.hxx rename to src/Cockpit/agradar.hxx diff --git a/src/Cockpit/cockpitDisplayManager.cxx b/src/Cockpit/cockpitDisplayManager.cxx new file mode 100644 index 000000000..18e6e7d8a --- /dev/null +++ b/src/Cockpit/cockpitDisplayManager.cxx @@ -0,0 +1,126 @@ +// cockpitDisplayManager.cxx -- manage cockpit displays, typically +// rendered using a sub-camera or render-texture +// +// Copyright (C) 2012 James Turner zakalawe@mac.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "cockpitDisplayManager.hxx" + +#include +#include +#include +#include + +#include + +#include
+#include
+ +#include "agradar.hxx" +#include "NavDisplay.hxx" +#include "groundradar.hxx" +#include "wxradar.hxx" + +namespace flightgear +{ + +CockpitDisplayManager::CockpitDisplayManager () +{ +} + +CockpitDisplayManager::~CockpitDisplayManager () +{ +} + +SGSubsystem::InitStatus CockpitDisplayManager::incrementalInit() +{ + init(); + return INIT_DONE; +} + +void CockpitDisplayManager::init() +{ + SGPropertyNode_ptr config_props = new SGPropertyNode; + SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path"); + if (!path_n) { + SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!"); + return; + } + + SGPath config = globals->resolve_aircraft_path(path_n->getStringValue()); + SG_LOG( SG_COCKPIT, SG_INFO, "Reading cockpit displays from " << config.str() ); + + try { + readProperties( config.str(), config_props ); + if (!build(config_props)) { + throw sg_exception( + "Detected an internal inconsistency in the instrumentation\n" + "system specification file. See earlier errors for details."); + } + } catch (const sg_exception& e) { + SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: " + << config.str() << ":" << e.getFormattedMessage() ); + } + + // bind() created instruments before init. + BOOST_FOREACH(std::string s, _displays) { + get_subsystem(s)->bind(); + } + + SGSubsystemGroup::init(); +} + +bool CockpitDisplayManager::build (SGPropertyNode* config_props) +{ + for ( int i = 0; i < config_props->nChildren(); ++i ) { + SGPropertyNode *node = config_props->getChild(i); + std::string name = node->getName(); + + std::ostringstream subsystemname; + subsystemname << "instrument-" << i << '-' + << node->getStringValue("name", name.c_str()); + int index = node->getIntValue("number", 0); + if (index > 0) + subsystemname << '['<< index << ']'; + std::string id = subsystemname.str(); + + if ( name == "radar" ) { + set_subsystem( id, new wxRadarBg ( node ) ); + + } else if ( name == "groundradar" ) { + set_subsystem( id, new GroundRadar( node ) ); + + } else if ( name == "air-ground-radar" ) { + set_subsystem( id, new agRadar( node ) ); + + } else if ( name == "navigation-display" ) { + set_subsystem( id, new NavDisplay( node ) ); + + } else { + // probably a regular instrument + continue; + } + // only add to our list if we build a display + _displays.push_back(id); + } + return true; +} + +} // of namespace flightgear diff --git a/src/Cockpit/cockpitDisplayManager.hxx b/src/Cockpit/cockpitDisplayManager.hxx new file mode 100644 index 000000000..53febaff9 --- /dev/null +++ b/src/Cockpit/cockpitDisplayManager.hxx @@ -0,0 +1,54 @@ +// cockpitDisplayManager.hxx -- manage cockpit displays, typically +// rendered using a sub-camera or render-texture +// +// Copyright (C) 2012 James Turner zakalawe@mac.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#ifndef COCKPIT_DISPLAY_MGR_HXX +#define COCKPIT_DISPLAY_MGR_HXX 1 + +#include + +#include +#include + +class SGPropertyNode; + +namespace flightgear +{ + +/** + * Manage aircraft displays. + */ +class CockpitDisplayManager : public SGSubsystemGroup +{ +public: + + CockpitDisplayManager (); + virtual ~CockpitDisplayManager (); + + virtual void init(); + virtual InitStatus incrementalInit(); + +private: + bool build (SGPropertyNode* config_props); + + std::vector _displays; +}; + +} // of namespace lfightgear + +#endif // COCKPIT_DISPLAY_MGR_HXX diff --git a/src/Instrumentation/groundradar.cxx b/src/Cockpit/groundradar.cxx similarity index 100% rename from src/Instrumentation/groundradar.cxx rename to src/Cockpit/groundradar.cxx diff --git a/src/Instrumentation/groundradar.hxx b/src/Cockpit/groundradar.hxx similarity index 99% rename from src/Instrumentation/groundradar.hxx rename to src/Cockpit/groundradar.hxx index fb603be19..ec439c273 100644 --- a/src/Instrumentation/groundradar.hxx +++ b/src/Cockpit/groundradar.hxx @@ -22,12 +22,15 @@ #include #include + #include -#include "od_gauge.hxx" #include +#include "od_gauge.hxx" + // forward decls class FGRunwayBase; +class FGPavement; //////////////////////////////////////////////////////////////////////// // Built-in layer for the atc radar. diff --git a/src/Instrumentation/od_gauge.cxx b/src/Cockpit/od_gauge.cxx similarity index 100% rename from src/Instrumentation/od_gauge.cxx rename to src/Cockpit/od_gauge.cxx diff --git a/src/Instrumentation/od_gauge.hxx b/src/Cockpit/od_gauge.hxx similarity index 100% rename from src/Instrumentation/od_gauge.hxx rename to src/Cockpit/od_gauge.hxx diff --git a/src/Instrumentation/render_area_2d.cxx b/src/Cockpit/render_area_2d.cxx similarity index 100% rename from src/Instrumentation/render_area_2d.cxx rename to src/Cockpit/render_area_2d.cxx diff --git a/src/Instrumentation/render_area_2d.hxx b/src/Cockpit/render_area_2d.hxx similarity index 100% rename from src/Instrumentation/render_area_2d.hxx rename to src/Cockpit/render_area_2d.hxx diff --git a/src/Instrumentation/wxradar.cxx b/src/Cockpit/wxradar.cxx similarity index 99% rename from src/Instrumentation/wxradar.cxx rename to src/Cockpit/wxradar.cxx index c773c6c2c..2d3ce04c5 100644 --- a/src/Instrumentation/wxradar.cxx +++ b/src/Cockpit/wxradar.cxx @@ -56,9 +56,8 @@ using std::string; #include
#include
-#include -#include "instrument_mgr.hxx" +#include "panel.hxx" // for FGTextureManager #include "od_gauge.hxx" #include "wxradar.hxx" diff --git a/src/Instrumentation/wxradar.hxx b/src/Cockpit/wxradar.hxx similarity index 100% rename from src/Instrumentation/wxradar.hxx rename to src/Cockpit/wxradar.hxx diff --git a/src/Instrumentation/CMakeLists.txt b/src/Instrumentation/CMakeLists.txt index 4060b83b9..ba0ba8b7b 100644 --- a/src/Instrumentation/CMakeLists.txt +++ b/src/Instrumentation/CMakeLists.txt @@ -2,7 +2,6 @@ include(FlightGearComponent) set(SOURCES adf.cxx - agradar.cxx airspeed_indicator.cxx altimeter.cxx attitude_indicator.cxx @@ -10,7 +9,6 @@ set(SOURCES dclgps.cxx dme.cxx gps.cxx - groundradar.cxx gsdi.cxx gyro.cxx heading_indicator.cxx @@ -26,9 +24,7 @@ set(SOURCES mrg.cxx navradio.cxx newnavradio.cxx - od_gauge.cxx rad_alt.cxx - render_area_2d.cxx rnav_waypt_controller.cxx slip_skid_ball.cxx tacan.cxx @@ -36,8 +32,6 @@ set(SOURCES transponder.cxx turn_indicator.cxx vertical_speed_indicator.cxx - wxradar.cxx - NavDisplay.cxx HUD/HUD.cxx HUD/HUD_dial.cxx HUD/HUD_gauge.cxx @@ -69,7 +63,6 @@ set(SOURCES set(HEADERS adf.hxx - agradar.hxx airspeed_indicator.hxx altimeter.hxx attitude_indicator.hxx @@ -77,7 +70,6 @@ set(HEADERS dclgps.hxx dme.hxx gps.hxx - groundradar.hxx gsdi.hxx gyro.hxx heading_indicator.hxx @@ -93,9 +85,7 @@ set(HEADERS mrg.hxx navradio.hxx newnavradio.hxx - od_gauge.hxx rad_alt.hxx - render_area_2d.hxx rnav_waypt_controller.hxx slip_skid_ball.hxx tacan.hxx @@ -103,8 +93,6 @@ set(HEADERS transponder.hxx turn_indicator.hxx vertical_speed_indicator.hxx - wxradar.hxx - NavDisplay.hxx HUD/HUD.hxx HUD/HUD_private.hxx KLN89/kln89.hxx diff --git a/src/Instrumentation/dclgps.hxx b/src/Instrumentation/dclgps.hxx index 1eeadfd67..405c5a70b 100644 --- a/src/Instrumentation/dclgps.hxx +++ b/src/Instrumentation/dclgps.hxx @@ -26,7 +26,8 @@ #ifndef _DCLGPS_HXX #define _DCLGPS_HXX -#include "render_area_2d.hxx" +#include + #include #include #include diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index 86b09e13e..b9e30154d 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -42,15 +42,11 @@ #include "turn_indicator.hxx" #include "vertical_speed_indicator.hxx" #include "inst_vertical_speed_indicator.hxx" -#include "wxradar.hxx" #include "tacan.hxx" #include "mk_viii.hxx" #include "mrg.hxx" -#include "groundradar.hxx" -#include "agradar.hxx" #include "rad_alt.hxx" #include "tcas.hxx" -#include "NavDisplay.hxx" FGInstrumentMgr::FGInstrumentMgr () : _explicitGps(false) @@ -124,7 +120,6 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props) if (index > 0) subsystemname << '['<< index << ']'; string id = subsystemname.str(); - _instruments.push_back(id); if ( name == "adf" ) { set_subsystem( id, new ADF( node ), 0.15 ); @@ -189,9 +184,6 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props) } else if ( name == "vertical-speed-indicator" ) { set_subsystem( id, new VerticalSpeedIndicator( node ) ); - } else if ( name == "radar" ) { - set_subsystem( id, new wxRadarBg ( node ) ); - } else if ( name == "inst-vertical-speed-indicator" ) { set_subsystem( id, new InstVerticalSpeedIndicator( node ) ); @@ -204,27 +196,30 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props) } else if ( name == "master-reference-gyro" ) { set_subsystem( id, new MasterReferenceGyro( node ) ); - } else if ( name == "groundradar" ) { - set_subsystem( id, new GroundRadar( node ) ); - - } else if ( name == "air-ground-radar" ) { - set_subsystem( id, new agRadar( node ) ); - + } else if (( name == "groundradar" ) || + ( name == "radar" ) || + ( name == "air-ground-radar" ) || + ( name == "navigation-display" )) + { + // these instruments are handled by the CockpitDisplayManager + // catch them here so we can still warn about bogus names in + // the instruments file + continue; } else if ( name == "radar-altimeter" ) { set_subsystem( id, new radAlt( node ) ); } else if ( name == "tcas" ) { set_subsystem( id, new TCAS( node ), 0.2); - - } else if ( name == "navigation-display" ) { - set_subsystem( id, new NavDisplay( node ) ); } else { SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: " << name ); return false; } - } + + // only push to our array if we actually built an insturment + _instruments.push_back(id); + } // of instruments iteration return true; } diff --git a/src/Instrumentation/rad_alt.hxx b/src/Instrumentation/rad_alt.hxx index 7ab1e657f..5babe3160 100644 --- a/src/Instrumentation/rad_alt.hxx +++ b/src/Instrumentation/rad_alt.hxx @@ -28,7 +28,7 @@ #include #include -#include "agradar.hxx" +#include class radAlt : public agRadar{ public: diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 1def26fe1..9e8c4d83b 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -99,6 +99,7 @@ #include #include #include +#include #include "fg_init.hxx" #include "fg_io.hxx" @@ -607,6 +608,7 @@ void fgCreateSubsystems() { globals->add_subsystem("systems", new FGSystemMgr, SGSubsystemMgr::FDM); globals->add_subsystem("instrumentation", new FGInstrumentMgr, SGSubsystemMgr::FDM); globals->add_subsystem("hud", new HUD, SGSubsystemMgr::DISPLAY); + globals->add_subsystem("cockpit-displays", new flightgear::CockpitDisplayManager, SGSubsystemMgr::DISPLAY); //////////////////////////////////////////////////////////////////// // Initialize the XML Autopilot subsystem. -- 2.39.5