Skip to content

Commit

Permalink
Show runway elevation
Browse files Browse the repository at this point in the history
  • Loading branch information
fpw committed Dec 25, 2021
1 parent 80476b0 commit 17bdbb0
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.9)
project(AviTab VERSION 0.4.7 DESCRIPTION "AviTab X-Plane plugin")
project(AviTab VERSION 0.4.8 DESCRIPTION "AviTab X-Plane plugin")

if (NOT "$ENV{NAVIGRAPH_SECRET}" STREQUAL "")
set(NAVIGRAPH_SECRET "$ENV{NAVIGRAPH_SECRET}" CACHE INTERNAL "Copied from environment variable")
Expand Down
6 changes: 5 additions & 1 deletion src/avitab/apps/AirportApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ std::string AirportApp::toRunwayInfo(std::shared_ptr<xdata::Airport> airport) {
auto aptLoc = airport->getLocation();
auto magneticVariation = api().getMagneticVariation(aptLoc.latitude, aptLoc.longitude);

str << "Runways (Length in X-Plane might differ from real length):\n";
str << "Runways:\n";
airport->forEachRunway([this, &str, &magneticVariation] (const std::shared_ptr<xdata::Runway> rwy) {
str << " " + rwy->getID();
auto ils = rwy->getILSData();
auto elevation = rwy->getElevation();
int rwHeading = (int)(rwy->getHeading() + magneticVariation + 0.5 + 360.0) % 360;
if (ils) {
int ilsHeading = (int)(ils->getILSLocalizer()->getRunwayHeading() + magneticVariation + 0.5 + 360.0) % 360;
Expand All @@ -237,6 +238,9 @@ std::string AirportApp::toRunwayInfo(std::shared_ptr<xdata::Airport> airport) {
if (!std::isnan(rwHeading)) {
str << ", CRS " << rwHeading << "° mag";
}
if (!std::isnan(elevation)) {
str << ", " << (int) elevation << " ft MSL";
}
float length = rwy->getLength();
if (!std::isnan(length)) {
str << ", " << std::to_string((int) (length * xdata::M_TO_FT + 0.5)) << " ft";
Expand Down
23 changes: 23 additions & 0 deletions src/libxdata/parsers/CIFPParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void CIFPParser::parseLine() {
case RecordType::APPROACH:
parseProcedure();
break;
case RecordType::RWY:
parseRunway();
break;
default:
// silently ignore other types for now
return;
Expand Down Expand Up @@ -82,6 +85,26 @@ CIFPParser::RecordType CIFPParser::parseRecordType() {
}
}

void CIFPParser::parseRunway() {
finishAndRestart();

curData.type = CIFPData::ProcedureType::RUNWAY;
curData.id = parser.nextDelimitedWord(','); // runway identifier
parser.nextDelimitedWord(','); // gradient
parser.nextDelimitedWord(','); // ellipsoid height
auto elevationStr = parser.nextDelimitedWord(','); // landing threshold elevation
parser.nextDelimitedWord(','); // TCH value
parser.nextDelimitedWord(','); // localizer identifier
auto ilsCatStr = parser.nextDelimitedWord(','); // ILS category
parser.nextDelimitedWord(';'); // threshold crossing height
parser.nextDelimitedWord(','); // latitude
parser.nextDelimitedWord(','); // longitude
parser.nextDelimitedWord(';'); // displacement distance

curData.rwyInfo.elevation = std::strtoul(elevationStr.c_str(), nullptr, 10);
curData.rwyInfo.ilsCategory = std::strtoul(ilsCatStr.c_str(), nullptr, 10);
}

void CIFPParser::parseProcedure() {
parser.nextDelimitedWord(','); // sequence number
std::string type = parser.nextDelimitedWord(','); // type
Expand Down
1 change: 1 addition & 0 deletions src/libxdata/parsers/CIFPParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CIFPParser {
void finishAndRestart();

RecordType parseRecordType();
void parseRunway();
void parseProcedure();
void parseRunwayTransition();
void parseCommonRoute();
Expand Down
10 changes: 9 additions & 1 deletion src/libxdata/parsers/objects/CIFPData.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ struct CIFPData {
NONE,
SID,
STAR,
APPROACH
APPROACH,
RUNWAY,
};

struct FixInRegion {
Expand Down Expand Up @@ -121,6 +122,12 @@ struct CIFPData {
std::vector<FixInRegion> fixes;
};

// For type = runway
struct RunwayInfo {
int elevation = 0;
int ilsCategory = 0;
};

ProcedureType type = ProcedureType::NONE;
std::string id;

Expand All @@ -129,6 +136,7 @@ struct CIFPData {
std::map<std::string, EnrouteTransition> enrouteTransitions; // key is destination fix, e.g. "COREZ"
std::map<std::string, ApproachTransition> approachTransitions; // key is approach name, e.g. "RAR25"
std::vector<FixInRegion> approach;
RunwayInfo rwyInfo{};
};

} /* namespace xdata */
Expand Down
17 changes: 11 additions & 6 deletions src/libxdata/world/loaders/CIFPLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,28 @@ void CIFPLoader::load(std::shared_ptr<Airport> airport, const std::string& file)

void CIFPLoader::onProcedureLoaded(std::shared_ptr<Airport> airport, const CIFPData& procedure) {
switch (procedure.type) {
case CIFPData::ProcedureType::SID: {
case CIFPData::ProcedureType::RUNWAY:
loadRunway(airport, procedure);
case CIFPData::ProcedureType::SID:
loadSID(airport, procedure);
break;
}
case CIFPData::ProcedureType::STAR: {
case CIFPData::ProcedureType::STAR:
loadSTAR(airport, procedure);
break;
}
case CIFPData::ProcedureType::APPROACH: {
case CIFPData::ProcedureType::APPROACH:
loadApproach(airport, procedure);
break;
}
default:
return;
}
}

void CIFPLoader::loadRunway(std::shared_ptr<Airport> airport, const CIFPData& procedure) {
forEveryMatchingRunway(procedure.id, airport, [&procedure] (std::shared_ptr<Runway> rwy) {
rwy->setElevation(procedure.rwyInfo.elevation);
});
}

void CIFPLoader::loadSID(std::shared_ptr<Airport> airport, const CIFPData& procedure) {
auto sid = std::make_shared<SID>(procedure.id);

Expand Down
1 change: 1 addition & 0 deletions src/libxdata/world/loaders/CIFPLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CIFPLoader {

void onProcedureLoaded(std::shared_ptr<Airport> airport, const CIFPData &procedure);

void loadRunway(std::shared_ptr<Airport> airport, const CIFPData &procedure);
void loadSID(std::shared_ptr<Airport> airport, const CIFPData &procedure);
void loadSTAR(std::shared_ptr<Airport> airport, const CIFPData &procedure);
void loadApproach(std::shared_ptr<Airport> airport, const CIFPData &procedure);
Expand Down
8 changes: 8 additions & 0 deletions src/libxdata/world/models/airport/Runway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void Runway::setLength(float l) {
this->length = l;
}

void Runway::setElevation(float e) {
this->elevation = e;
}

void Runway::setLocation(const Location &loc) {
this->location = loc;
}
Expand Down Expand Up @@ -91,6 +95,10 @@ float xdata::Runway::getLength() const {
return length;
}

float xdata::Runway::getElevation() const {
return elevation;
}

xdata::Runway::SurfaceType xdata::Runway::getSurfaceType() const{
return surfaceType;
}
Expand Down
3 changes: 3 additions & 0 deletions src/libxdata/world/models/airport/Runway.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ class Runway: public NavNode {
void setLength(float l);
void setLocation(const Location &loc);
void setSurfaceType(SurfaceType surfaceType);
void setElevation(float elevation);
float getHeading() const; // can be NaN
float getLength() const; // can be NaN
float getElevation() const; // can be NaN

const std::string &getID() const override;
const Location &getLocation() const override;
Expand All @@ -68,6 +70,7 @@ class Runway: public NavNode {
private:
std::string name;
Location location;
float elevation = std::numeric_limits<float>::quiet_NaN(); // feet MSL
float width = std::numeric_limits<float>::quiet_NaN(); // meters
float heading = std::numeric_limits<float>::quiet_NaN(); // degrees
float length = std::numeric_limits<float>::quiet_NaN(); // meters
Expand Down

0 comments on commit 17bdbb0

Please sign in to comment.