altium_format/records/sch/
rectangle.rs1use crate::error::Result;
4use crate::traits::{FromParams, ToParams};
5use crate::types::{Coord, CoordRect, ParameterCollection, UnknownFields};
6use altium_format_derive::AltiumRecord;
7
8use super::{LineWidth, SchGraphicalBase, SchPrimitive};
9
10#[derive(Debug, Clone, Default, AltiumRecord)]
12#[altium(record_id = 14, format = "params")]
13pub struct SchRectangle {
14 #[altium(flatten)]
16 pub graphical: SchGraphicalBase,
17
18 #[altium(param = "CORNER.X", frac = "CORNER.X_FRAC")]
20 pub corner_x: i32,
21
22 #[altium(param = "CORNER.Y", frac = "CORNER.Y_FRAC")]
24 pub corner_y: i32,
25
26 #[altium(param = "LINEWIDTH", default)]
28 pub line_width: LineWidth,
29
30 #[altium(param = "ISSOLID", default)]
32 pub is_solid: bool,
33
34 #[altium(param = "TRANSPARENT", default)]
36 pub transparent: bool,
37
38 #[altium(unknown)]
40 pub unknown_params: UnknownFields,
41}
42
43impl SchPrimitive for SchRectangle {
44 const RECORD_ID: i32 = 14;
45
46 fn location(&self) -> Option<crate::types::CoordPoint> {
47 Some(crate::types::CoordPoint::from_raw(
48 self.graphical.location_x,
49 self.graphical.location_y,
50 ))
51 }
52
53 fn record_type_name(&self) -> &'static str {
54 "Rectangle"
55 }
56
57 fn import_from_params(params: &ParameterCollection) -> Result<Self> {
58 Self::from_params(params)
59 }
60
61 fn export_to_params(&self) -> ParameterCollection {
62 self.to_params()
63 }
64
65 fn owner_index(&self) -> i32 {
66 self.graphical.base.owner_index
67 }
68
69 fn calculate_bounds(&self) -> CoordRect {
70 CoordRect::from_points(
71 Coord::from_raw(self.graphical.location_x),
72 Coord::from_raw(self.graphical.location_y),
73 Coord::from_raw(self.corner_x),
74 Coord::from_raw(self.corner_y),
75 )
76 }
77}