sct_reader/loaders/ese/
mod.rs

1use std::{collections::HashMap, fmt::Display, fs::File, io::{BufRead, BufReader}, str::FromStr};
2
3use partial::PartialEse;
4
5use super::euroscope::{self, colour::Colour, error::Error, position::{Position, Valid}, waypoint::RunwayModifier};
6
7
8pub mod reader;
9pub(crate) mod partial;
10
11
12
13
14
15
16
17#[derive(Debug)]
18pub struct Ese {
19    pub colours: HashMap<String, Colour>,
20    pub free_text: Vec<FreeTextGroup>,
21    pub sids_stars: Vec<Airport>,
22    pub non_critical_errors: Vec<(usize, String, Error)>,
23    pub atc_positions: Vec<AtcPosition>,
24}
25impl TryFrom<PartialEse> for Ese {
26    type Error = Error;
27    fn try_from(value: PartialEse) -> Result<Self, Self::Error> {
28        let ese = Ese {
29            colours: value.colours,
30            free_text: value.free_text,
31            sids_stars: value.sids_stars,
32            atc_positions: value.atc_positions,
33            non_critical_errors: vec![],
34        };
35        Ok(ese)
36    }
37}
38#[derive(Debug)]
39pub struct FreeTextGroup {
40    pub name: String,
41    pub entries: Vec<FreeText>,
42}
43
44#[derive(Debug)]
45pub struct FreeText {
46    pub position: Position<Valid>,
47    pub text: String,
48}
49
50
51#[derive(Debug)]
52pub struct Airport {
53    pub identifier: String,
54    pub runways: HashMap<RunwayIdentifier, Vec<Procedure>>
55}
56
57#[derive(Debug)]
58pub enum ProcedureType {
59    SID,
60    STAR,
61}
62
63#[derive(Debug)]
64pub struct Procedure {
65    pub proc_type: ProcedureType,
66    pub identifier: String,
67    pub route: Vec<String>,
68}
69
70#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
71pub struct RunwayIdentifier {
72    number: u8,
73    modifier: RunwayModifier
74}
75impl FromStr for RunwayIdentifier {
76    type Err = Error;
77    fn from_str(s: &str) -> Result<Self, Self::Err> {
78        let (number, modifier) = euroscope::partial::parse_runway_identifier(s)?;
79        Ok(RunwayIdentifier {
80            number,
81            modifier
82        })
83    }
84}
85impl RunwayIdentifier {
86    pub fn number(&self) -> u8 {
87        self.number
88    }
89    pub fn modifier(&self) -> RunwayModifier {
90        self.modifier.clone()
91    }
92    pub fn number_and_modifier(&self) -> (u8, RunwayModifier) {
93        (self.number, self.modifier.clone())
94    }
95}
96impl Display for RunwayIdentifier {
97    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
98        write!(f, "{:02}{}", self.number, self.modifier)
99    }
100}
101
102#[derive(Debug)]
103pub struct AtcPosition {
104    pub name: String,
105    pub rt_callsign: String,
106    pub radio_freq: String,
107    pub short_identifier: String,
108    pub full_identifier: String,
109    pub start_squawk: Option<u16>,
110    pub end_squawk: Option<u16>,
111    pub vis_centres: [Option<Position<Valid>>; 4]
112}
113
114