2017-03-21 20:43:42 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2018-03-28 15:30:59 +00:00
|
|
|
#include "test_suite/dataStore.hxx"
|
2021-04-24 20:39:14 +00:00
|
|
|
#include <ctime>
|
2018-03-28 15:30:59 +00:00
|
|
|
|
2020-04-25 17:03:39 +00:00
|
|
|
#include "TestDataLogger.hxx"
|
2019-09-24 10:32:03 +00:00
|
|
|
#include "testGlobals.hxx"
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
#include <simgear/io/iostreams/sgstream.hxx>
|
|
|
|
|
2018-06-11 09:35:09 +00:00
|
|
|
#if defined(HAVE_QT)
|
2018-03-28 22:39:38 +00:00
|
|
|
#include <GUI/QtLauncher.hxx>
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <Main/globals.hxx>
|
2017-03-27 14:37:54 +00:00
|
|
|
#include <Main/options.hxx>
|
2019-04-19 11:26:07 +00:00
|
|
|
#include <Main/util.hxx>
|
|
|
|
#include <Main/FGInterpolator.hxx>
|
2021-06-08 13:20:13 +00:00
|
|
|
#include <Main/locale.hxx>
|
2017-03-27 14:37:54 +00:00
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <Time/TimeManager.hxx>
|
|
|
|
|
2018-06-12 12:28:23 +00:00
|
|
|
#include <simgear/structure/event_mgr.hxx>
|
2017-03-21 20:43:42 +00:00
|
|
|
#include <simgear/timing/timestamp.hxx>
|
2021-02-16 20:25:15 +00:00
|
|
|
#include <simgear/timing/sg_time.hxx>
|
2018-10-10 08:26:06 +00:00
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
2020-07-02 11:13:53 +00:00
|
|
|
#include <simgear/props/props_io.hxx>
|
2017-03-27 14:37:54 +00:00
|
|
|
|
2019-04-23 17:10:39 +00:00
|
|
|
#include <Airports/airport.hxx>
|
|
|
|
#include <Navaids/FlightPlan.hxx>
|
|
|
|
#include <Navaids/waypoint.hxx>
|
2019-09-19 15:05:26 +00:00
|
|
|
#include <Navaids/routePath.hxx>
|
2019-04-23 17:10:39 +00:00
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
#include <Scripting/NasalSys.hxx>
|
|
|
|
|
2019-04-23 17:10:39 +00:00
|
|
|
using namespace flightgear;
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace FGTestApi {
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
bool global_loggingToKML = false;
|
|
|
|
sg_ofstream global_kmlStream;
|
|
|
|
bool global_lineStringOpen = false;
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace setUp {
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
void initTestGlobals(const std::string& testName)
|
|
|
|
{
|
2019-04-19 11:26:07 +00:00
|
|
|
assert(globals == nullptr);
|
2017-03-21 20:43:42 +00:00
|
|
|
globals = new FGGlobals;
|
|
|
|
|
2018-03-28 15:30:59 +00:00
|
|
|
DataStore &data = DataStore::get();
|
2018-06-05 12:31:06 +00:00
|
|
|
if (!data.getFGRoot().exists()) {
|
|
|
|
data.findFGRoot("");
|
|
|
|
}
|
2018-03-28 15:30:59 +00:00
|
|
|
globals->set_fg_root(data.getFGRoot());
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
// current dir
|
|
|
|
SGPath homePath = SGPath::fromUtf8(FGBUILDDIR) / "test_home";
|
|
|
|
if (!homePath.exists()) {
|
|
|
|
(homePath / "dummyFile").create_dir(0755);
|
|
|
|
}
|
2017-03-27 14:37:54 +00:00
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
globals->set_fg_home(homePath);
|
2019-04-19 11:26:07 +00:00
|
|
|
auto props = globals->get_props();
|
|
|
|
props->setStringValue("sim/fg-home", homePath.utf8Str());
|
|
|
|
|
2018-06-11 06:50:36 +00:00
|
|
|
// Activate headless mode.
|
|
|
|
globals->set_headless(true);
|
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
fgSetDefaults();
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2021-04-24 20:39:14 +00:00
|
|
|
auto t = globals->add_new_subsystem<TimeManager>(SGSubsystemMgr::INIT);
|
2021-07-21 09:59:08 +00:00
|
|
|
t->bind();
|
2018-06-10 13:43:20 +00:00
|
|
|
t->init(); // establish mag-var data
|
2018-06-12 12:28:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Both the event manager and subsystem manager are initialised by the
|
|
|
|
* FGGlobals ctor, but only the subsystem manager is destroyed by the dtor.
|
|
|
|
* Here the event manager is added to the subsystem manager so it can be
|
|
|
|
* destroyed via the subsystem manager.
|
|
|
|
*/
|
|
|
|
globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY);
|
2021-06-08 13:20:13 +00:00
|
|
|
|
|
|
|
// necessary to avoid asserts: mark FGLocale as initialized
|
|
|
|
globals->get_locale()->selectLanguage({});
|
2019-04-19 11:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool logPositionToKML(const std::string& testName)
|
|
|
|
{
|
2019-09-18 22:54:32 +00:00
|
|
|
// clear any previous state
|
|
|
|
if (global_loggingToKML) {
|
|
|
|
global_kmlStream.close();
|
|
|
|
global_lineStringOpen = false;
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
SGPath p = SGPath::desktop() / (testName + ".kml");
|
|
|
|
global_kmlStream.open(p);
|
|
|
|
if (!global_kmlStream.is_open()) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "unable to open:" << p);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pre-amble
|
|
|
|
global_kmlStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
|
|
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
|
|
|
|
"<Document>\n";
|
|
|
|
// need more precision for doubles when specifying lat/lon, see
|
|
|
|
// https://xkcd.com/2170/ :)
|
|
|
|
global_kmlStream.precision(12);
|
|
|
|
|
|
|
|
global_loggingToKML = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-08 20:56:54 +00:00
|
|
|
bool logLinestringsToKML(const std::string& testName)
|
|
|
|
{
|
|
|
|
// clear any previous state
|
|
|
|
if (global_loggingToKML) {
|
|
|
|
global_kmlStream.close();
|
|
|
|
global_lineStringOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGPath p = SGPath::desktop() / (testName + ".kml");
|
|
|
|
global_kmlStream.open(p);
|
|
|
|
if (!global_kmlStream.is_open()) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "unable to open:" << p);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// pre-amble
|
|
|
|
global_kmlStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
|
|
|
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
|
|
|
|
"<Document>\n";
|
|
|
|
// need more precision for doubles when specifying lat/lon, see
|
|
|
|
// https://xkcd.com/2170/ :)
|
|
|
|
global_kmlStream.precision(12);
|
|
|
|
|
|
|
|
global_loggingToKML = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:14:38 +00:00
|
|
|
void initStandardNasal(bool withCanvas)
|
2019-04-19 11:26:07 +00:00
|
|
|
{
|
|
|
|
fgInitAllowedPaths();
|
|
|
|
|
|
|
|
auto nasalNode = globals->get_props()->getNode("nasal", true);
|
|
|
|
|
2020-07-02 11:13:53 +00:00
|
|
|
// load loadpriority.xml, for default modules load order
|
|
|
|
|
|
|
|
auto nasalLoadPriority = globals->get_props()->getNode("/sim/nasal-load-priority",true);
|
|
|
|
readProperties(globals->get_fg_root() / "Nasal/loadpriority.xml", nasalLoadPriority);
|
|
|
|
|
2019-09-24 10:39:56 +00:00
|
|
|
// set various props to reduce Nasal errors
|
|
|
|
auto props = globals->get_props();
|
|
|
|
props->setStringValue("sim/flight-model", "null");
|
|
|
|
props->setStringValue("sim/aircraft", "test-suite-aircraft");
|
|
|
|
|
|
|
|
props->setDoubleValue("sim/current-view/config/default-field-of-view-deg", 90.0);
|
|
|
|
// ensure /sim/view/config exists
|
|
|
|
props->setBoolValue("sim/view/config/foo", false);
|
|
|
|
|
|
|
|
props->setBoolValue("sim/rendering/precipitation-gui-enable", false);
|
|
|
|
props->setBoolValue("sim/rendering/precipitation-aircraft-enable", false);
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
// disable various larger modules
|
2020-03-11 17:14:38 +00:00
|
|
|
nasalNode->setBoolValue("canvas/enabled", withCanvas);
|
2019-04-19 11:26:07 +00:00
|
|
|
nasalNode->setBoolValue("jetways/enabled", false);
|
|
|
|
nasalNode->setBoolValue("jetways_edit/enabled", false);
|
|
|
|
nasalNode->setBoolValue("local_weather/enabled", false);
|
|
|
|
|
2019-09-24 10:39:56 +00:00
|
|
|
// Nasal needs the interpolator running
|
|
|
|
globals->add_subsystem("prop-interpolator", new FGInterpolator, SGSubsystemMgr::INIT);
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
// will be inited, since we already did that
|
|
|
|
globals->add_new_subsystem<FGNasalSys>(SGSubsystemMgr::INIT);
|
2018-06-10 13:43:20 +00:00
|
|
|
}
|
2017-03-21 20:43:42 +00:00
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
void populateFPWithoutNasal(flightgear::FlightPlanRef f,
|
2019-04-23 17:10:39 +00:00
|
|
|
const std::string& depICAO, const std::string& depRunway,
|
|
|
|
const std::string& destICAO, const std::string& destRunway,
|
|
|
|
const std::string& waypoints)
|
|
|
|
{
|
|
|
|
FGAirportRef depApt = FGAirport::getByIdent(depICAO);
|
|
|
|
f->setDeparture(depApt->getRunwayByIdent(depRunway));
|
|
|
|
|
|
|
|
|
|
|
|
FGAirportRef destApt = FGAirport::getByIdent(destICAO);
|
|
|
|
f->setDestination(destApt->getRunwayByIdent(destRunway));
|
|
|
|
|
|
|
|
// since we don't have the Nasal route-manager delegate, insert the
|
|
|
|
// runway waypoints manually
|
|
|
|
|
2019-09-25 12:25:53 +00:00
|
|
|
auto depRwy = new RunwayWaypt(f->departureRunway(), f);
|
|
|
|
depRwy->setFlag(WPT_DEPARTURE);
|
|
|
|
f->insertWayptAtIndex(depRwy, -1);
|
2019-04-23 17:10:39 +00:00
|
|
|
|
|
|
|
for (auto ws : simgear::strutils::split(waypoints)) {
|
|
|
|
WayptRef wpt = f->waypointFromString(ws);
|
2020-04-15 15:11:33 +00:00
|
|
|
if (!wpt) {
|
|
|
|
SG_LOG(SG_NAVAID, SG_ALERT, "No waypoint created for:" << ws);
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-23 17:10:39 +00:00
|
|
|
f->insertWayptAtIndex(wpt, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto destRwy = f->destinationRunway();
|
|
|
|
f->insertWayptAtIndex(new BasicWaypt(destRwy->pointOnCenterline(-8 * SG_NM_TO_METER),
|
|
|
|
destRwy->ident() + "-8", f), -1);
|
|
|
|
f->insertWayptAtIndex(new RunwayWaypt(destRwy, f), -1);
|
|
|
|
}
|
2019-04-19 11:26:07 +00:00
|
|
|
|
|
|
|
void populateFPWithNasal(flightgear::FlightPlanRef f,
|
|
|
|
const std::string& depICAO, const std::string& depRunway,
|
|
|
|
const std::string& destICAO, const std::string& destRunway,
|
|
|
|
const std::string& waypoints)
|
|
|
|
{
|
|
|
|
FGAirportRef depApt = FGAirport::getByIdent(depICAO);
|
|
|
|
f->setDeparture(depApt->getRunwayByIdent(depRunway));
|
|
|
|
|
|
|
|
FGAirportRef destApt = FGAirport::getByIdent(destICAO);
|
|
|
|
f->setDestination(destApt->getRunwayByIdent(destRunway));
|
|
|
|
|
|
|
|
// insert after the last departure waypoint
|
|
|
|
int insertIndex = 1;
|
|
|
|
|
|
|
|
for (auto ws : simgear::strutils::split(waypoints)) {
|
|
|
|
WayptRef wpt = f->waypointFromString(ws);
|
|
|
|
f->insertWayptAtIndex(wpt, insertIndex++);
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 17:10:39 +00:00
|
|
|
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
} // End of namespace setUp.
|
2019-04-19 11:26:07 +00:00
|
|
|
|
|
|
|
void beginLineString(const std::string& ident)
|
|
|
|
{
|
|
|
|
global_lineStringOpen = true;
|
|
|
|
global_kmlStream << "<Placemark>\n";
|
|
|
|
if (!ident.empty()) {
|
|
|
|
global_kmlStream << "<name>" << ident << "</name>\n";
|
|
|
|
}
|
|
|
|
global_kmlStream << "<LineString>\n";
|
|
|
|
global_kmlStream << "<tessellate>1</tessellate>\n";
|
|
|
|
global_kmlStream << "<coordinates>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void logCoordinate(const SGGeod& pos)
|
|
|
|
{
|
|
|
|
if (!global_lineStringOpen) {
|
|
|
|
beginLineString({});
|
|
|
|
}
|
|
|
|
|
|
|
|
global_kmlStream << pos.getLongitudeDeg() << "," << pos.getLatitudeDeg() << " " << endl;
|
|
|
|
}
|
2018-07-16 13:59:21 +00:00
|
|
|
|
2020-04-20 13:50:24 +00:00
|
|
|
void rawLogCoordinate(const SGGeod& pos)
|
|
|
|
{
|
|
|
|
global_kmlStream << pos.getLongitudeDeg() << "," << pos.getLatitudeDeg() << " " << endl;
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
void endCurrentLineString()
|
|
|
|
{
|
|
|
|
global_lineStringOpen = false;
|
|
|
|
global_kmlStream <<
|
|
|
|
"</coordinates>\n"
|
|
|
|
"</LineString>\n"
|
|
|
|
"</Placemark>\n" << endl;
|
|
|
|
}
|
|
|
|
|
2018-10-10 08:26:06 +00:00
|
|
|
void setPosition(const SGGeod& g)
|
|
|
|
{
|
2019-04-19 11:26:07 +00:00
|
|
|
if (global_loggingToKML) {
|
|
|
|
if (global_lineStringOpen) {
|
|
|
|
endCurrentLineString();
|
|
|
|
}
|
|
|
|
|
|
|
|
logCoordinate(g);
|
|
|
|
}
|
|
|
|
|
2018-10-10 08:26:06 +00:00
|
|
|
globals->get_props()->setDoubleValue("position/latitude-deg", g.getLatitudeDeg());
|
|
|
|
globals->get_props()->setDoubleValue("position/longitude-deg", g.getLongitudeDeg());
|
|
|
|
globals->get_props()->setDoubleValue("position/altitude-ft", g.getElevationFt());
|
|
|
|
}
|
2021-03-08 20:56:54 +00:00
|
|
|
|
|
|
|
const SGGeod getPosition()
|
|
|
|
{
|
|
|
|
return SGGeod::fromDegFt(
|
|
|
|
globals->get_props()->getDoubleValue("position/latitude-deg"),
|
|
|
|
globals->get_props()->getDoubleValue("position/longitude-deg"),
|
|
|
|
globals->get_props()->getDoubleValue("position/altitude-ft"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-24 10:29:05 +00:00
|
|
|
|
|
|
|
void setPositionAndStabilise(const SGGeod& g)
|
|
|
|
{
|
|
|
|
setPosition(g);
|
|
|
|
for (int i=0; i<60; ++i) {
|
|
|
|
globals->get_subsystem_mgr()->update(0.015);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
|
2019-04-22 10:57:55 +00:00
|
|
|
void runForTime(double t)
|
|
|
|
{
|
2020-04-25 17:03:39 +00:00
|
|
|
const int tickHz = 30;
|
|
|
|
const double tickDuration = 1.0 / tickHz;
|
|
|
|
|
|
|
|
int ticks = static_cast<int>(t * tickHz);
|
2019-04-22 10:57:55 +00:00
|
|
|
assert(ticks > 0);
|
2020-04-25 17:03:39 +00:00
|
|
|
|
|
|
|
const int logInterval = 0.5 * tickHz;
|
|
|
|
int nextLog = 0;
|
|
|
|
|
2021-02-16 20:25:15 +00:00
|
|
|
long startTime = globals->get_time_params()->get_cur_time();
|
|
|
|
|
2019-04-22 10:57:55 +00:00
|
|
|
for (int t = 0; t < ticks; ++t) {
|
2020-04-25 17:03:39 +00:00
|
|
|
globals->inc_sim_time_sec(tickDuration);
|
2021-02-16 20:25:15 +00:00
|
|
|
globals->get_time_params()->update(globals->get_view_position(), startTime, t * tickDuration);
|
2020-04-25 17:03:39 +00:00
|
|
|
globals->get_subsystem_mgr()->update(tickDuration);
|
|
|
|
|
|
|
|
if (nextLog == 0) {
|
|
|
|
if (global_loggingToKML) {
|
|
|
|
logCoordinate(globals->get_aircraft_position());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DataLogger::isActive()) {
|
|
|
|
DataLogger::instance()->writeRecord();
|
|
|
|
}
|
|
|
|
nextLog = logInterval;
|
|
|
|
} else {
|
|
|
|
nextLog--;
|
2019-04-19 11:26:07 +00:00
|
|
|
}
|
2019-04-22 10:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
bool runForTimeWithCheck(double t, RunCheck check)
|
|
|
|
{
|
|
|
|
const int tickHz = 30;
|
|
|
|
const double tickDuration = 1.0 / tickHz;
|
2019-09-25 12:25:53 +00:00
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
int ticks = static_cast<int>(t * tickHz);
|
|
|
|
assert(ticks > 0);
|
2020-04-25 17:03:39 +00:00
|
|
|
const int logInterval = 0.5 * tickHz;
|
2019-04-19 11:26:07 +00:00
|
|
|
int nextLog = 0;
|
|
|
|
|
|
|
|
for (int t = 0; t < ticks; ++t) {
|
2019-09-25 12:25:53 +00:00
|
|
|
globals->inc_sim_time_sec(tickDuration);
|
2019-04-19 11:26:07 +00:00
|
|
|
globals->get_subsystem_mgr()->update(tickDuration);
|
2020-04-25 17:03:39 +00:00
|
|
|
|
|
|
|
if (nextLog == 0) {
|
|
|
|
if (global_loggingToKML) {
|
2019-04-19 11:26:07 +00:00
|
|
|
logCoordinate(globals->get_aircraft_position());
|
|
|
|
}
|
2020-04-25 17:03:39 +00:00
|
|
|
|
|
|
|
if (DataLogger::isActive()) {
|
|
|
|
DataLogger::instance()->writeRecord();
|
|
|
|
}
|
|
|
|
nextLog = logInterval;
|
|
|
|
} else {
|
|
|
|
nextLog--;
|
2019-04-19 11:26:07 +00:00
|
|
|
}
|
2020-04-25 17:03:39 +00:00
|
|
|
|
2019-04-19 11:26:07 +00:00
|
|
|
bool done = check();
|
|
|
|
if (done) {
|
|
|
|
if (global_loggingToKML) {
|
|
|
|
endCurrentLineString();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-19 15:05:26 +00:00
|
|
|
|
2021-04-24 20:39:14 +00:00
|
|
|
void adjustSimulationWorldTime(time_t desiredUnixTime)
|
|
|
|
{
|
|
|
|
int timeOffset = desiredUnixTime - time(nullptr);
|
|
|
|
globals->get_props()->setIntValue("/sim/time/cur-time-override", 0);
|
|
|
|
globals->get_props()->setIntValue("/sim/time/warp", timeOffset);
|
|
|
|
|
|
|
|
globals->get_subsystem<TimeManager>()->update(0.0);
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:05:26 +00:00
|
|
|
void writeFlightPlanToKML(flightgear::FlightPlanRef fp)
|
|
|
|
{
|
2019-09-24 10:39:56 +00:00
|
|
|
if (!global_loggingToKML)
|
|
|
|
return;
|
|
|
|
|
2019-09-19 15:05:26 +00:00
|
|
|
RoutePath rpath(fp);
|
|
|
|
|
|
|
|
for (int i=0; i<fp->numLegs(); ++i) {
|
|
|
|
SGGeodVec legPath = rpath.pathForIndex(i);
|
2020-04-20 13:50:24 +00:00
|
|
|
auto wp = fp->legAtIndex(i)->waypoint();
|
2020-05-30 14:50:09 +00:00
|
|
|
|
|
|
|
writeGeodsToKML("FP-leg-" + wp->ident(), legPath);
|
|
|
|
|
2020-04-20 13:50:24 +00:00
|
|
|
SGGeod legWPPosition = wp->position();
|
|
|
|
writePointToKML("WP " + wp->ident(), legWPPosition);
|
2019-09-19 15:05:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-23 22:14:32 +00:00
|
|
|
void writeGeodsToKML(const std::string &label, const flightgear::SGGeodVec& geods)
|
2019-09-19 15:05:26 +00:00
|
|
|
{
|
|
|
|
if (global_lineStringOpen) {
|
|
|
|
endCurrentLineString();
|
|
|
|
}
|
|
|
|
|
|
|
|
beginLineString(label);
|
|
|
|
|
|
|
|
for (const auto& g : geods) {
|
|
|
|
logCoordinate(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
endCurrentLineString();
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:50:24 +00:00
|
|
|
void writePointToKML(const std::string& ident, const SGGeod& pos)
|
|
|
|
{
|
|
|
|
global_kmlStream << "<Placemark>\n";
|
|
|
|
global_kmlStream << "<name>" << ident << "</name>\n";
|
|
|
|
global_kmlStream << "<Point>\n";
|
|
|
|
global_kmlStream << "<coordinates>\n";
|
|
|
|
rawLogCoordinate(pos);
|
|
|
|
global_kmlStream << "</coordinates>\n";
|
|
|
|
global_kmlStream << "</Point>\n";
|
|
|
|
global_kmlStream << "</Placemark>\n";
|
|
|
|
}
|
|
|
|
|
2019-09-24 10:29:05 +00:00
|
|
|
bool executeNasal(const std::string& code)
|
|
|
|
{
|
|
|
|
auto nasal = globals->get_subsystem<FGNasalSys>();
|
|
|
|
if (!nasal) {
|
|
|
|
throw sg_exception("Nasal not available");
|
|
|
|
}
|
2022-01-05 15:44:50 +00:00
|
|
|
|
|
|
|
nasal->getAndClearErrorList();
|
2022-01-14 06:57:24 +00:00
|
|
|
std::string output, parseErrors;
|
|
|
|
bool ok = nasal->parseAndRunWithOutput(code, output, parseErrors);
|
|
|
|
if (!parseErrors.empty()) {
|
|
|
|
SG_LOG(SG_NASAL, SG_ALERT, "Errors running Nasal:" << parseErrors);
|
2022-01-05 15:44:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-24 10:29:05 +00:00
|
|
|
return ok;
|
|
|
|
}
|
2019-04-19 11:26:07 +00:00
|
|
|
|
2018-07-16 13:59:21 +00:00
|
|
|
namespace tearDown {
|
|
|
|
|
2018-06-10 13:43:20 +00:00
|
|
|
void shutdownTestGlobals()
|
|
|
|
{
|
2018-03-28 22:39:38 +00:00
|
|
|
// The QApplication instance must be destroyed before exit() begins, see
|
|
|
|
// <https://bugreports.qt.io/browse/QTBUG-48709> (otherwise, segfault).
|
2018-06-11 09:35:09 +00:00
|
|
|
#if defined(HAVE_QT)
|
2018-03-28 22:39:38 +00:00
|
|
|
flightgear::shutdownQtApp();
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 20:43:42 +00:00
|
|
|
delete globals;
|
2019-04-19 11:26:07 +00:00
|
|
|
globals = nullptr;
|
|
|
|
|
2021-03-10 20:27:06 +00:00
|
|
|
if (global_kmlStream) {
|
2019-04-19 11:26:07 +00:00
|
|
|
if (global_lineStringOpen) {
|
|
|
|
endCurrentLineString();
|
|
|
|
}
|
|
|
|
// post-amble
|
|
|
|
global_kmlStream << "</Document>\n"
|
|
|
|
"</kml>" << endl;
|
|
|
|
global_kmlStream.close();
|
2019-09-18 22:54:32 +00:00
|
|
|
global_loggingToKML = false;
|
2019-04-19 11:26:07 +00:00
|
|
|
}
|
2018-06-10 13:43:20 +00:00
|
|
|
}
|
2018-07-16 13:59:21 +00:00
|
|
|
|
|
|
|
} // End of namespace tearDown.
|
|
|
|
|
|
|
|
} // End of namespace FGTestApi.
|