]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/procedure.cxx
NasalCanvas: Clean up and expose Element node ghost
[flightgear.git] / src / Navaids / procedure.cxx
index bff774b4d360d12eaeb3890d33a2302b113d7de0..94afcdd2c69b3cd9f9e6a64dff5696ad0e650705 100644 (file)
@@ -49,6 +49,14 @@ Approach::Approach(const string& aIdent, ProcedureType ty) :
 {
 
 }
+    
+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)
 {
@@ -93,21 +101,23 @@ void Approach::addTransition(Transition* aTrans)
 
 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_GENERAL, 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);
@@ -116,7 +126,9 @@ bool Approach::route(WayptRef aIAF, WayptVec& 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;
 }
@@ -148,7 +160,7 @@ bool ArrivalDeparture::isForRunway(const FGRunway* aWay) const
   }
   
   FGRunwayRef r(const_cast<FGRunway*>(aWay));
-  return (_runways.count(r));
+  return (_runways.count(r) > 0);
 }
 
 RunwayVec ArrivalDeparture::runways() const
@@ -325,6 +337,19 @@ bool SID::route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath)
 
   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;
+}
 
 ////////////////////////////////////////////////////////////////////////////