use crate::error::Result;
use crate::traits::{FromParams, ToParams};
use crate::types::{CoordRect, ParameterCollection, UnknownFields};
use altium_format_derive::AltiumRecord;
use super::{SchParameter, SchPrimitive};
#[derive(Debug, Clone, Default, AltiumRecord)]
#[altium(record_id = 34, format = "params")]
pub struct SchDesignator {
#[altium(flatten)]
pub param: SchParameter,
#[altium(unknown)]
pub unknown_params: UnknownFields,
}
impl SchDesignator {
pub fn text(&self) -> &str {
self.param.value()
}
}
impl SchPrimitive for SchDesignator {
const RECORD_ID: i32 = 34;
fn location(&self) -> Option<crate::types::CoordPoint> {
Some(crate::types::CoordPoint::from_raw(
self.param.label.graphical.location_x,
self.param.label.graphical.location_y,
))
}
fn record_type_name(&self) -> &'static str {
"Designator"
}
fn get_property(&self, name: &str) -> Option<String> {
match name {
"NAME" => Some(self.param.name.clone()),
"TEXT" => Some(self.param.label.text.clone()),
_ => None,
}
}
fn import_from_params(params: &ParameterCollection) -> Result<Self> {
let mut result = Self::from_params(params)?;
if result.param.read_only_state == 0 {
result.param.read_only_state = 1;
}
Ok(result)
}
fn export_to_params(&self) -> ParameterCollection {
self.to_params()
}
fn owner_index(&self) -> i32 {
self.param.owner_index()
}
fn calculate_bounds(&self) -> CoordRect {
self.param.calculate_bounds()
}
}