altium_format/records/sch/
power.rs1use crate::error::Result;
4use crate::traits::{FromParams, ToParams};
5use crate::types::{Coord, CoordRect, ParameterCollection, UnknownFields};
6use altium_format_derive::AltiumRecord;
7
8use super::{PowerObjectStyle, SchGraphicalBase, SchPrimitive, TextOrientations};
9
10#[derive(Debug, Clone, Default, AltiumRecord)]
12#[altium(record_id = 17, format = "params")]
13pub struct SchPowerObject {
14 #[altium(flatten)]
16 pub graphical: SchGraphicalBase,
17
18 #[altium(param = "STYLE", default)]
20 pub style: PowerObjectStyle,
21
22 #[altium(param = "ORIENTATION", default)]
24 pub orientation: TextOrientations,
25
26 #[altium(param = "TEXT", default)]
28 pub text: String,
29
30 #[altium(param = "SHOWNETNAME", default)]
32 pub show_net_name: bool,
33
34 #[altium(param = "FONTID", default)]
36 pub font_id: i32,
37
38 #[altium(unknown)]
40 pub unknown_params: UnknownFields,
41}
42
43impl SchPrimitive for SchPowerObject {
44 const RECORD_ID: i32 = 17;
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 "PowerObject"
55 }
56
57 fn get_property(&self, name: &str) -> Option<String> {
58 match name {
59 "TEXT" => Some(self.text.clone()),
60 _ => None,
61 }
62 }
63
64 fn import_from_params(params: &ParameterCollection) -> Result<Self> {
65 Self::from_params(params)
66 }
67
68 fn export_to_params(&self) -> ParameterCollection {
69 self.to_params()
70 }
71
72 fn owner_index(&self) -> i32 {
73 self.graphical.base.owner_index
74 }
75
76 fn calculate_bounds(&self) -> CoordRect {
77 let size = 50000; CoordRect::from_points(
80 Coord::from_raw(self.graphical.location_x - size),
81 Coord::from_raw(self.graphical.location_y - size),
82 Coord::from_raw(self.graphical.location_x + size),
83 Coord::from_raw(self.graphical.location_y + size),
84 )
85 }
86}