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,41 +766,45 @@ void FlightPlan::saveToProperties(SGPropertyNode* d) const
|
||||||
|
|
||||||
bool FlightPlan::load(const SGPath& path)
|
bool FlightPlan::load(const SGPath& path)
|
||||||
{
|
{
|
||||||
if (!path.exists())
|
if (!path.exists()) {
|
||||||
{
|
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << path
|
||||||
SG_LOG(SG_NAVAID, SG_ALERT, "Failed to load flight-plan '" << path
|
<< "'. The file does not exist.");
|
||||||
<< "'. The file does not exist.");
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
SG_LOG(SG_NAVAID, SG_INFO, "going to read flight-plan from:" << path);
|
||||||
SG_LOG(SG_NAVAID, SG_INFO, "going to read flight-plan from:" << path);
|
|
||||||
|
bool Status = false;
|
||||||
bool Status = false;
|
lockDelegates();
|
||||||
lockDelegates();
|
|
||||||
|
// try different file formats
|
||||||
// try different file formats
|
if (loadGpxFormat(path)) { // GPX format
|
||||||
if (loadGpxFormat(path)) // GPX format
|
_arrivalChanged = true;
|
||||||
Status = true;
|
_departureChanged = true;
|
||||||
else
|
Status = true;
|
||||||
if (loadXmlFormat(path)) // XML property data
|
} else if (loadXmlFormat(path)) { // XML property data
|
||||||
Status = true;
|
// we don't want to re-compute the arrival / departure after
|
||||||
else
|
// a load, since we assume the flight-plan had it specified already
|
||||||
if (loadPlainTextFormat(path)) // simple textual list of waypoints
|
// especially, the XML might have a SID/STAR embedded, which we don't
|
||||||
Status = true;
|
// want to lose
|
||||||
|
_arrivalChanged = false;
|
||||||
|
_departureChanged = false;
|
||||||
if (Status == true) {
|
Status = true;
|
||||||
setIdent(path.file_base());
|
} else if (loadPlainTextFormat(path)) { // simple textual list of waypoints
|
||||||
}
|
_arrivalChanged = true;
|
||||||
|
_departureChanged = true;
|
||||||
// mark data as unchanged since this is a clean plan
|
Status = true;
|
||||||
_arrivalChanged = false;
|
}
|
||||||
_departureChanged = false;
|
|
||||||
_cruiseDataChanged = true;
|
if (Status == true) {
|
||||||
_waypointsChanged = true;
|
setIdent(path.file_base());
|
||||||
unlockDelegates();
|
}
|
||||||
|
|
||||||
return Status;
|
_cruiseDataChanged = true;
|
||||||
|
_waypointsChanged = true;
|
||||||
|
unlockDelegates();
|
||||||
|
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FlightPlan::load(std::istream &stream)
|
bool FlightPlan::load(std::istream &stream)
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
|
#include <simgear/io/iostreams/sgstream.hxx>
|
||||||
|
|
||||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||||
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
||||||
#include "test_suite/FGTestApi/TestPilot.hxx"
|
#include "test_suite/FGTestApi/TestPilot.hxx"
|
||||||
|
@ -544,3 +547,53 @@ void RouteManagerTests::testHoldFromNasal()
|
||||||
// get back on course
|
// get back on course
|
||||||
FGTestApi::runForTime(60.0);
|
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(testHoldFromNasal);
|
||||||
CPPUNIT_TEST(testSequenceDiscontinuityAndResume);
|
CPPUNIT_TEST(testSequenceDiscontinuityAndResume);
|
||||||
CPPUNIT_TEST(testHiddenWaypoints);
|
CPPUNIT_TEST(testHiddenWaypoints);
|
||||||
|
CPPUNIT_TEST(loadGPX);
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
@ -62,6 +63,7 @@ public:
|
||||||
void testHoldFromNasal();
|
void testHoldFromNasal();
|
||||||
void testSequenceDiscontinuityAndResume();
|
void testSequenceDiscontinuityAndResume();
|
||||||
void testHiddenWaypoints();
|
void testHiddenWaypoints();
|
||||||
|
void loadGPX();
|
||||||
private:
|
private:
|
||||||
GPS* m_gps = nullptr;
|
GPS* m_gps = nullptr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue