#include <simgear/misc/strutils.hxx>
#include <simgear/structure/exception.hxx>
+#include <simgear/misc/sgstream.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/misc/sg_path.hxx>
void FGRouteMgr::loadRoute()
{
- try {
- // deactivate route first
- active->setBoolValue(false);
-
- SGPropertyNode_ptr routeData(new SGPropertyNode);
- SGPath path(_pathNode->getStringValue());
+ // 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());
- SG_LOG(SG_IO, SG_INFO, "going to read flight-plan from:" << path.str());
+ try {
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
SGPropertyNode* dep = routeData->getChild("departure");
if (!dep) {
// cruise
SGPropertyNode* crs = routeData->getChild("cruise");
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
// route nodes
}
SGPropertyNode_ptr altProp = aWP->getChild("altitude-ft");
- double altM = cruise->getDoubleValue("altitude-ft") * SG_FEET_TO_METER;
+ double altM = -9999.0;
if (altProp) {
altM = altProp->getDoubleValue() * SG_FEET_TO_METER;
}
}
}
+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
{
if (!_departure) {