In the route-manager, track the departure and destination airport objects
* Expose the airport names as properties * Use tied properties to simplify the code
This commit is contained in:
parent
9cdcd76c6b
commit
6a4e458af9
2 changed files with 93 additions and 28 deletions
|
@ -92,15 +92,18 @@ void FGRouteMgr::init() {
|
||||||
magvar = fgGetNode("/environment/magnetic-variation-deg", true);
|
magvar = fgGetNode("/environment/magnetic-variation-deg", true);
|
||||||
|
|
||||||
departure = fgGetNode(RM "departure", true);
|
departure = fgGetNode(RM "departure", true);
|
||||||
|
departure->tie("airport", SGRawValueMethods<FGRouteMgr, const char*>(*this,
|
||||||
|
&FGRouteMgr::getDepartureICAO, &FGRouteMgr::setDepartureICAO));
|
||||||
|
departure->tie("name", SGRawValueMethods<FGRouteMgr, const char*>(*this,
|
||||||
|
&FGRouteMgr::getDepartureName, NULL));
|
||||||
|
|
||||||
// init departure information from current location
|
// init departure information from current location
|
||||||
SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), lat->getDoubleValue(), alt->getDoubleValue());
|
SGGeod pos = SGGeod::fromDegFt(lon->getDoubleValue(), lat->getDoubleValue(), alt->getDoubleValue());
|
||||||
FGAirport* apt = FGAirport::findClosest(pos, 20.0);
|
_departure = FGAirport::findClosest(pos, 20.0);
|
||||||
if (apt) {
|
if (_departure) {
|
||||||
departure->setStringValue("airport", apt->ident().c_str());
|
FGRunway* active = _departure->getActiveRunwayForUsage();
|
||||||
FGRunway* active = apt->getActiveRunwayForUsage();
|
|
||||||
departure->setStringValue("runway", active->ident().c_str());
|
departure->setStringValue("runway", active->ident().c_str());
|
||||||
} else {
|
} else {
|
||||||
departure->setStringValue("airport", "");
|
|
||||||
departure->setStringValue("runway", "");
|
departure->setStringValue("runway", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +112,12 @@ void FGRouteMgr::init() {
|
||||||
|
|
||||||
destination = fgGetNode(RM "destination", true);
|
destination = fgGetNode(RM "destination", true);
|
||||||
destination->getChild("airport", 0, true);
|
destination->getChild("airport", 0, true);
|
||||||
|
|
||||||
|
destination->tie("airport", SGRawValueMethods<FGRouteMgr, const char*>(*this,
|
||||||
|
&FGRouteMgr::getDestinationICAO, &FGRouteMgr::setDestinationICAO));
|
||||||
|
destination->tie("name", SGRawValueMethods<FGRouteMgr, const char*>(*this,
|
||||||
|
&FGRouteMgr::getDestinationName, NULL));
|
||||||
|
|
||||||
destination->getChild("runway", 0, true);
|
destination->getChild("runway", 0, true);
|
||||||
destination->getChild("eta", 0, true);
|
destination->getChild("eta", 0, true);
|
||||||
destination->getChild("touchdown-time", 0, true);
|
destination->getChild("touchdown-time", 0, true);
|
||||||
|
@ -477,36 +486,34 @@ void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
|
||||||
|
|
||||||
bool FGRouteMgr::activate()
|
bool FGRouteMgr::activate()
|
||||||
{
|
{
|
||||||
const FGAirport* depApt = fgFindAirportID(departure->getStringValue("airport"));
|
if (_departure) {
|
||||||
if (depApt) {
|
|
||||||
string runwayId(departure->getStringValue("runway"));
|
string runwayId(departure->getStringValue("runway"));
|
||||||
FGRunway* runway = NULL;
|
FGRunway* runway = NULL;
|
||||||
if (depApt->hasRunwayWithIdent(runwayId)) {
|
if (_departure->hasRunwayWithIdent(runwayId)) {
|
||||||
runway = depApt->getRunwayByIdent(runwayId);
|
runway = _departure->getRunwayByIdent(runwayId);
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_AUTOPILOT, SG_INFO,
|
SG_LOG(SG_AUTOPILOT, SG_INFO,
|
||||||
"route-manager, departure runway not found:" << runwayId);
|
"route-manager, departure runway not found:" << runwayId);
|
||||||
runway = depApt->getActiveRunwayForUsage();
|
runway = _departure->getActiveRunwayForUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
SGWayPoint swp(runway->threshold(),
|
SGWayPoint swp(runway->threshold(),
|
||||||
depApt->ident() + "-" + runway->ident(), runway->name());
|
_departure->ident() + "-" + runway->ident(), runway->name());
|
||||||
add_waypoint(swp, 0);
|
add_waypoint(swp, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const FGAirport* destApt = fgFindAirportID(destination->getStringValue("airport"));
|
if (_destination) {
|
||||||
if (destApt) {
|
|
||||||
string runwayId = (destination->getStringValue("runway"));
|
string runwayId = (destination->getStringValue("runway"));
|
||||||
if (destApt->hasRunwayWithIdent(runwayId)) {
|
if (_destination->hasRunwayWithIdent(runwayId)) {
|
||||||
FGRunway* runway = destApt->getRunwayByIdent(runwayId);
|
FGRunway* runway = _destination->getRunwayByIdent(runwayId);
|
||||||
SGWayPoint swp(runway->end(),
|
SGWayPoint swp(runway->end(),
|
||||||
destApt->ident() + "-" + runway->ident(), runway->name());
|
_destination->ident() + "-" + runway->ident(), runway->name());
|
||||||
add_waypoint(swp);
|
add_waypoint(swp);
|
||||||
} else {
|
} else {
|
||||||
// quite likely, since destination runway may not be known until enroute
|
// quite likely, since destination runway may not be known until enroute
|
||||||
// probably want a listener on the 'destination' node to allow an enroute
|
// probably want a listener on the 'destination' node to allow an enroute
|
||||||
// update
|
// update
|
||||||
add_waypoint(SGWayPoint(destApt->geod(), destApt->ident(), destApt->name()));
|
add_waypoint(SGWayPoint(_destination->geod(), _destination->ident(), _destination->name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,21 +657,17 @@ void FGRouteMgr::loadRoute()
|
||||||
}
|
}
|
||||||
|
|
||||||
string depIdent = dep->getStringValue("airport");
|
string depIdent = dep->getStringValue("airport");
|
||||||
const FGAirport* depApt = fgFindAirportID(depIdent);
|
_departure = (FGAirport*) fgFindAirportID(depIdent);
|
||||||
if (!depApt) {
|
|
||||||
throw sg_io_exception("bad route file, unknown airport:" + depIdent);
|
|
||||||
}
|
|
||||||
|
|
||||||
departure->setStringValue("runway", dep->getStringValue("runway"));
|
|
||||||
|
|
||||||
// destination
|
// destination
|
||||||
SGPropertyNode* dst = routeData->getChild("destination");
|
SGPropertyNode* dst = routeData->getChild("destination");
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
throw sg_io_exception("malformed route file, no destination node");
|
throw sg_io_exception("malformed route file, no destination node");
|
||||||
}
|
}
|
||||||
|
|
||||||
destination->setStringValue("airport", dst->getStringValue("airport"));
|
_destination = (FGAirport*) fgFindAirportID(dst->getStringValue("airport"));
|
||||||
destination->setStringValue("runay", dst->getStringValue("runway"));
|
destination->setStringValue("runway", dst->getStringValue("runway"));
|
||||||
|
|
||||||
// alternate
|
// alternate
|
||||||
SGPropertyNode* alt = routeData->getChild("alternate");
|
SGPropertyNode* alt = routeData->getChild("alternate");
|
||||||
|
@ -681,7 +684,7 @@ void FGRouteMgr::loadRoute()
|
||||||
// route nodes
|
// route nodes
|
||||||
_route->clear();
|
_route->clear();
|
||||||
SGPropertyNode_ptr _route = routeData->getChild("route", 0);
|
SGPropertyNode_ptr _route = routeData->getChild("route", 0);
|
||||||
SGGeod lastPos(depApt->geod());
|
SGGeod lastPos = (_departure ? _departure->geod() : SGGeod());
|
||||||
|
|
||||||
for (int i=0; i<_route->nChildren(); ++i) {
|
for (int i=0; i<_route->nChildren(); ++i) {
|
||||||
SGPropertyNode_ptr wp = _route->getChild("wp", i);
|
SGPropertyNode_ptr wp = _route->getChild("wp", i);
|
||||||
|
@ -751,3 +754,50 @@ void FGRouteMgr::parseRouteWaypoint(SGPropertyNode* aWP)
|
||||||
add_waypoint(swp);
|
add_waypoint(swp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* FGRouteMgr::getDepartureICAO() const
|
||||||
|
{
|
||||||
|
if (!_departure) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return _departure->ident().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* FGRouteMgr::getDepartureName() const
|
||||||
|
{
|
||||||
|
if (!_departure) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return _departure->name().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FGRouteMgr::setDepartureICAO(const char* aIdent)
|
||||||
|
{
|
||||||
|
_departure = FGAirport::findByIdent(aIdent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* FGRouteMgr::getDestinationICAO() const
|
||||||
|
{
|
||||||
|
if (!_destination) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return _destination->ident().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* FGRouteMgr::getDestinationName() const
|
||||||
|
{
|
||||||
|
if (!_destination) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return _destination->name().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FGRouteMgr::setDestinationICAO(const char* aIdent)
|
||||||
|
{
|
||||||
|
_destination = FGAirport::findByIdent(aIdent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
class SGRoute;
|
class SGRoute;
|
||||||
class SGPath;
|
class SGPath;
|
||||||
|
|
||||||
|
class FGAirport;
|
||||||
|
typedef SGSharedPtr<FGAirport> FGAirportRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top level route manager class
|
* Top level route manager class
|
||||||
*
|
*
|
||||||
|
@ -44,7 +47,9 @@ private:
|
||||||
SGRoute* _route;
|
SGRoute* _route;
|
||||||
time_t _takeoffTime;
|
time_t _takeoffTime;
|
||||||
time_t _touchdownTime;
|
time_t _touchdownTime;
|
||||||
|
FGAirportRef _departure;
|
||||||
|
FGAirportRef _destination;
|
||||||
|
|
||||||
// automatic inputs
|
// automatic inputs
|
||||||
SGPropertyNode_ptr lon;
|
SGPropertyNode_ptr lon;
|
||||||
SGPropertyNode_ptr lat;
|
SGPropertyNode_ptr lat;
|
||||||
|
@ -123,6 +128,16 @@ private:
|
||||||
* Returns true if we have.
|
* Returns true if we have.
|
||||||
*/
|
*/
|
||||||
bool checkFinished();
|
bool checkFinished();
|
||||||
|
|
||||||
|
// tied getters and setters
|
||||||
|
const char* getDepartureICAO() const;
|
||||||
|
const char* getDepartureName() const;
|
||||||
|
void setDepartureICAO(const char* aIdent);
|
||||||
|
|
||||||
|
const char* getDestinationICAO() const;
|
||||||
|
const char* getDestinationName() const;
|
||||||
|
void setDestinationICAO(const char* aIdent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGRouteMgr();
|
FGRouteMgr();
|
||||||
|
|
Loading…
Add table
Reference in a new issue