mod dictionary_variable;
mod group;
mod image_definition;
mod mlinestyle;
mod multileader_style;
mod plot_settings;
mod scale;
mod sort_entities_table;
mod table_style;
mod xrecord;
mod stub_objects;
pub use dictionary_variable::DictionaryVariable;
pub use group::Group;
pub use image_definition::{ImageDefinition, ImageDefinitionReactor, ResolutionUnit};
pub use mlinestyle::{MLineStyle, MLineStyleElement, MLineStyleFlags};
pub use multileader_style::{
BlockContentConnectionType, LeaderContentType, LeaderDrawOrderType,
LeaderLinePropertyOverrideFlags, MultiLeaderDrawOrderType, MultiLeaderPathType,
MultiLeaderPropertyOverrideFlags, MultiLeaderStyle, TextAlignmentType, TextAngleType,
TextAttachmentDirectionType, TextAttachmentType,
};
pub use plot_settings::{
PaperMargin, PlotFlags, PlotPaperUnits, PlotRotation, PlotSettings, PlotType, PlotWindow,
ScaledType, ShadePlotMode, ShadePlotResolutionLevel,
};
pub use scale::Scale;
pub use sort_entities_table::{SortEntsEntry, SortEntitiesTable};
pub use table_style::{
CellAlignment, RowCellStyle, TableBorderPropertyFlags, TableBorderType, TableCellBorder,
TableCellStylePropertyFlags, TableFlowDirection, TableStyle, TableStyleFlags,
};
pub use xrecord::{DictionaryCloningFlags, XRecord, XRecordEntry, XRecordValue, XRecordValueType};
pub use stub_objects::{
VisualStyle, Material, GeoData,
SpatialFilter, RasterVariables, BookColor, PlaceHolder,
DictionaryWithDefault, WipeoutVariables, StubObject,
};
use crate::types::Handle;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Dictionary {
pub handle: Handle,
pub owner: Handle,
pub entries: Vec<(String, Handle)>,
pub duplicate_cloning: i16,
pub hard_owner: bool,
pub reactors: Vec<Handle>,
pub xdictionary_handle: Option<Handle>,
}
impl Dictionary {
pub fn new() -> Self {
Self {
handle: Handle::NULL,
owner: Handle::NULL,
entries: Vec::new(),
duplicate_cloning: 1,
hard_owner: false,
reactors: Vec::new(),
xdictionary_handle: None,
}
}
pub fn add_entry(&mut self, key: impl Into<String>, handle: Handle) {
self.entries.push((key.into(), handle));
}
pub fn get(&self, key: &str) -> Option<Handle> {
self.entries
.iter()
.find(|(k, _)| k == key)
.map(|(_, h)| *h)
}
pub fn len(&self) -> usize {
self.entries.len()
}
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}
impl Default for Dictionary {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Layout {
pub handle: Handle,
pub owner: Handle,
pub name: String,
pub flags: i16,
pub tab_order: i16,
pub min_limits: (f64, f64),
pub max_limits: (f64, f64),
pub insertion_base: (f64, f64, f64),
pub min_extents: (f64, f64, f64),
pub max_extents: (f64, f64, f64),
pub elevation: f64,
pub ucs_origin: (f64, f64, f64),
pub ucs_x_axis: (f64, f64, f64),
pub ucs_y_axis: (f64, f64, f64),
pub ucs_ortho_type: i16,
pub block_record: Handle,
pub viewport: Handle,
pub reactors: Vec<Handle>,
pub xdictionary_handle: Option<Handle>,
#[cfg_attr(feature = "serde", serde(skip))]
pub raw_plot_settings_codes: Option<Vec<(i32, String)>>,
}
impl Layout {
pub fn new(name: impl Into<String>) -> Self {
Self {
handle: Handle::NULL,
owner: Handle::NULL,
name: name.into(),
flags: 0,
tab_order: 0,
min_limits: (0.0, 0.0),
max_limits: (12.0, 9.0),
insertion_base: (0.0, 0.0, 0.0),
min_extents: (0.0, 0.0, 0.0),
max_extents: (12.0, 9.0, 0.0),
elevation: 0.0,
ucs_origin: (0.0, 0.0, 0.0),
ucs_x_axis: (1.0, 0.0, 0.0),
ucs_y_axis: (0.0, 1.0, 0.0),
ucs_ortho_type: 0,
block_record: Handle::NULL,
viewport: Handle::NULL,
reactors: Vec::new(),
xdictionary_handle: None,
raw_plot_settings_codes: None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ObjectType {
Dictionary(Dictionary),
Layout(Layout),
XRecord(XRecord),
Group(Group),
MLineStyle(MLineStyle),
ImageDefinition(ImageDefinition),
PlotSettings(PlotSettings),
MultiLeaderStyle(MultiLeaderStyle),
TableStyle(TableStyle),
Scale(Scale),
SortEntitiesTable(SortEntitiesTable),
DictionaryVariable(DictionaryVariable),
VisualStyle(VisualStyle),
Material(Material),
ImageDefinitionReactor(ImageDefinitionReactor),
GeoData(GeoData),
SpatialFilter(SpatialFilter),
RasterVariables(RasterVariables),
BookColor(BookColor),
PlaceHolder(PlaceHolder),
DictionaryWithDefault(DictionaryWithDefault),
WipeoutVariables(WipeoutVariables),
Unknown {
type_name: String,
handle: Handle,
owner: Handle,
#[cfg_attr(feature = "serde", serde(skip))]
raw_dxf_codes: Option<Vec<(i32, String)>>,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_dictionary_creation() {
let mut dict = Dictionary::new();
assert!(dict.is_empty());
dict.add_entry("KEY1", Handle::new(100));
assert_eq!(dict.len(), 1);
assert_eq!(dict.get("KEY1"), Some(Handle::new(100)));
assert_eq!(dict.get("KEY2"), None);
}
#[test]
fn test_layout_creation() {
let layout = Layout::new("Layout1");
assert_eq!(layout.name, "Layout1");
assert_eq!(layout.tab_order, 0);
}
}