sct_reader/loaders/euroscope/
asr.rs1use std::{fs::File, io::{BufRead, BufReader}, path::Path};
2
3use aviation_calc_util::{geo::GeoPoint, units::Angle};
4
5use super::symbology::SymbologyItemType;
6
7
8#[derive(Debug, Clone, Default)]
9pub struct EsAsr {
10 pub name: String,
11 pub file_name: String,
12 pub display_type_name: String,
13 pub display_type_need_radar_content: bool,
14 pub display_type_geo_reference: bool,
15 pub sector_file_id: Option<String>,
16 pub sector_title: String,
17 pub display_items: Vec<DisplayItem>,
18 pub show_c: bool,
19 pub shows_b: bool,
20 pub below: i32,
21 pub above: i32,
22 pub leader: i32,
23 pub show_leader: bool,
24 pub turn_leader: bool,
25 pub history_dots: u32,
26 pub simulation_mode: u32,
27 pub disable_panning: bool,
28 pub disable_zooming: bool,
29 pub display_rotation: Angle,
30 pub window_area: (GeoPoint, GeoPoint)
31}
32
33impl EsAsr {
34 pub fn try_from_asr_file(asr_file: impl AsRef<Path>) -> anyhow::Result<(Self, String)> {
35 let file_reader = BufReader::new(File::open(&asr_file)?);
36 let mut ret_val = Self::default();
37 let mut sector_file = "".to_string();
38 ret_val.file_name = asr_file.as_ref().to_str().unwrap().to_string();
39
40 for line in file_reader.lines() {
41 if let Ok(line_str) = line {
42 let items = line_str.split(":").collect::<Vec<&str>>();
43
44 if items.len() > 0 {
45 match items[0].to_lowercase().as_str() {
46 "displaytypename" => ret_val.display_type_name = items[1].to_string(),
47 "displaytypeneedradarcontent" => ret_val.display_type_need_radar_content = items[1].parse::<u8>()? != 0,
48 "displaytypegeoreferenced" => ret_val.display_type_geo_reference = items[1].parse::<u8>()? != 0,
49 "sectorfile" => sector_file = items[1].to_string(),
50 "sectortitle" => ret_val.sector_title = items[1].to_string(),
51 "showc" => ret_val.show_c = items[1].parse::<u8>()? != 0,
52 "showsb" => ret_val.shows_b = items[1].parse::<u8>()? != 0,
53 "below" => ret_val.below = items[1].parse()?,
54 "above" => ret_val.above = items[1].parse()?,
55 "leader" => ret_val.leader = items[1].parse()?,
56 "showleader" => ret_val.show_leader = items[1].parse::<u8>()? != 0,
57 "turnleader" => ret_val.turn_leader = items[1].parse::<u8>()? != 0,
58 "history_dots" => ret_val.history_dots = items[1].parse()?,
59 "simulation_mode" => ret_val.simulation_mode = items[1].parse()?,
60 "disablepanning" => ret_val.disable_panning = items[1].parse::<u8>()? != 0,
61 "disablezooming" => ret_val.disable_zooming = items[1].parse::<u8>()? != 0,
62 "displayrotation" => ret_val.display_rotation = Angle::from_degrees(items[1].parse()?),
63 "windowarea" => ret_val.window_area = (GeoPoint::from_degs_and_ft(items[1].parse()?, items[2].parse()?, 0_f64), GeoPoint::from_degs_and_ft(items[3].parse()?, items[4].parse()?, 0_f64)),
64 &_ => {
65 if let Ok(symbol_type) = items[0].try_into() {
66 ret_val.display_items.push(DisplayItem {
67 item_type: symbol_type,
68 name: items[1].to_string(),
69 attribute: items[2].to_string()
70 });
71 }
72 }
73 }
74 }
75 }
76 }
77
78 Ok((ret_val, sector_file.to_string()))
79 }
80}
81
82
83#[derive(Debug, Clone, Default)]
84pub struct DisplayItem {
85 pub item_type: SymbologyItemType,
86 pub name: String,
87 pub attribute: String
88}