use super::{Entity, EntityCommon};
use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transparency, Vector3};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AttachmentPoint {
TopLeft = 1,
TopCenter = 2,
TopRight = 3,
MiddleLeft = 4,
MiddleCenter = 5,
MiddleRight = 6,
BottomLeft = 7,
BottomCenter = 8,
BottomRight = 9,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DrawingDirection {
LeftToRight = 1,
TopToBottom = 2,
ByStyle = 3,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MText {
pub common: EntityCommon,
pub value: String,
pub insertion_point: Vector3,
pub height: f64,
pub rectangle_width: f64,
pub rectangle_height: Option<f64>,
pub rotation: f64,
pub style: String,
pub attachment_point: AttachmentPoint,
pub drawing_direction: DrawingDirection,
pub line_spacing_factor: f64,
pub normal: Vector3,
}
impl MText {
pub fn new() -> Self {
MText {
common: EntityCommon::new(),
value: String::new(),
insertion_point: Vector3::ZERO,
height: 1.0,
rectangle_width: 10.0,
rectangle_height: None,
rotation: 0.0,
style: "STANDARD".to_string(),
attachment_point: AttachmentPoint::TopLeft,
drawing_direction: DrawingDirection::LeftToRight,
line_spacing_factor: 1.0,
normal: Vector3::UNIT_Z,
}
}
pub fn with_value(value: impl Into<String>, position: Vector3) -> Self {
MText {
value: value.into(),
insertion_point: position,
..Self::new()
}
}
pub fn with_height(mut self, height: f64) -> Self {
self.height = height;
self
}
pub fn with_width(mut self, width: f64) -> Self {
self.rectangle_width = width;
self
}
}
impl Default for MText {
fn default() -> Self {
Self::new()
}
}
impl Entity for MText {
fn handle(&self) -> Handle {
self.common.handle
}
fn set_handle(&mut self, handle: Handle) {
self.common.handle = handle;
}
fn layer(&self) -> &str {
&self.common.layer
}
fn set_layer(&mut self, layer: String) {
self.common.layer = layer;
}
fn color(&self) -> Color {
self.common.color
}
fn set_color(&mut self, color: Color) {
self.common.color = color;
}
fn line_weight(&self) -> LineWeight {
self.common.line_weight
}
fn set_line_weight(&mut self, weight: LineWeight) {
self.common.line_weight = weight;
}
fn transparency(&self) -> Transparency {
self.common.transparency
}
fn set_transparency(&mut self, transparency: Transparency) {
self.common.transparency = transparency;
}
fn is_invisible(&self) -> bool {
self.common.invisible
}
fn set_invisible(&mut self, invisible: bool) {
self.common.invisible = invisible;
}
fn bounding_box(&self) -> BoundingBox3D {
let height = self.rectangle_height.unwrap_or(self.height * 2.0);
BoundingBox3D::new(
self.insertion_point,
Vector3::new(
self.insertion_point.x + self.rectangle_width,
self.insertion_point.y + height,
self.insertion_point.z,
),
)
}
fn translate(&mut self, offset: Vector3) {
super::translate::translate_mtext(self, offset);
}
fn entity_type(&self) -> &'static str {
"MTEXT"
}
fn apply_transform(&mut self, transform: &crate::types::Transform) {
super::transform::transform_mtext(self, transform);
}
fn apply_mirror(&mut self, transform: &crate::types::Transform) {
super::mirror::mirror_mtext(self, transform);
}
}