Panel/cockpit loading: report errors
This commit is contained in:
parent
ba783ccce9
commit
14d01ccffe
4 changed files with 38 additions and 40 deletions
|
@ -17,9 +17,7 @@
|
|||
// 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 <config.h>
|
||||
#endif
|
||||
#include <config.h>
|
||||
|
||||
#include "cockpitDisplayManager.hxx"
|
||||
|
||||
|
@ -27,6 +25,7 @@
|
|||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/sg_inlines.h>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
|
@ -58,13 +57,13 @@ 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());
|
||||
if (!config.exists()) {
|
||||
SG_LOG(SG_COCKPIT, SG_DEV_ALERT, "CockpitDisplaysManager: Missing instrumentation file at:" << config);
|
||||
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
|
||||
"CockpitDisplaysManager: Missing instrumentation file", config);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -78,8 +77,9 @@ void CockpitDisplayManager::init()
|
|||
"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 << ":" << e.getFormattedMessage() );
|
||||
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
|
||||
"Failed to load cockpit displays system:" + e.getFormattedMessage(),
|
||||
e.getLocation());
|
||||
}
|
||||
|
||||
SGSubsystemGroup::init();
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
//
|
||||
// $Id$
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h> // for strcmp()
|
||||
|
||||
|
@ -30,6 +28,7 @@
|
|||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||
|
||||
#include <istream>
|
||||
#include <fstream>
|
||||
|
@ -37,6 +36,7 @@
|
|||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/sentryIntegration.hxx>
|
||||
|
||||
#include <GUI/gui.h>
|
||||
|
||||
|
@ -571,7 +571,7 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
|
|||
* scaled automatically if the instrument is not at its preferred size.
|
||||
*/
|
||||
static FGPanelInstrument *
|
||||
readInstrument (const SGPropertyNode * node)
|
||||
readInstrument (const SGPropertyNode * node, const SGPath& path)
|
||||
{
|
||||
const string name = node->getStringValue("name");
|
||||
int x = node->getIntValue("x", -1);
|
||||
|
@ -582,8 +582,8 @@ readInstrument (const SGPropertyNode * node)
|
|||
int h = node->getIntValue("h-base", -1);
|
||||
|
||||
if (x == -1 || y == -1) {
|
||||
SG_LOG( SG_COCKPIT, SG_ALERT,
|
||||
"x and y positions must be specified and > 0" );
|
||||
simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems,
|
||||
"Panel x and y positions must be specified and > 0", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ readInstrument (const SGPropertyNode * node)
|
|||
* Construct the panel from a property tree.
|
||||
*/
|
||||
FGPanel *
|
||||
readPanel (const SGPropertyNode * root)
|
||||
readPanel (const SGPropertyNode * root, const SGPath& path)
|
||||
{
|
||||
SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " <<
|
||||
root->getStringValue("name", "[Unnamed Panel]") );
|
||||
|
@ -742,7 +742,7 @@ readPanel (const SGPropertyNode * root)
|
|||
for (int i = 0; i < nInstruments; i++) {
|
||||
const SGPropertyNode * node = instrument_group->getChild(i);
|
||||
if (!strcmp(node->getName(), "instrument")) {
|
||||
FGPanelInstrument * instrument = readInstrument(node);
|
||||
FGPanelInstrument * instrument = readInstrument(node, path);
|
||||
if (instrument != 0)
|
||||
panel->addInstrument(instrument);
|
||||
} else if (!strcmp(node->getName(), "special-instrument")) {
|
||||
|
@ -822,12 +822,13 @@ fgReadPanel (istream &input)
|
|||
SGPropertyNode root;
|
||||
|
||||
try {
|
||||
flightgear::SentryXMLErrorSupression xs;
|
||||
readProperties(input, &root);
|
||||
} catch (const sg_exception &e) {
|
||||
guiErrorMessage("Error reading panel: ", e);
|
||||
return 0;
|
||||
}
|
||||
return readPanel(&root);
|
||||
return readPanel(&root, SGPath{});
|
||||
}
|
||||
|
||||
|
||||
|
@ -844,18 +845,20 @@ fgReadPanel (const string &relative_path)
|
|||
SGPropertyNode root;
|
||||
|
||||
if (!path.exists()) {
|
||||
auto msg = string{"Missing panel file: "} + relative_path;
|
||||
guiErrorMessage(msg.c_str());
|
||||
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
|
||||
"Missing panel file:" + relative_path, path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
try {
|
||||
flightgear::SentryXMLErrorSupression xs;
|
||||
readProperties(path, &root);
|
||||
} catch (const sg_exception &e) {
|
||||
guiErrorMessage("Error reading panel: ", e);
|
||||
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
|
||||
"Error parsing panel file:" + e.getFormattedMessage(), path);
|
||||
return 0;
|
||||
}
|
||||
return readPanel(&root);
|
||||
return readPanel(&root, path);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
//
|
||||
// This file is in the Public Domain and comes with no warranty.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <config.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -15,6 +13,7 @@
|
|||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/sg_inlines.h>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
|
@ -68,13 +67,15 @@ void FGInstrumentMgr::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!");
|
||||
SG_LOG(SG_COCKPIT, SG_DEV_WARN, "No instrumentation model specified for this model!");
|
||||
return;
|
||||
}
|
||||
|
||||
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
|
||||
if (!config.exists()) {
|
||||
SG_LOG(SG_COCKPIT, SG_DEV_ALERT, "Missing instrumentation file at:" << config);
|
||||
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
|
||||
"FGInstrumentMgr: Missing instrumentation file", config);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -82,14 +83,15 @@ void FGInstrumentMgr::init()
|
|||
|
||||
try {
|
||||
readProperties( config, config_props );
|
||||
if (!build(config_props)) {
|
||||
if (!build(config_props, config)) {
|
||||
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 << ":" << e.getFormattedMessage() );
|
||||
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
|
||||
"Failed to load instrumentation system:" + e.getFormattedMessage(),
|
||||
e.getLocation());
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +107,7 @@ void FGInstrumentMgr::init()
|
|||
SGSubsystemGroup::init();
|
||||
}
|
||||
|
||||
bool FGInstrumentMgr::build (SGPropertyNode* config_props)
|
||||
bool FGInstrumentMgr::build (SGPropertyNode* config_props, const SGPath& path)
|
||||
{
|
||||
for ( int i = 0; i < config_props->nChildren(); ++i ) {
|
||||
SGPropertyNode *node = config_props->getChild(i);
|
||||
|
@ -220,8 +222,9 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props)
|
|||
set_subsystem( id, new TCAS( node ), 0.2);
|
||||
|
||||
} else {
|
||||
SG_LOG( SG_INSTR, SG_ALERT,
|
||||
"Unknown top level section in instrumentation: " << name );
|
||||
simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems,
|
||||
"Unknown top level section in instrumentation:" + name,
|
||||
path);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,6 @@
|
|||
#ifndef __INSTRUMENT_MGR_HXX
|
||||
#define __INSTRUMENT_MGR_HXX 1
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
|
||||
|
@ -39,9 +31,9 @@ public:
|
|||
static const char* staticSubsystemClassId() { return "instrumentation"; }
|
||||
|
||||
private:
|
||||
bool build (SGPropertyNode* config_props);
|
||||
bool build (SGPropertyNode* config_props, const SGPath& path);
|
||||
|
||||
bool _explicitGps;
|
||||
bool _explicitGps = false;
|
||||
|
||||
std::vector<std::string> _instruments;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue