Skip to main content

reda_gds/models/
structure.rs

1use crate::{GdsDateTime, GdsBoundary, GdsPath, GdsSref, GdsAref, GdsText};
2use super::{GdsBox, GdsCoord, GdsNode, GdsTransform};
3
4#[derive(Debug, Default, Clone)]
5pub struct GdsStructure {
6    pub name: String,
7    pub create_date: GdsDateTime,
8    pub modify_date: GdsDateTime,
9    pub boundarys: Vec<GdsBoundary>,
10    pub paths: Vec<GdsPath>,
11    pub srefs: Vec<GdsSref>,
12    pub arefs: Vec<GdsAref>,
13    pub texts: Vec<GdsText>,
14    pub nodes: Vec<GdsNode>,
15    pub boxes: Vec<GdsBox>,
16}
17
18impl GdsStructure {
19    pub fn new<S: Into<String>>(name: S) -> Self {
20        Self {
21            name: name.into(),
22            ..Default::default()
23        }
24    }
25
26    pub fn add_rectangle(&mut self, layer: i16, leftdown: impl Into<GdsCoord>, rightup: impl Into<GdsCoord>) {
27        self.boundarys.push(GdsBoundary::rect(layer, leftdown, rightup));
28    }
29
30    pub fn add_text(&mut self, layer: i16, offset: impl Into<GdsCoord>, text: impl Into<String>) {
31        self.texts.push(GdsText::new(layer, offset, text));
32    }
33
34    pub fn add_path(&mut self, layer: i16, coords: impl Into<Vec<GdsCoord>>, width: i32) {
35        self.paths.push(GdsPath::new(layer, coords, width));
36    }
37
38    pub fn add_sref(&mut self, ref_name: impl Into<String>, coord: impl Into<GdsCoord>, transform: Option<GdsTransform>) {
39        self.srefs.push(GdsSref::new(ref_name, coord, transform));
40    }
41
42    pub fn add_aref(&mut self, ref_name: impl Into<String>, row: i16, col: i16, coord: impl Into<GdsCoord>, transform: Option<GdsTransform>) {
43        self.arefs.push(GdsAref::new(ref_name, row, col, coord, transform));
44    }
45}