Skip to main content

altium_format/records/sch/
netlabel.rs

1//! SchNetLabel - Schematic net label (Record 25).
2
3use crate::error::Result;
4use crate::traits::{FromParams, ToParams};
5use crate::types::{CoordRect, ParameterCollection, UnknownFields};
6use altium_format_derive::AltiumRecord;
7
8use super::{SchLabel, SchPrimitive};
9
10/// Schematic net label primitive - extends label for net naming.
11#[derive(Debug, Clone, Default, AltiumRecord)]
12#[altium(record_id = 25, format = "params")]
13pub struct SchNetLabel {
14    /// Base label data (includes graphical base, text, orientation, etc).
15    #[altium(flatten)]
16    pub label: SchLabel,
17
18    /// Unknown parameters (preserved for non-destructive editing).
19    #[altium(unknown)]
20    pub unknown_params: UnknownFields,
21}
22
23impl SchPrimitive for SchNetLabel {
24    const RECORD_ID: i32 = 25;
25
26    fn location(&self) -> Option<crate::types::CoordPoint> {
27        Some(crate::types::CoordPoint::from_raw(
28            self.label.graphical.location_x,
29            self.label.graphical.location_y,
30        ))
31    }
32
33    fn record_type_name(&self) -> &'static str {
34        "NetLabel"
35    }
36
37    fn get_property(&self, name: &str) -> Option<String> {
38        match name {
39            "TEXT" => Some(self.label.text.clone()),
40            _ => None,
41        }
42    }
43
44    fn import_from_params(params: &ParameterCollection) -> Result<Self> {
45        Self::from_params(params)
46    }
47
48    fn export_to_params(&self) -> ParameterCollection {
49        self.to_params()
50    }
51
52    fn owner_index(&self) -> i32 {
53        self.label.graphical.base.owner_index
54    }
55
56    fn calculate_bounds(&self) -> CoordRect {
57        self.label.calculate_bounds()
58    }
59}