use crate::error::Result;
use crate::traits::{FromParams, ToParams};
use crate::types::{Coord, CoordRect, ParameterCollection, UnknownFields};
use altium_format_derive::AltiumRecord;
use super::{LineWidth, SchGraphicalBase, SchPrimitive, TextOrientations};
fn text_frame_bounds(location_x: i32, location_y: i32, corner_x: i32, corner_y: i32) -> CoordRect {
CoordRect::from_points(
Coord::from_raw(location_x),
Coord::from_raw(location_y),
Coord::from_raw(corner_x),
Coord::from_raw(corner_y),
)
}
#[derive(Debug, Clone, Default, AltiumRecord)]
#[altium(record_id = 28, format = "params")]
pub struct SchTextFrame {
#[altium(flatten)]
pub graphical: SchGraphicalBase,
#[altium(param = "CORNER.X", frac = "CORNER.X_FRAC")]
pub corner_x: i32,
#[altium(param = "CORNER.Y", frac = "CORNER.Y_FRAC")]
pub corner_y: i32,
#[altium(param = "LINEWIDTH", default)]
pub line_width: LineWidth,
#[altium(param = "ISSOLID", default)]
pub is_solid: bool,
#[altium(param = "TRANSPARENT", default)]
pub transparent: bool,
#[altium(param = "FONTID", default)]
pub font_id: i32,
#[altium(param = "ALIGNMENT", default)]
pub alignment: i32,
#[altium(param = "WORDWRAP", default)]
pub word_wrap: bool,
#[altium(param = "CLIPTORECT", default)]
pub clip_to_rect: bool,
#[altium(param = "TEXTCOLOR", default)]
pub text_color: i32,
#[altium(param = "TEXT", default)]
pub text: String,
#[altium(param = "ORIENTATION", default)]
pub orientation: TextOrientations,
#[altium(param = "TEXTMARGIN", frac = "TEXTMARGIN_FRAC")]
pub text_margin: i32,
#[altium(param = "SHOWBORDER", default)]
pub show_border: bool,
#[altium(unknown)]
pub unknown_params: UnknownFields,
}
impl SchPrimitive for SchTextFrame {
const RECORD_ID: i32 = 28;
fn location(&self) -> Option<crate::types::CoordPoint> {
Some(crate::types::CoordPoint::from_raw(
self.graphical.location_x,
self.graphical.location_y,
))
}
fn record_type_name(&self) -> &'static str {
"TextFrame"
}
fn get_property(&self, name: &str) -> Option<String> {
match name {
"TEXT" => Some(self.text.clone()),
_ => None,
}
}
fn import_from_params(params: &ParameterCollection) -> Result<Self> {
Self::from_params(params)
}
fn export_to_params(&self) -> ParameterCollection {
self.to_params()
}
fn owner_index(&self) -> i32 {
self.graphical.base.owner_index
}
fn calculate_bounds(&self) -> CoordRect {
text_frame_bounds(
self.graphical.location_x,
self.graphical.location_y,
self.corner_x,
self.corner_y,
)
}
}
#[derive(Debug, Clone, Default, AltiumRecord)]
#[altium(record_id = 209, format = "params")]
pub struct SchTextFrameVariant {
#[altium(flatten)]
pub graphical: SchGraphicalBase,
#[altium(param = "CORNER.X", frac = "CORNER.X_FRAC")]
pub corner_x: i32,
#[altium(param = "CORNER.Y", frac = "CORNER.Y_FRAC")]
pub corner_y: i32,
#[altium(param = "LINEWIDTH", default)]
pub line_width: LineWidth,
#[altium(param = "ISSOLID", default)]
pub is_solid: bool,
#[altium(param = "TRANSPARENT", default)]
pub transparent: bool,
#[altium(param = "FONTID", default)]
pub font_id: i32,
#[altium(param = "ALIGNMENT", default)]
pub alignment: i32,
#[altium(param = "WORDWRAP", default)]
pub word_wrap: bool,
#[altium(param = "CLIPTORECT", default)]
pub clip_to_rect: bool,
#[altium(param = "TEXTCOLOR", default)]
pub text_color: i32,
#[altium(param = "TEXT", default)]
pub text: String,
#[altium(param = "ORIENTATION", default)]
pub orientation: TextOrientations,
#[altium(param = "TEXTMARGIN", frac = "TEXTMARGIN_FRAC")]
pub text_margin: i32,
#[altium(param = "SHOWBORDER", default)]
pub show_border: bool,
#[altium(unknown)]
pub unknown_params: UnknownFields,
}
impl SchPrimitive for SchTextFrameVariant {
const RECORD_ID: i32 = 209;
fn location(&self) -> Option<crate::types::CoordPoint> {
Some(crate::types::CoordPoint::from_raw(
self.graphical.location_x,
self.graphical.location_y,
))
}
fn record_type_name(&self) -> &'static str {
"TextFrameVariant"
}
fn get_property(&self, name: &str) -> Option<String> {
match name {
"TEXT" => Some(self.text.clone()),
_ => None,
}
}
fn import_from_params(params: &ParameterCollection) -> Result<Self> {
Self::from_params(params)
}
fn export_to_params(&self) -> ParameterCollection {
self.to_params()
}
fn owner_index(&self) -> i32 {
self.graphical.base.owner_index
}
fn calculate_bounds(&self) -> CoordRect {
text_frame_bounds(
self.graphical.location_x,
self.graphical.location_y,
self.corner_x,
self.corner_y,
)
}
}