acadrust/entities/
ole2frame.rs1use super::{Entity, EntityCommon};
4use crate::types::{BoundingBox3D, Color, Handle, LineWeight, Transform, Transparency, Vector3};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[repr(i16)]
10pub enum OleObjectType {
11 Link = 1,
13 Embedded = 2,
15 Static = 3,
17}
18
19impl OleObjectType {
20 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#[derive(Debug, Clone, PartialEq)]
34#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35pub struct Ole2Frame {
36 pub common: EntityCommon,
38 pub version: i16,
40 pub source_application: String,
42 pub upper_left_corner: Vector3,
44 pub lower_right_corner: Vector3,
46 pub ole_object_type: OleObjectType,
48 pub is_paper_space: bool,
50 pub binary_data: Vec<u8>,
52 pub dwg_mode: i16,
54 pub dwg_trailing_byte: u8,
56}
57
58impl Ole2Frame {
59 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}