Skip to main content

acadrust/entities/
ole2frame.rs

1//! OLE2FRAME entity — embedded OLE object in a drawing
2
3use super::{Entity, EntityCommon};
4use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transform, Transparency, Vector3};
5
6/// OLE object type
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[repr(i16)]
10pub enum OleObjectType {
11    /// Linked OLE object
12    Link = 1,
13    /// Embedded OLE object
14    Embedded = 2,
15    /// Static OLE object
16    Static = 3,
17}
18
19impl OleObjectType {
20    /// Create from DXF code value
21    pub fn from_i16(v: i16) -> Self {
22        match v {
23            1 => OleObjectType::Link,
24            3 => OleObjectType::Static,
25            _ => OleObjectType::Embedded,
26        }
27    }
28}
29
30/// An embedded OLE2 object entity.
31///
32/// Stores the binary OLE data and bounding rectangle.
33#[derive(Debug, Clone, PartialEq)]
34#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35pub struct Ole2Frame {
36    /// Common entity data
37    pub common: EntityCommon,
38    /// OLE version (typically 2)
39    pub version: i16,
40    /// Name of the source application (e.g. "Excel.Sheet.12")
41    pub source_application: String,
42    /// Upper-left corner of the OLE frame
43    pub upper_left_corner: Vector3,
44    /// Lower-right corner of the OLE frame
45    pub lower_right_corner: Vector3,
46    /// Object type (link, embedded, static)
47    pub ole_object_type: OleObjectType,
48    /// Whether the object is in paper space
49    pub is_paper_space: bool,
50    /// Raw OLE binary data (code 310 chunks concatenated)
51    pub binary_data: Vec<u8>,
52    /// DWG tile mode descriptor (0=model, 1=paper, 2=model in layout)
53    pub dwg_mode: i16,
54    /// DWG trailing byte (OLE type indicator)
55    pub dwg_trailing_byte: u8,
56}
57
58impl Ole2Frame {
59    /// Create a new OLE2FRAME with defaults
60    pub fn new() -> Self {
61        Ole2Frame {
62            common: EntityCommon::new(),
63            version: 2,
64            source_application: String::new(),
65            upper_left_corner: Vector3::new(1.0, 1.0, 0.0),
66            lower_right_corner: Vector3::ZERO,
67            ole_object_type: OleObjectType::Embedded,
68            is_paper_space: false,
69            binary_data: Vec::new(),
70            dwg_mode: 0,
71            dwg_trailing_byte: 3,
72        }
73    }
74}
75
76impl Default for Ole2Frame {
77    fn default() -> Self {
78        Self::new()
79    }
80}
81
82impl Entity for Ole2Frame {
83    fn handle(&self) -> Handle { self.common.handle }
84    fn set_handle(&mut self, handle: Handle) { self.common.handle = handle; }
85    fn layer(&self) -> &str { &self.common.layer }
86    fn set_layer(&mut self, layer: String) { self.common.layer = layer; }
87    fn color(&self) -> Color { self.common.color }
88    fn set_color(&mut self, color: Color) { self.common.color = color; }
89    fn line_weight(&self) -> LineWeight { self.common.line_weight }
90    fn set_line_weight(&mut self, weight: LineWeight) { self.common.line_weight = weight; }
91    fn transparency(&self) -> Transparency { self.common.transparency }
92    fn set_transparency(&mut self, transparency: Transparency) { self.common.transparency = transparency; }
93    fn is_invisible(&self) -> bool { self.common.invisible }
94    fn set_invisible(&mut self, invisible: bool) { self.common.invisible = invisible; }
95    fn bounding_box(&self) -> BoundingBox3D {
96        BoundingBox3D::from_points(&[self.upper_left_corner, self.lower_right_corner])
97            .unwrap_or_else(|| BoundingBox3D::from_point(self.upper_left_corner))
98    }
99    fn translate(&mut self, offset: Vector3) {
100        super::translate::translate_ole2frame(self, offset);
101    }
102    fn entity_type(&self) -> &'static str { "OLE2FRAME" }
103    fn apply_transform(&mut self, transform: &Transform) {
104        super::transform::transform_ole2frame(self, transform);
105    }
106}