Skip to content

Commit

Permalink
feat: add description_code to fix output
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigTag committed Feb 2, 2025
1 parent f242a95 commit c7d931f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Before building, make sure you have properly created and set an `.env` file in `

## Building the WASM Module Yourself

1. [Download](https://www.docker.com/products/docker-desktop/) Docker Desktop
1. [Install](https://github.com/navigraph/cargo-msfs) cargo-msfs
2. Run `npm run build:wasm` (must be on Windows)
- This will take a while to download and build the first time, but subsequent runs will be quicker
3. The compiled WASM module will be copied to `out` **and** `examples/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navigation_Data_Interface_Aircraft/panel`
Expand Down
1 change: 1 addition & 0 deletions src/database/src/output/airway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) fn map_airways(data: Vec<sql_structs::EnrouteAirways>) -> Vec<Airway>
airway_row.icao_code.unwrap_or("NULL".to_string()),
None,
airway_row.waypoint_ref_table,
airway_row.waypoint_description_code.clone(),
));

if airway_row
Expand Down
167 changes: 85 additions & 82 deletions src/database/src/output/fix.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,85 @@
use serde::Serialize;

use crate::math::Coordinates;

#[derive(Serialize, Copy, Clone)]
pub enum FixType {
#[serde(rename = "A")]
Airport,
#[serde(rename = "N")]
NdbNavaid,
#[serde(rename = "R")]
RunwayThreshold,
#[serde(rename = "G")]
GlsNavaid,
#[serde(rename = "I")]
IlsNavaid,
#[serde(rename = "V")]
VhfNavaid,
#[serde(rename = "W")]
Waypoint,
#[serde(rename = "U")]
None,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone)]
/// Represents a fix which was used as a reference in a procedure or an airway.
///
/// Every `Fix` will have a full data entry as one of these structs somewhere in the database with the same `ident` and
/// `icao_code`:
/// - `Airport`
/// - `NdbNavaid`
/// - `RunwayThreshold`
/// - `GlsNavaid`
/// - `IlsNavaid`
/// - `VhfNavaid`
/// - `Waypoint`
pub struct Fix {
/// The type of fix
pub fix_type: Option<FixType>,
/// The identifier of this fix (not unique), such as `KLAX` or `BI` or `RW17L` or `G07J` or `ISYK` or `YXM` or
/// `GLENN`
pub ident: String,
/// The icao prefix of the region that this fix is in.
pub icao_code: String,
/// The geographic location of this fix
pub location: Coordinates,
/// The identifier of the airport that this fix is associated with, if any
pub airport_ident: Option<String>,
}

impl Fix {
/// Creates a `Fix` by using the latitude and longitude fields, and by parsing the linked id field from a procedure
/// or airway row.
pub fn from_row_data(
lat: f64,
long: f64,
ident: String,
icao_code: String,
airport_ident: Option<String>,
ref_table: Option<String>,
) -> Self {
let fix_type = ref_table.map(|ref_table| match ref_table.as_str() {
"PA" => FixType::Airport,
"PN" | "DB" => FixType::NdbNavaid,
"PG" => FixType::RunwayThreshold,
"PT" => FixType::GlsNavaid,
"PI" => FixType::IlsNavaid,
"D " => FixType::VhfNavaid,
"EA" | "PC" => FixType::Waypoint,
x => panic!("Unexpected table: '{x}'"),
});

Self {
fix_type,
ident,
icao_code,
location: Coordinates { lat, long },
airport_ident,
}
}
}
use serde::Serialize;

use crate::math::Coordinates;

#[derive(Serialize, Copy, Clone)]
pub enum FixType {
#[serde(rename = "A")]
Airport,
#[serde(rename = "N")]
NdbNavaid,
#[serde(rename = "R")]
RunwayThreshold,
#[serde(rename = "G")]
GlsNavaid,
#[serde(rename = "I")]
IlsNavaid,
#[serde(rename = "V")]
VhfNavaid,
#[serde(rename = "W")]
Waypoint,
#[serde(rename = "U")]
None,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone)]
/// Represents a fix which was used as a reference in a procedure or an airway.
///
/// Every `Fix` will have a full data entry as one of these structs somewhere in the database with the same `ident` and
/// `icao_code`:
/// - `Airport`
/// - `NdbNavaid`
/// - `RunwayThreshold`
/// - `GlsNavaid`
/// - `IlsNavaid`
/// - `VhfNavaid`
/// - `Waypoint`
pub struct Fix {
/// The type of fix
pub fix_type: Option<FixType>,
pub fix_code: Option<String>,
/// The identifier of this fix (not unique), such as `KLAX` or `BI` or `RW17L` or `G07J` or `ISYK` or `YXM` or
/// `GLENN`
pub ident: String,
/// The icao prefix of the region that this fix is in.
pub icao_code: String,
/// The geographic location of this fix
pub location: Coordinates,
/// The identifier of the airport that this fix is associated with, if any
pub airport_ident: Option<String>,
}

impl Fix {
/// Creates a `Fix` by using the latitude and longitude fields, and by parsing the linked id field from a procedure
/// or airway row.
pub fn from_row_data(
lat: f64,
long: f64,
ident: String,
icao_code: String,
airport_ident: Option<String>,
ref_table: Option<String>,
fix_code: Option<String>,
) -> Self {
let fix_type = ref_table.map(|ref_table| match ref_table.as_str() {
"PA" => FixType::Airport,
"PN" | "DB" => FixType::NdbNavaid,
"PG" => FixType::RunwayThreshold,
"PT" => FixType::GlsNavaid,
"PI" => FixType::IlsNavaid,
"D " => FixType::VhfNavaid,
"EA" | "PC" => FixType::Waypoint,
x => panic!("Unexpected table: '{x}'"),
});

Self {
fix_type,
ident,
icao_code,
location: Coordinates { lat, long },
airport_ident,
fix_code,
}
}
}
4 changes: 4 additions & 0 deletions src/database/src/output/procedure_leg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
ProcedureLeg {
overfly: leg
.waypoint_description_code
.clone()
.map_or(false, |x| x.chars().nth(1) == Some('Y')),
altitude: leg.altitude1.map(|altitude1| AltitudeContstraint {
altitude1,
Expand All @@ -131,6 +132,7 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
leg.waypoint_icao_code.unwrap(),
Some(leg.airport_identifier.clone()),
leg.waypoint_ref_table,
leg.waypoint_description_code.clone(),
))
} else {
None
Expand All @@ -143,6 +145,7 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
leg.recommended_navaid_icao_code.unwrap(),
Some(leg.airport_identifier.clone()),
leg.recommended_navaid_ref_table,
leg.waypoint_description_code.clone(),
))
} else {
None
Expand All @@ -169,6 +172,7 @@ impl From<sql_structs::Procedures> for ProcedureLeg {
leg.center_waypoint_icao_code.unwrap(),
Some(leg.airport_identifier),
leg.center_waypoint_ref_table,
leg.waypoint_description_code,
))
} else {
None
Expand Down

0 comments on commit c7d931f

Please sign in to comment.