mod presentation;
mod transform;
pub use presentation::*;
use reda_geometry::shape::Point;
pub use transform::*;
use std::fmt;
use chrono::{Datelike, Timelike, Local};
#[derive(Debug, Clone, Copy)]
pub enum GdsPathType {
SquareEnd = 0,
RoundEnd = 1,
SquareEndExtend = 2,
}
impl Default for GdsPathType {
fn default() -> Self {
Self::SquareEnd
}
}
impl GdsPathType {
pub fn from_u16(value: u16) -> Option<Self> {
match value {
0 => Some(Self::SquareEnd),
1 => Some(Self::RoundEnd),
2 => Some(Self::SquareEndExtend),
_ => None,
}
}
pub fn to_u16(&self) -> u16 {
match self {
Self::SquareEnd => 0,
Self::RoundEnd => 1,
Self::SquareEndExtend => 2,
}
}
}
impl std::fmt::Display for GdsPathType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let description = match self {
GdsPathType::SquareEnd => "SquareEnd (0)",
GdsPathType::RoundEnd => "RoundEnd (1)",
GdsPathType::SquareEndExtend => "SquareEndExtend (2)",
};
write!(f, "{}", description)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GdsFormat {
GdsiiArchive = 0,
GdsiiFiltered = 1,
EdsmArchive = 2,
EdshiFiltered = 3,
}
impl GdsFormat {
pub fn from_u16(value: u16) -> Option<Self> {
match value {
0 => Some(GdsFormat::GdsiiArchive),
1 => Some(GdsFormat::GdsiiFiltered),
2 => Some(GdsFormat::EdsmArchive),
3 => Some(GdsFormat::EdshiFiltered),
_ => None,
}
}
pub fn to_u16(self) -> u16 {
self as u16
}
}
#[derive(Debug, Clone)]
pub struct GdsDateTime {
pub year: i16,
pub month: i16,
pub day: i16,
pub hour: i16,
pub minute: i16,
pub second: i16,
}
impl Default for GdsDateTime {
fn default() -> Self {
Self::now()
}
}
impl GdsDateTime {
pub fn now() -> Self {
let now = Local::now();
GdsDateTime {
year: now.year() as i16,
month: now.month() as i16,
day: now.day() as i16,
hour: now.hour() as i16,
minute: now.minute() as i16,
second: now.second() as i16,
}
}
}
impl fmt::Display for GdsDateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
self.year, self.month, self.day, self.hour, self.minute, self.second)
}
}
pub type GdsCoord = Point<i32>;