# include <config.h>
#endif
-#include <cmath> // fabs()
#include <cstdio> // sprintf()
#include <cstdlib> // atoi()
+#include <cassert>
#include <simgear/compiler.h>
-#include <simgear/debug/logstream.hxx>
-#include <Main/fg_props.hxx>
+
+#include <simgear/props/props.hxx>
#include <string>
-#include <map>
#include "runways.hxx"
-using std::istream;
-using std::multimap;
+#include <Airports/simple.hxx>
+#include <Navaids/procedure.hxx>
+
using std::string;
-FGRunway::FGRunway()
+static std::string cleanRunwayNo(const std::string& aRwyNo)
{
-}
-
-FGRunway::FGRunway(const string& rwy_no,
- const double longitude, const double latitude,
- const double heading, const double length,
- const double width,
- const double displ_thresh1, const double displ_thresh2,
- const double stopway1, const double stopway2,
- const int surface_code)
-{
- _rwy_no = rwy_no;
- if (rwy_no[0] == 'x') {
- _type = "taxiway";
- } else {
- _type = "runway";
-
+ if (aRwyNo[0] == 'x') {
+ return std::string(); // no ident for taxiways
+ }
+
+ string result(aRwyNo);
// canonicalise runway ident
- if ((rwy_no.size() == 1) || !isdigit(rwy_no[1])) {
- _rwy_no = "0" + rwy_no;
- }
+ if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
+ result = "0" + aRwyNo;
+ }
- if ((_rwy_no.size() > 2) && (_rwy_no[2] == 'x')) {
- _rwy_no = _rwy_no.substr(0, 2);
+ // trim off trailing garbage
+ if (result.size() > 2) {
+ char suffix = toupper(result[2]);
+ if (suffix == 'X') {
+ result = result.substr(0, 2);
}
}
+
+ return result;
+}
- _lon = longitude;
- _lat = latitude;
- _heading = heading;
- _length = length;
- _width = width;
- _displ_thresh1 = displ_thresh1;
- _displ_thresh2 = displ_thresh2;
- _stopway1 = stopway1;
- _stopway2 = stopway2;
-
- _surface_code = surface_code;
+FGRunway::FGRunway(FGAirport* aAirport, const string& aIdent,
+ const SGGeod& aGeod,
+ const double heading, const double length,
+ const double width,
+ const double displ_thresh,
+ const double stopway,
+ const int surface_code,
+ bool reciprocal) :
+ FGRunwayBase(RUNWAY, cleanRunwayNo(aIdent), aGeod, heading, length, width, surface_code, true),
+ _airport(aAirport),
+ _isReciprocal(reciprocal),
+ _reciprocal(NULL),
+ _displ_thresh(displ_thresh),
+ _stopway(stopway),
+ _ils(NULL)
+{
}
string FGRunway::reverseIdent(const string& aRunwayIdent)
sprintf(buf, "%02i", rn);
if(ident.size() == 3) {
- if(ident.substr(2,1) == "L") {
- buf[2] = 'R';
- buf[3] = '\0';
- } else if (ident.substr(2,1) == "R") {
- buf[2] = 'L';
- buf[3] = '\0';
- } else if (ident.substr(2,1) == "C") {
- buf[2] = 'C';
- buf[3] = '\0';
- } else if (ident.substr(2,1) == "T") {
- buf[2] = 'T';
- buf[3] = '\0';
+ char suffix = toupper(ident[2]);
+ if(suffix == 'L') {
+ buf[2] = 'R';
+ } else if (suffix == 'R') {
+ buf[2] = 'L';
} else {
- SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code "
- << aRunwayIdent << " passed to FGRunway::reverseIdent");
+ // something else, just copy
+ buf[2] = suffix;
}
+
+ buf[3] = 0;
}
return buf;
return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
}
-bool FGRunway::isTaxiway() const
+SGGeod FGRunway::begin() const
+{
+ return pointOnCenterline(0.0);
+}
+
+SGGeod FGRunway::end() const
+{
+ return pointOnCenterline(lengthM());
+}
+
+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()
{
- return (_rwy_no[0] == 'x');
+ 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;
+}
+
+