1mod dictionary_variable;
7mod group;
8mod image_definition;
9mod mlinestyle;
10mod multileader_style;
11mod plot_settings;
12mod scale;
13mod sort_entities_table;
14mod table_style;
15mod xrecord;
16mod stub_objects;
17
18pub use dictionary_variable::DictionaryVariable;
19pub use group::Group;
20pub use image_definition::{ImageDefinition, ImageDefinitionReactor, ResolutionUnit};
21pub use mlinestyle::{MLineStyle, MLineStyleElement, MLineStyleFlags};
22pub use multileader_style::{
23 BlockContentConnectionType, LeaderContentType, LeaderDrawOrderType,
24 LeaderLinePropertyOverrideFlags, MultiLeaderDrawOrderType, MultiLeaderPathType,
25 MultiLeaderPropertyOverrideFlags, MultiLeaderStyle, TextAlignmentType, TextAngleType,
26 TextAttachmentDirectionType, TextAttachmentType,
27};
28pub use plot_settings::{
29 PaperMargin, PlotFlags, PlotPaperUnits, PlotRotation, PlotSettings, PlotType, PlotWindow,
30 ScaledType, ShadePlotMode, ShadePlotResolutionLevel,
31};
32pub use scale::Scale;
33pub use sort_entities_table::{SortEntsEntry, SortEntitiesTable};
34pub use table_style::{
35 CellAlignment, RowCellStyle, TableBorderPropertyFlags, TableBorderType, TableCellBorder,
36 TableCellStylePropertyFlags, TableFlowDirection, TableStyle, TableStyleFlags,
37};
38pub use xrecord::{DictionaryCloningFlags, XRecord, XRecordEntry, XRecordValue, XRecordValueType};
39pub use stub_objects::{
40 VisualStyle, Material, GeoData,
41 SpatialFilter, RasterVariables, BookColor, PlaceHolder,
42 DictionaryWithDefault, WipeoutVariables, StubObject,
43};
44
45use crate::types::Handle;
46
47#[derive(Debug, Clone, PartialEq)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50pub struct Dictionary {
51 pub handle: Handle,
53 pub owner: Handle,
55 pub entries: Vec<(String, Handle)>,
57 pub duplicate_cloning: i16,
59 pub hard_owner: bool,
61 pub reactors: Vec<Handle>,
63 pub xdictionary_handle: Option<Handle>,
65}
66
67impl Dictionary {
68 pub fn new() -> Self {
70 Self {
71 handle: Handle::NULL,
72 owner: Handle::NULL,
73 entries: Vec::new(),
74 duplicate_cloning: 1,
75 hard_owner: false,
76 reactors: Vec::new(),
77 xdictionary_handle: None,
78 }
79 }
80
81 pub fn add_entry(&mut self, key: impl Into<String>, handle: Handle) {
83 self.entries.push((key.into(), handle));
84 }
85
86 pub fn get(&self, key: &str) -> Option<Handle> {
88 self.entries
89 .iter()
90 .find(|(k, _)| k == key)
91 .map(|(_, h)| *h)
92 }
93
94 pub fn len(&self) -> usize {
96 self.entries.len()
97 }
98
99 pub fn is_empty(&self) -> bool {
101 self.entries.is_empty()
102 }
103}
104
105impl Default for Dictionary {
106 fn default() -> Self {
107 Self::new()
108 }
109}
110
111#[derive(Debug, Clone, PartialEq)]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114pub struct Layout {
115 pub handle: Handle,
117 pub owner: Handle,
119 pub name: String,
121 pub flags: i16,
123 pub tab_order: i16,
125 pub min_limits: (f64, f64),
127 pub max_limits: (f64, f64),
129 pub insertion_base: (f64, f64, f64),
131 pub min_extents: (f64, f64, f64),
133 pub max_extents: (f64, f64, f64),
135 pub elevation: f64,
137 pub ucs_origin: (f64, f64, f64),
139 pub ucs_x_axis: (f64, f64, f64),
141 pub ucs_y_axis: (f64, f64, f64),
143 pub ucs_ortho_type: i16,
145 pub block_record: Handle,
147 pub viewport: Handle,
149 pub reactors: Vec<Handle>,
151 pub xdictionary_handle: Option<Handle>,
153 #[cfg_attr(feature = "serde", serde(skip))]
158 pub raw_plot_settings_codes: Option<Vec<(i32, String)>>,
159}
160
161impl Layout {
162 pub fn new(name: impl Into<String>) -> Self {
164 Self {
165 handle: Handle::NULL,
166 owner: Handle::NULL,
167 name: name.into(),
168 flags: 0,
169 tab_order: 0,
170 min_limits: (0.0, 0.0),
171 max_limits: (12.0, 9.0),
172 insertion_base: (0.0, 0.0, 0.0),
173 min_extents: (0.0, 0.0, 0.0),
174 max_extents: (12.0, 9.0, 0.0),
175 elevation: 0.0,
176 ucs_origin: (0.0, 0.0, 0.0),
177 ucs_x_axis: (1.0, 0.0, 0.0),
178 ucs_y_axis: (0.0, 1.0, 0.0),
179 ucs_ortho_type: 0,
180 block_record: Handle::NULL,
181 viewport: Handle::NULL,
182 reactors: Vec::new(),
183 xdictionary_handle: None,
184 raw_plot_settings_codes: None,
185 }
186 }
187}
188
189#[derive(Debug, Clone, PartialEq)]
191#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
192pub enum ObjectType {
193 Dictionary(Dictionary),
195 Layout(Layout),
197 XRecord(XRecord),
199 Group(Group),
201 MLineStyle(MLineStyle),
203 ImageDefinition(ImageDefinition),
205 PlotSettings(PlotSettings),
207 MultiLeaderStyle(MultiLeaderStyle),
209 TableStyle(TableStyle),
211 Scale(Scale),
213 SortEntitiesTable(SortEntitiesTable),
215 DictionaryVariable(DictionaryVariable),
217 VisualStyle(VisualStyle),
219 Material(Material),
221 ImageDefinitionReactor(ImageDefinitionReactor),
223 GeoData(GeoData),
225 SpatialFilter(SpatialFilter),
227 RasterVariables(RasterVariables),
229 BookColor(BookColor),
231 PlaceHolder(PlaceHolder),
233 DictionaryWithDefault(DictionaryWithDefault),
235 WipeoutVariables(WipeoutVariables),
237 Unknown {
239 type_name: String,
241 handle: Handle,
243 owner: Handle,
245 #[cfg_attr(feature = "serde", serde(skip))]
251 raw_dxf_codes: Option<Vec<(i32, String)>>,
252 },
253}
254
255#[cfg(test)]
256mod tests {
257 use super::*;
258
259 #[test]
260 fn test_dictionary_creation() {
261 let mut dict = Dictionary::new();
262 assert!(dict.is_empty());
263
264 dict.add_entry("KEY1", Handle::new(100));
265 assert_eq!(dict.len(), 1);
266 assert_eq!(dict.get("KEY1"), Some(Handle::new(100)));
267 assert_eq!(dict.get("KEY2"), None);
268 }
269
270 #[test]
271 fn test_layout_creation() {
272 let layout = Layout::new("Layout1");
273 assert_eq!(layout.name, "Layout1");
274 assert_eq!(layout.tab_order, 0);
275 }
276}
277
278