Support loading plain-text routes, and stop aggressively using the cruise altitude when loading waypoints.
This commit is contained in:
parent
1c7278b474
commit
3270a610f8
2 changed files with 43 additions and 10 deletions
src/Autopilot
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include <simgear/misc/strutils.hxx>
|
#include <simgear/misc/strutils.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
#include <simgear/misc/sgstream.hxx>
|
||||||
|
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
@ -666,16 +667,23 @@ void FGRouteMgr::saveRoute()
|
||||||
|
|
||||||
void FGRouteMgr::loadRoute()
|
void FGRouteMgr::loadRoute()
|
||||||
{
|
{
|
||||||
|
// deactivate route first
|
||||||
|
active->setBoolValue(false);
|
||||||
|
|
||||||
|
SGPropertyNode_ptr routeData(new SGPropertyNode);
|
||||||
|
SGPath path(_pathNode->getStringValue());
|
||||||
|
|
||||||
|
SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// deactivate route first
|
|
||||||
active->setBoolValue(false);
|
|
||||||
|
|
||||||
SGPropertyNode_ptr routeData(new SGPropertyNode);
|
|
||||||
SGPath path(_pathNode->getStringValue());
|
|
||||||
|
|
||||||
SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
|
|
||||||
readProperties(path.str(), routeData);
|
readProperties(path.str(), routeData);
|
||||||
|
} catch (sg_exception& e) {
|
||||||
|
// if XML parsing fails, the file might be simple textual list of waypoints
|
||||||
|
loadPlainTextRoute(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// departure nodes
|
// departure nodes
|
||||||
SGPropertyNode* dep = routeData->getChild("departure");
|
SGPropertyNode* dep = routeData->getChild("departure");
|
||||||
if (!dep) {
|
if (!dep) {
|
||||||
|
@ -704,7 +712,9 @@ void FGRouteMgr::loadRoute()
|
||||||
// cruise
|
// cruise
|
||||||
SGPropertyNode* crs = routeData->getChild("cruise");
|
SGPropertyNode* crs = routeData->getChild("cruise");
|
||||||
if (crs) {
|
if (crs) {
|
||||||
cruise->setDoubleValue(crs->getDoubleValue("speed"));
|
cruise->setDoubleValue("speed-kts", crs->getDoubleValue("speed-kts"));
|
||||||
|
cruise->setDoubleValue("mach", crs->getDoubleValue("mach"));
|
||||||
|
cruise->setDoubleValue("altitude-ft", crs->getDoubleValue("altitude-ft"));
|
||||||
} // of cruise data loading
|
} // of cruise data loading
|
||||||
|
|
||||||
// route nodes
|
// route nodes
|
||||||
|
@ -735,7 +745,7 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
|
||||||
}
|
}
|
||||||
|
|
||||||
SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
|
SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
|
||||||
double altM = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
|
double altM = -9999.0;
|
||||||
if (altProp) {
|
if (altProp) {
|
||||||
altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
|
altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
|
||||||
}
|
}
|
||||||
|
@ -781,6 +791,26 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGRouteMgr::loadPlainTextRoute(const SGPath& path)
|
||||||
|
{
|
||||||
|
sg_gzifstream in(path.str().c_str());
|
||||||
|
if (!in.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_route->clear();
|
||||||
|
while (!in.eof()) {
|
||||||
|
string line;
|
||||||
|
getline(in, line, '\n');
|
||||||
|
// trim CR from end of line, if found
|
||||||
|
if (line[line.size() - 1] == '\r') {
|
||||||
|
line.erase(line.size() - 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
new_waypoint(line, -1);
|
||||||
|
} // of line iteration
|
||||||
|
}
|
||||||
|
|
||||||
const char* FGRouteMgr::getDepartureICAO() const
|
const char* FGRouteMgr::getDepartureICAO() const
|
||||||
{
|
{
|
||||||
if (!_departure) {
|
if (!_departure) {
|
||||||
|
|
|
@ -135,6 +135,9 @@ private:
|
||||||
*/
|
*/
|
||||||
bool checkFinished();
|
bool checkFinished();
|
||||||
|
|
||||||
|
|
||||||
|
void loadPlainTextRoute(const SGPath& path);
|
||||||
|
|
||||||
// tied getters and setters
|
// tied getters and setters
|
||||||
const char* getDepartureICAO() const;
|
const char* getDepartureICAO() const;
|
||||||
const char* getDepartureName() const;
|
const char* getDepartureName() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue