#include <simgear/structure/exception.hxx>
+#include <Airports/runways.hxx>
#include <Navaids/waypoint.hxx>
using std::string;
{
}
+
+Approach* Approach::createTempApproach(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath)
+{
+ Approach* app = new Approach(aIdent, PROCEDURE_APPROACH_RNAV);
+ app->setRunway(aRunway);
+ app->setPrimaryAndMissed(aPath, WayptVec());
+ return app;
+}
void Approach::setRunway(FGRunwayRef aRwy)
{
bool Approach::route(WayptRef aIAF, WayptVec& aWps)
{
- WptTransitionMap::iterator it;
- bool haveTrans = false;
- for (it = _transitions.begin(); it != _transitions.end(); ++it) {
- Transition* t= it->second;
- if (t->enroute()->matches(aIAF)) {
- t->route(aWps);
- haveTrans = true;
- break;
+ if (aIAF.valid()) {
+ WptTransitionMap::iterator it;
+ bool haveTrans = false;
+ for (it = _transitions.begin(); it != _transitions.end(); ++it) {
+ Transition* t= it->second;
+ if (t->enroute()->matches(aIAF)) {
+ t->route(aWps);
+ haveTrans = true;
+ break;
+ }
+ } // of transitions iteration
+
+ if (!haveTrans) {
+ SG_LOG(SG_NAVAID, SG_INFO, "approach " << ident() << " has no transition " <<
+ "for IAF: " << aIAF->ident());
+ return false;
}
- } // of transitions iteration
-
- if (!haveTrans) {
- SG_LOG(SG_GENERAL, SG_INFO, "approach " << ident() << " has no transition " <<
- "for IAF: " << aIAF->ident());
- return false;
}
return routeFromVectors(aWps);
bool Approach::routeFromVectors(WayptVec& aWps)
{
aWps.insert(aWps.end(), _primary.begin(), _primary.end());
- aWps.push_back(new RunwayWaypt(_runway, NULL));
+ RunwayWaypt* rwy = new RunwayWaypt(_runway, NULL);
+ rwy->setFlag(WPT_APPROACH);
+ aWps.push_back(rwy);
aWps.insert(aWps.end(), _missed.begin(), _missed.end());
return true;
}
}
FGRunwayRef r(const_cast<FGRunway*>(aWay));
- return (_runways.count(r));
+ return (_runways.count(r) > 0);
}
RunwayVec ArrivalDeparture::runways() const
return true;
}
- SG_LOG(SG_GENERAL, SG_INFO, ident() << " using runway transition for " << r->first->ident());
+ SG_LOG(SG_NAVAID, SG_INFO, ident() << " using runway transition for " << r->first->ident());
r->second->route(aPath);
return true;
}
WptTransitionMap::const_iterator eit;
for (eit = _enrouteTransitions.begin(); eit != _enrouteTransitions.end(); ++eit) {
if (eit->second->enroute()->matches(aEnroute)) {
- SG_LOG(SG_GENERAL, SG_INFO, ident() << " using enroute transition " << eit->second->ident());
+ SG_LOG(SG_NAVAID, SG_INFO, ident() << " using enroute transition " << eit->second->ident());
return eit->second;
}
} // of enroute transition iteration
{
// no transitions, that's easy
if (_enrouteTransitions.empty()) {
- SG_LOG(SG_GENERAL, SG_INFO, "no enroute transitions for " << ident());
+ SG_LOG(SG_NAVAID, SG_INFO, "no enroute transitions for " << ident());
return _common.front();
}
WptTransitionMap::const_iterator eit;
for (eit = _enrouteTransitions.begin(); eit != _enrouteTransitions.end(); ++eit) {
WayptRef c = eit->second->enroute();
- SG_LOG(SG_GENERAL, SG_INFO, "findBestTransition for " << ident() << ", looking at " << c->ident());
+ SG_LOG(SG_NAVAID, SG_INFO, "findBestTransition for " << ident() << ", looking at " << c->ident());
// assert(c->hasFixedPosition());
double cd = SGGeodesy::distanceM(aPos, c->position());
bool SID::route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath)
{
if (!isForRunway(aWay)) {
- SG_LOG(SG_GENERAL, SG_WARN, "SID " << ident() << " not for runway " << aWay->ident());
+ SG_LOG(SG_NAVAID, SG_WARN, "SID " << ident() << " not for runway " << aWay->ident());
return false;
}
return true;
}
+
+SID* SID::createTempSID(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath)
+{
+// flip waypoints since SID stores them reversed
+ WayptVec path;
+ std::back_insert_iterator<WayptVec> bi(path);
+ std::reverse_copy(aPath.begin(), aPath.end(), bi);
+
+ SID* sid = new SID(aIdent, aRunway->airport());
+ sid->setCommon(path);
+ sid->addRunway(aRunway);
+ return sid;
+}
////////////////////////////////////////////////////////////////////////////