]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/runways.cxx
Expose more things to Nasal for FMSs in particular - still work in progress.
[flightgear.git] / src / Airports / runways.cxx
index 5adfba4f8ac19ec9910a4797b5282526fe17747b..bd2df3038ceddcb1c9d7fa2528a24a9958ab5d53 100644 (file)
 
 #include <cstdio>              // sprintf()
 #include <cstdlib>             // atoi()
+#include <cassert>
 
 #include <simgear/compiler.h>
 
+#include <simgear/props/props.hxx>
+
 #include <string>
 
 #include "runways.hxx"
 
+#include <Airports/simple.hxx>
+#include <Navaids/procedure.hxx>
+#include <Navaids/navrecord.hxx>
+#include <Navaids/PositionedBinding.hxx>
+
 using std::string;
 
 static std::string cleanRunwayNo(const std::string& aRwyNo)
@@ -69,9 +77,11 @@ FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent,
                         bool reciprocal) :
   FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true),
   _airport(aAirport),
-  _reciprocal(reciprocal),
+  _isReciprocal(reciprocal),
+  _reciprocal(NULL),
   _displ_thresh(displ_thresh),
-  _stopway(stopway)
+  _stopway(stopway),
+  _ils(NULL)
 {
 }
 
@@ -120,18 +130,78 @@ double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) con
   return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
 }
 
-SGGeod FGRunway::threshold() const
+SGGeod FGRunway::begin() const
 {
   return pointOnCenterline(0.0);
 }
 
-SGGeod FGRunway::reverseThreshold() const
+SGGeod FGRunway::end() const
 {
   return pointOnCenterline(lengthM());
 }
 
-SGGeod FGRunway::displacedThreshold() const
+SGGeod FGRunway::threshold() const
 {
   return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
 }
 
+void FGRunway::processThreshold(SGPropertyNode* aThreshold)
+{
+  assert(ident() == aThreshold->getStringValue("rwy"));
+  
+  double lon = aThreshold->getDoubleValue("lon"),
+    lat = aThreshold->getDoubleValue("lat");
+  SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM()));
+  
+  _heading = aThreshold->getDoubleValue("hdg-deg");
+  _displ_thresh = aThreshold->getDoubleValue("displ-m") * SG_METER_TO_FEET;
+  _stopway = aThreshold->getDoubleValue("stopw-m") * SG_METER_TO_FEET;
+  
+  // compute the new runway center, based on the threshold lat/lon and length,
+  double offsetFt = (0.5 * _length);
+  SGGeod newCenter;
+  double dummy;
+  SGGeodesy::direct(newThreshold, _heading, offsetFt * SG_FEET_TO_METER, newCenter, dummy);
+  mPosition = newCenter;
+} 
+
+void FGRunway::setReciprocalRunway(FGRunway* other)
+{
+  assert(_reciprocal==NULL);
+  assert((other->_reciprocal == NULL) || (other->_reciprocal == this));
+  
+  _reciprocal = other;
+}
+
+std::vector<flightgear::SID*> FGRunway::getSIDs()
+{
+  std::vector<flightgear::SID*> result;
+  for (unsigned int i=0; i<_airport->numSIDs(); ++i) {
+    flightgear::SID* s = _airport->getSIDByIndex(i);
+    if (s->isForRunway(this)) {
+      result.push_back(s);
+    }
+  } // of SIDs at the airport iteration
+  
+  return result;
+}
+
+std::vector<flightgear::STAR*> FGRunway::getSTARs()
+{
+  std::vector<flightgear::STAR*> result;
+  for (unsigned int i=0; i<_airport->numSTARs(); ++i) {
+    flightgear::STAR* s = _airport->getSTARByIndex(i);
+    if (s->isForRunway(this)) {
+      result.push_back(s);
+    }
+  } // of STARs at the airport iteration
+  
+  return result;
+}
+
+flightgear::PositionedBinding*
+FGRunway::createBinding(SGPropertyNode* nd) const
+{
+    return new flightgear::RunwayBinding(this, nd);
+}
+