Fix FP delegate when loading GPXs
When load a GPX route, run normal departure/arrival airport callbacks on the delegates. (They are blocked for ‘native’ XML routes to avoid losing SIDs and STARs) https://sourceforge.net/p/flightgear/codetickets/2227/
This commit is contained in:
parent
032f65e643
commit
134685b527
3 changed files with 94 additions and 35 deletions
|
@ -766,8 +766,7 @@ void FlightPlan::saveToProperties(SGPropertyNode* d) const
|
|||
|
||||
bool FlightPlan::load(const SGPath& path)
|
||||
{
|
||||
if (!path.exists())
|
||||
{
|
||||
if (!path.exists()) {
|
||||
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << path
|
||||
<< "'. The file does not exist.");
|
||||
return false;
|
||||
|
@ -779,23 +778,28 @@ bool FlightPlan::load(const SGPath& path)
|
|||
lockDelegates();
|
||||
|
||||
// try different file formats
|
||||
if (loadGpxFormat(path)) // GPX format
|
||||
if (loadGpxFormat(path)) { // GPX format
|
||||
_arrivalChanged = true;
|
||||
_departureChanged = true;
|
||||
Status = true;
|
||||
else
|
||||
if (loadXmlFormat(path)) // XML property data
|
||||
} else if (loadXmlFormat(path)) { // XML property data
|
||||
// we don't want to re-compute the arrival / departure after
|
||||
// a load, since we assume the flight-plan had it specified already
|
||||
// especially, the XML might have a SID/STAR embedded, which we don't
|
||||
// want to lose
|
||||
_arrivalChanged = false;
|
||||
_departureChanged = false;
|
||||
Status = true;
|
||||
else
|
||||
if (loadPlainTextFormat(path)) // simple textual list of waypoints
|
||||
} else if (loadPlainTextFormat(path)) { // simple textual list of waypoints
|
||||
_arrivalChanged = true;
|
||||
_departureChanged = true;
|
||||
Status = true;
|
||||
|
||||
}
|
||||
|
||||
if (Status == true) {
|
||||
setIdent(path.file_base());
|
||||
}
|
||||
|
||||
// mark data as unchanged since this is a clean plan
|
||||
_arrivalChanged = false;
|
||||
_departureChanged = false;
|
||||
_cruiseDataChanged = true;
|
||||
_waypointsChanged = true;
|
||||
unlockDelegates();
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
#include <simgear/misc/sg_dir.hxx>
|
||||
#include <simgear/io/iostreams/sgstream.hxx>
|
||||
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
||||
#include "test_suite/FGTestApi/TestPilot.hxx"
|
||||
|
@ -544,3 +547,53 @@ void RouteManagerTests::testHoldFromNasal()
|
|||
// get back on course
|
||||
FGTestApi::runForTime(60.0);
|
||||
}
|
||||
|
||||
// check that when loading a GPX, airport waypoints are created
|
||||
// by the default delegate
|
||||
// https://sourceforge.net/p/flightgear/codetickets/2227/
|
||||
void RouteManagerTests::loadGPX()
|
||||
{
|
||||
auto rm = globals->get_subsystem<FGRouteMgr>();
|
||||
|
||||
FlightPlanRef f = new FlightPlan;
|
||||
rm->setFlightPlan(f);
|
||||
|
||||
SGPath gpxPath = simgear::Dir::current().path() / "test_gpx.gpx";
|
||||
{
|
||||
sg_ofstream s(gpxPath);
|
||||
s << R"(<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="SkyVector" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
||||
<rte>
|
||||
<name>KJFK-KBOS</name>
|
||||
<rtept lat="40.639928" lon="-73.778692">
|
||||
<name>KJFK</name>
|
||||
<overfly>false</overfly>
|
||||
</rtept>
|
||||
<rtept lat="41.641106" lon="-72.547419">
|
||||
<name>HFD</name>
|
||||
<overfly>false</overfly>
|
||||
</rtept>
|
||||
<rtept lat="42.362944" lon="-71.006389">
|
||||
<name>KBOS</name>
|
||||
<overfly>false</overfly>
|
||||
</rtept>
|
||||
|
||||
</rte>
|
||||
</gpx>
|
||||
)";
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(f->load(gpxPath));
|
||||
|
||||
auto kbos = FGAirport::getByIdent("KBOS");
|
||||
auto kjfk = FGAirport::getByIdent("KJFK");
|
||||
CPPUNIT_ASSERT_EQUAL(kjfk, f->departureAirport());
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<FGRunway*>(nullptr), f->departureRunway());
|
||||
CPPUNIT_ASSERT_EQUAL(3, f->numLegs());
|
||||
CPPUNIT_ASSERT_EQUAL(kbos, f->destinationAirport());
|
||||
|
||||
auto wp1 = f->legAtIndex(1);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string{"HFD"}, wp1->waypoint()->ident());
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class RouteManagerTests : public CppUnit::TestFixture
|
|||
CPPUNIT_TEST(testHoldFromNasal);
|
||||
CPPUNIT_TEST(testSequenceDiscontinuityAndResume);
|
||||
CPPUNIT_TEST(testHiddenWaypoints);
|
||||
CPPUNIT_TEST(loadGPX);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
|
@ -62,6 +63,7 @@ public:
|
|||
void testHoldFromNasal();
|
||||
void testSequenceDiscontinuityAndResume();
|
||||
void testHiddenWaypoints();
|
||||
void loadGPX();
|
||||
private:
|
||||
GPS* m_gps = nullptr;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue