use crate::model::chart::Anchor;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Shape {
pub name: String,
pub description: String,
pub anchor: Anchor,
pub geometry: Option<String>,
pub text: String,
pub origin: Option<ShapeOrigin>,
}
impl Shape {
#[must_use]
pub fn new(geometry: impl Into<String>, anchor: Anchor) -> Self {
Self {
name: String::new(),
description: String::new(),
anchor,
geometry: Some(geometry.into()),
text: String::new(),
origin: None,
}
}
#[must_use]
pub fn is_unchanged(&self) -> bool {
self.origin.as_ref().is_some_and(|o| {
o.name == self.name
&& o.description == self.description
&& o.anchor == self.anchor
&& o.geometry == self.geometry
&& o.text == self.text
})
}
pub(crate) fn settle(&mut self) {
if let Some(origin) = &mut self.origin {
origin.anchor = self.anchor;
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShapeOrigin {
pub(crate) drawing: String,
pub(crate) id: u32,
pub(crate) grouped: bool,
pub(crate) name: String,
pub(crate) description: String,
pub(crate) anchor: Anchor,
pub(crate) geometry: Option<String>,
pub(crate) text: String,
pub(crate) read_from_drawing: usize,
}
impl ShapeOrigin {
#[must_use]
pub fn drawing(&self) -> &str {
&self.drawing
}
#[must_use]
pub const fn grouped(&self) -> bool {
self.grouped
}
}