#![allow(unused)]
use chrono::{DateTime, Datelike, Timelike, Utc};
use std::{error::Error, time::SystemTime};
use super::gds_error::gds_err;
pub const HEADER: &[u8] = &[0x00, 0x02];
pub const BGNLIB: &[u8] = &[0x01, 0x02];
pub const LIBNAME: &[u8] = &[0x02, 0x06];
pub const UNITS: &[u8] = &[0x03, 0x05];
pub const ENDLIB: &[u8] = &[0x04, 0x00];
pub const BGNSTR: &[u8] = &[0x05, 0x02];
pub const STRNAME: &[u8] = &[0x06, 0x06];
pub const ENDSTR: &[u8] = &[0x07, 0x00];
pub const BOUNDARY: &[u8] = &[0x08, 0x00];
pub const PATH: &[u8] = &[0x09, 0x00];
pub const SREF: &[u8] = &[0x0a, 0x00];
pub const AREF: &[u8] = &[0x0b, 0x00];
pub const TEXT: &[u8] = &[0x0c, 0x00];
pub const LAYER: &[u8] = &[0x0d, 0x02];
pub const DATATYPE: &[u8] = &[0x0e, 0x02];
pub const WIDTH: &[u8] = &[0x0f, 0x03];
pub const XY: &[u8] = &[0x10, 0x03];
pub const ENDEL: &[u8] = &[0x11, 0x00];
pub const SNAME: &[u8] = &[0x12, 0x06];
pub const COLROW: &[u8] = &[0x13, 0x02];
pub const TEXTNODE: &[u8] = &[0x14, 0x00]; pub const NODE: &[u8] = &[0x15, 0x00]; pub const TEXTTYPE: &[u8] = &[0x16, 0x02];
pub const PRESENTATION: &[u8] = &[0x17, 0x01];
pub const SPACING: Option<&[u8]> = None; pub const STRING: &[u8] = &[0x19, 0x06];
pub const STRANS: &[u8] = &[0x1a, 0x01];
pub const MAG: &[u8] = &[0x1b, 0x05];
pub const ANGLE: &[u8] = &[0x1c, 0x05];
pub const UINTEGER: Option<&[u8]> = None; pub const USTRING: Option<&[u8]> = None; pub const REFLIBS: &[u8] = &[0x1f, 0x06];
pub const FONTS: &[u8] = &[0x20, 0x06];
pub const PATHTYPE: &[u8] = &[0x21, 0x02];
pub const GENERATIONS: &[u8] = &[0x22, 0x02];
pub const ATTRTABLE: &[u8] = &[0x23, 0x06];
pub const STYPTABLE: &[u8] = &[0x24, 0x06]; pub const STRTYPE: &[u8] = &[0x25, 0x02]; pub const ELFLAGS: &[u8] = &[0x26, 0x01];
pub const ELKEY: &[u8] = &[0x27, 0x03]; pub const LINKTYPE: &[u8] = &[0x28]; pub const LINKKEYS: &[u8] = &[0x29]; pub const NODETYPE: &[u8] = &[0x2a, 0x02];
pub const PROPATTR: &[u8] = &[0x2b, 0x02];
pub const PROPVALUE: &[u8] = &[0x2c, 0x06];
pub const BOX: &[u8] = &[0x2d, 0x00];
pub const BOXTYPE: &[u8] = &[0x2e, 0x02];
pub const PLEX: &[u8] = &[0x2f, 0x03];
pub const BGNEXTN: &[u8] = &[0x30, 0x03]; pub const ENDEXTN: &[u8] = &[0x31, 0x03]; pub const TAPENUM: &[u8] = &[0x32, 0x03];
pub const TAPECODE: &[u8] = &[0x33, 0x02];
pub const STRCLASS: &[u8] = &[0x34, 0x01];
pub const RESERVED: &[u8] = &[0x35, 0x03]; pub const FORMAT: &[u8] = &[0x36, 0x02];
pub const MASK: &[u8] = &[0x37, 0x06];
pub const ENDMASKS: &[u8] = &[0x38, 0x00];
pub const LIBDIRSIZE: &[u8] = &[0x39, 0x02];
pub const SRFNAME: &[u8] = &[0x3a, 0x06];
pub const LIBSECUR: &[u8] = &[0x3b, 0x02];
pub const BORDER: &[u8] = &[0x3c, 0x00];
pub const SOFTFENCE: &[u8] = &[0x3d, 0x00];
pub const HARDFENCE: &[u8] = &[0x3e, 0x00];
pub const SOFTWIRE: &[u8] = &[0x3f, 0x00];
pub const HARDWIRE: &[u8] = &[0x40, 0x00];
pub const PATHPORT: &[u8] = &[0x41, 0x00];
pub const NODEPORT: &[u8] = &[0x42, 0x00];
pub const USERCONSTRAINT: &[u8] = &[0x43, 0x00];
pub const SPACERERROR: &[u8] = &[0x44, 0x00];
pub const CONTACT: &[u8] = &[0x45, 0x00];
#[derive(Debug)]
pub enum PresentationFont {
Fonts0,
Fonts1,
Fonts2,
Fonts3,
}
#[derive(Debug)]
pub enum PresentationVerticalPos {
Top,
Middle,
Bottom,
}
#[derive(Debug)]
pub enum PresentationHorizontalPos {
Left,
Center,
Right,
}
#[derive(Debug, Default, Clone)]
pub struct Date {
pub mod_year: i16,
pub mod_month: i16,
pub mod_day: i16,
pub mod_hour: i16,
pub mod_minute: i16,
pub mod_second: i16,
pub acc_year: i16,
pub acc_month: i16,
pub acc_day: i16,
pub acc_hour: i16,
pub acc_minute: i16,
pub acc_second: i16,
}
impl Date {
pub fn new() -> Self {
Date {
mod_year: i16::default(),
mod_month: i16::default(),
mod_day: i16::default(),
mod_hour: i16::default(),
mod_minute: i16::default(),
mod_second: i16::default(),
acc_year: i16::default(),
acc_month: i16::default(),
acc_day: i16::default(),
acc_hour: i16::default(),
acc_minute: i16::default(),
acc_second: i16::default(),
}
}
pub fn now() -> Self {
let now = SystemTime::now();
let utc: DateTime<Utc> = now.into();
let year = utc.year() as i16;
let month = utc.month() as i16;
let day = utc.day() as i16;
let hour = utc.hour() as i16;
let minute = utc.minute() as i16;
let second = utc.second() as i16;
Date {
mod_year: year,
mod_month: month,
mod_day: day,
mod_hour: hour,
mod_minute: minute,
mod_second: second,
acc_year: year,
acc_month: month,
acc_day: day,
acc_hour: hour,
acc_minute: minute,
acc_second: second,
}
}
pub fn from_i16_array(date: &[i16]) -> Result<Date, Box<dyn Error>> {
if date.len() < 12 {
return Err(Box::new(gds_err(
"Can't create gds Date for data length less than 12",
)));
}
let mut it = date.iter();
Ok(Date {
mod_year: *it.next().unwrap(),
mod_month: *it.next().unwrap(),
mod_day: *it.next().unwrap(),
mod_hour: *it.next().unwrap(),
mod_minute: *it.next().unwrap(),
mod_second: *it.next().unwrap(),
acc_year: *it.next().unwrap(),
acc_month: *it.next().unwrap(),
acc_day: *it.next().unwrap(),
acc_hour: *it.next().unwrap(),
acc_minute: *it.next().unwrap(),
acc_second: *it.next().unwrap(),
})
}
}
#[derive(Debug)]
pub enum Record {
Header {
version: i16,
},
BgnLib(Date),
LibName(String),
Units {
unit_in_meter: f64,
precision: f64,
},
EndLib,
BgnStr(Date),
StrName(String),
EndStr,
Boundary,
Path,
StrRef,
AryRef,
Text,
Layer(i16),
DataType(i16),
Width(i32),
Points(Vec<(i32, i32)>),
EndElem,
StrRefName(String),
ColRow {
column: i16,
row: i16,
},
TextType(i16),
Presentation {
font_num: PresentationFont,
vertival_justfication: PresentationVerticalPos,
horizontal_justfication: PresentationHorizontalPos,
},
String(String),
RefTrans {
reflection_x: bool,
absolute_magnification: bool,
absolute_angle: bool,
},
Mag(f64),
Angle(f64),
PathType(i16),
PropAttr(i16),
PropValue(String),
Box,
BoxType(i16),
}