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
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "cockpitDisplayManager.hxx"
|
#include "cockpitDisplayManager.hxx"
|
||||||
|
|
||||||
|
@ -27,6 +25,7 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/sg_inlines.h>
|
#include <simgear/sg_inlines.h>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
@ -58,13 +57,13 @@ void CockpitDisplayManager::init()
|
||||||
SGPropertyNode_ptr config_props = new SGPropertyNode;
|
SGPropertyNode_ptr config_props = new SGPropertyNode;
|
||||||
SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
|
SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
|
||||||
if (!path_n) {
|
if (!path_n) {
|
||||||
SG_LOG(SG_COCKPIT, SG_WARN, "No instrumentation model specified for this model!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
|
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
|
||||||
if (!config.exists()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +77,9 @@ void CockpitDisplayManager::init()
|
||||||
"system specification file. See earlier errors for details.");
|
"system specification file. See earlier errors for details.");
|
||||||
}
|
}
|
||||||
} catch (const sg_exception& e) {
|
} catch (const sg_exception& e) {
|
||||||
SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
|
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
|
||||||
<< config << ":" << e.getFormattedMessage() );
|
"Failed to load cockpit displays system:" + e.getFormattedMessage(),
|
||||||
|
e.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
SGSubsystemGroup::init();
|
SGSubsystemGroup::init();
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h> // for strcmp()
|
#include <string.h> // for strcmp()
|
||||||
|
|
||||||
|
@ -30,6 +28,7 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||||
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -37,6 +36,7 @@
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/sentryIntegration.hxx>
|
||||||
|
|
||||||
#include <GUI/gui.h>
|
#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.
|
* scaled automatically if the instrument is not at its preferred size.
|
||||||
*/
|
*/
|
||||||
static FGPanelInstrument *
|
static FGPanelInstrument *
|
||||||
readInstrument (const SGPropertyNode * node)
|
readInstrument (const SGPropertyNode * node, const SGPath& path)
|
||||||
{
|
{
|
||||||
const string name = node->getStringValue("name");
|
const string name = node->getStringValue("name");
|
||||||
int x = node->getIntValue("x", -1);
|
int x = node->getIntValue("x", -1);
|
||||||
|
@ -582,8 +582,8 @@ readInstrument (const SGPropertyNode * node)
|
||||||
int h = node->getIntValue("h-base", -1);
|
int h = node->getIntValue("h-base", -1);
|
||||||
|
|
||||||
if (x == -1 || y == -1) {
|
if (x == -1 || y == -1) {
|
||||||
SG_LOG( SG_COCKPIT, SG_ALERT,
|
simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems,
|
||||||
"x and y positions must be specified and > 0" );
|
"Panel x and y positions must be specified and > 0", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +650,7 @@ readInstrument (const SGPropertyNode * node)
|
||||||
* Construct the panel from a property tree.
|
* Construct the panel from a property tree.
|
||||||
*/
|
*/
|
||||||
FGPanel *
|
FGPanel *
|
||||||
readPanel (const SGPropertyNode * root)
|
readPanel (const SGPropertyNode * root, const SGPath& path)
|
||||||
{
|
{
|
||||||
SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " <<
|
SG_LOG( SG_COCKPIT, SG_INFO, "Reading properties for panel " <<
|
||||||
root->getStringValue("name", "[Unnamed Panel]") );
|
root->getStringValue("name", "[Unnamed Panel]") );
|
||||||
|
@ -742,7 +742,7 @@ readPanel (const SGPropertyNode * root)
|
||||||
for (int i = 0; i < nInstruments; i++) {
|
for (int i = 0; i < nInstruments; i++) {
|
||||||
const SGPropertyNode * node = instrument_group->getChild(i);
|
const SGPropertyNode * node = instrument_group->getChild(i);
|
||||||
if (!strcmp(node->getName(), "instrument")) {
|
if (!strcmp(node->getName(), "instrument")) {
|
||||||
FGPanelInstrument * instrument = readInstrument(node);
|
FGPanelInstrument * instrument = readInstrument(node, path);
|
||||||
if (instrument != 0)
|
if (instrument != 0)
|
||||||
panel->addInstrument(instrument);
|
panel->addInstrument(instrument);
|
||||||
} else if (!strcmp(node->getName(), "special-instrument")) {
|
} else if (!strcmp(node->getName(), "special-instrument")) {
|
||||||
|
@ -822,12 +822,13 @@ fgReadPanel (istream &input)
|
||||||
SGPropertyNode root;
|
SGPropertyNode root;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
flightgear::SentryXMLErrorSupression xs;
|
||||||
readProperties(input, &root);
|
readProperties(input, &root);
|
||||||
} catch (const sg_exception &e) {
|
} catch (const sg_exception &e) {
|
||||||
guiErrorMessage("Error reading panel: ", e);
|
guiErrorMessage("Error reading panel: ", e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return readPanel(&root);
|
return readPanel(&root, SGPath{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -844,18 +845,20 @@ fgReadPanel (const string &relative_path)
|
||||||
SGPropertyNode root;
|
SGPropertyNode root;
|
||||||
|
|
||||||
if (!path.exists()) {
|
if (!path.exists()) {
|
||||||
auto msg = string{"Missing panel file: "} + relative_path;
|
simgear::reportFailure(simgear::LoadFailure::NotFound, simgear::ErrorCode::AircraftSystems,
|
||||||
guiErrorMessage(msg.c_str());
|
"Missing panel file:" + relative_path, path);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
flightgear::SentryXMLErrorSupression xs;
|
||||||
readProperties(path, &root);
|
readProperties(path, &root);
|
||||||
} catch (const sg_exception &e) {
|
} 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 0;
|
||||||
}
|
}
|
||||||
return readPanel(&root);
|
return readPanel(&root, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
//
|
//
|
||||||
// This file is in the Public Domain and comes with no warranty.
|
// This file is in the Public Domain and comes with no warranty.
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -15,6 +13,7 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/sg_inlines.h>
|
#include <simgear/sg_inlines.h>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
|
#include <simgear/debug/ErrorReportingCallback.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
@ -68,13 +67,15 @@ void FGInstrumentMgr::init()
|
||||||
SGPropertyNode_ptr config_props = new SGPropertyNode;
|
SGPropertyNode_ptr config_props = new SGPropertyNode;
|
||||||
SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
|
SGPropertyNode* path_n = fgGetNode("/sim/instrumentation/path");
|
||||||
if (!path_n) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
|
SGPath config = globals->resolve_aircraft_path(path_n->getStringValue());
|
||||||
if (!config.exists()) {
|
if (!config.exists()) {
|
||||||
SG_LOG(SG_COCKPIT, SG_DEV_ALERT, "Missing instrumentation file at:" << config);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +83,15 @@ void FGInstrumentMgr::init()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
readProperties( config, config_props );
|
readProperties( config, config_props );
|
||||||
if (!build(config_props)) {
|
if (!build(config_props, config)) {
|
||||||
throw sg_exception(
|
throw sg_exception(
|
||||||
"Detected an internal inconsistency in the instrumentation\n"
|
"Detected an internal inconsistency in the instrumentation\n"
|
||||||
"system specification file. See earlier errors for details.");
|
"system specification file. See earlier errors for details.");
|
||||||
}
|
}
|
||||||
} catch (const sg_exception& e) {
|
} catch (const sg_exception& e) {
|
||||||
SG_LOG(SG_COCKPIT, SG_ALERT, "Failed to load instrumentation system model: "
|
simgear::reportFailure(simgear::LoadFailure::BadData, simgear::ErrorCode::AircraftSystems,
|
||||||
<< config << ":" << e.getFormattedMessage() );
|
"Failed to load instrumentation system:" + e.getFormattedMessage(),
|
||||||
|
e.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +107,7 @@ void FGInstrumentMgr::init()
|
||||||
SGSubsystemGroup::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 ) {
|
for ( int i = 0; i < config_props->nChildren(); ++i ) {
|
||||||
SGPropertyNode *node = config_props->getChild(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);
|
set_subsystem( id, new TCAS( node ), 0.2);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SG_LOG( SG_INSTR, SG_ALERT,
|
simgear::reportFailure(simgear::LoadFailure::Misconfigured, simgear::ErrorCode::AircraftSystems,
|
||||||
"Unknown top level section in instrumentation: " << name );
|
"Unknown top level section in instrumentation:" + name,
|
||||||
|
path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,6 @@
|
||||||
#ifndef __INSTRUMENT_MGR_HXX
|
#ifndef __INSTRUMENT_MGR_HXX
|
||||||
#define __INSTRUMENT_MGR_HXX 1
|
#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/compiler.h>
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
|
|
||||||
|
@ -39,9 +31,9 @@ public:
|
||||||
static const char* staticSubsystemClassId() { return "instrumentation"; }
|
static const char* staticSubsystemClassId() { return "instrumentation"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool build (SGPropertyNode* config_props);
|
bool build (SGPropertyNode* config_props, const SGPath& path);
|
||||||
|
|
||||||
bool _explicitGps;
|
bool _explicitGps = false;
|
||||||
|
|
||||||
std::vector<std::string> _instruments;
|
std::vector<std::string> _instruments;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue