use super::{Entity, EntityCommon};
use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transform, Transparency, Vector3};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(i16)]
pub enum OleObjectType {
Link = 1,
Embedded = 2,
Static = 3,
}
impl OleObjectType {
pub fn from_i16(v: i16) -> Self {
match v {
1 => OleObjectType::Link,
3 => OleObjectType::Static,
_ => OleObjectType::Embedded,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ole2Frame {
pub common: EntityCommon,
pub version: i16,
pub source_application: String,
pub upper_left_corner: Vector3,
pub lower_right_corner: Vector3,
pub ole_object_type: OleObjectType,
pub is_paper_space: bool,
pub binary_data: Vec<u8>,
pub dwg_mode: i16,
pub dwg_trailing_byte: u8,
}
impl Ole2Frame {
pub fn new() -> Self {
Ole2Frame {
common: EntityCommon::new(),
version: 2,
source_application: String::new(),
upper_left_corner: Vector3::new(1.0, 1.0, 0.0),
lower_right_corner: Vector3::ZERO,
ole_object_type: OleObjectType::Embedded,
is_paper_space: false,
binary_data: Vec::new(),
dwg_mode: 0,
dwg_trailing_byte: 3,
}
}
}
impl Default for Ole2Frame {
fn default() -> Self {
Self::new()
}
}
impl Entity for Ole2Frame {
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 {
BoundingBox3D::from_points(&[self.upper_left_corner, self.lower_right_corner])
.unwrap_or_else(|| BoundingBox3D::from_point(self.upper_left_corner))
}
fn translate(&mut self, offset: Vector3) {
super::translate::translate_ole2frame(self, offset);
}
fn entity_type(&self) -> &'static str { "OLE2FRAME" }
fn apply_transform(&mut self, transform: &Transform) {
super::transform::transform_ole2frame(self, transform);
}
}