diff --git a/src/app/commands.rs b/src/app/commands.rs index e59d484e2..afcc2772b 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -1723,7 +1723,7 @@ impl OpenCADStudio { } else { for (handle, _) in &selected { if let Some(entity) = self.tabs[i].scene.document.get_entity(*handle) { - let type_name = entity_type_name(entity); + let type_name = crate::entities::names::dxf_name(entity); let common = entity.common(); let color_str = common .color @@ -2106,7 +2106,7 @@ impl OpenCADStudio { if let Some(props) = entity.mass_props() { self.command_line.push_output(&format!( "{} Area={:.4} Perimeter={:.4} Centroid=({:.4},{:.4})", - entity_type_name(entity), + crate::entities::names::dxf_name(entity), props.area, props.perimeter, props.cx, @@ -2170,7 +2170,7 @@ impl OpenCADStudio { .filter(|e| { let c = e.common(); match prop.as_str() { - "TYPE" => entity_type_name(e).to_uppercase() == val, + "TYPE" => crate::entities::names::dxf_name(e).to_uppercase() == val, "LAYER" => c.layer.to_uppercase() == val, "COLOR" => c .color @@ -2207,7 +2207,7 @@ impl OpenCADStudio { let mut counts: std::collections::BTreeMap = Default::default(); for e in self.tabs[i].scene.document.entities() { let layer = &e.common().layer; - let type_name = entity_type_name(e); + let type_name = crate::entities::names::dxf_name(e); let key = match &filter { Some(f) if f == "LAYER" => layer.clone(), Some(f) if f == "TYPE" => type_name.to_string(), @@ -5344,40 +5344,6 @@ fn find_last_linear_dim( result } -fn entity_type_name(entity: &acadrust::EntityType) -> &'static str { - match entity { - acadrust::EntityType::Line(_) => "LINE", - acadrust::EntityType::Circle(_) => "CIRCLE", - acadrust::EntityType::Arc(_) => "ARC", - acadrust::EntityType::LwPolyline(_) => "LWPOLYLINE", - acadrust::EntityType::Polyline(_) => "POLYLINE", - acadrust::EntityType::Polyline2D(_) => "POLYLINE2D", - acadrust::EntityType::Polyline3D(_) => "POLYLINE3D", - acadrust::EntityType::Text(_) => "TEXT", - acadrust::EntityType::MText(_) => "MTEXT", - acadrust::EntityType::Insert(_) => "INSERT", - acadrust::EntityType::Hatch(_) => "HATCH", - acadrust::EntityType::Dimension(_) => "DIMENSION", - acadrust::EntityType::Viewport(_) => "VIEWPORT", - acadrust::EntityType::Spline(_) => "SPLINE", - acadrust::EntityType::Ellipse(_) => "ELLIPSE", - acadrust::EntityType::Point(_) => "POINT", - acadrust::EntityType::Ray(_) => "RAY", - acadrust::EntityType::XLine(_) => "XLINE", - acadrust::EntityType::Face3D(_) => "3DFACE", - acadrust::EntityType::Table(_) => "TABLE", - acadrust::EntityType::MLine(_) => "MLINE", - acadrust::EntityType::RasterImage(_) => "RASTERIMAGE", - acadrust::EntityType::Wipeout(_) => "WIPEOUT", - acadrust::EntityType::Underlay(_) => "UNDERLAY", - acadrust::EntityType::AttributeDefinition(_) => "ATTDEF", - acadrust::EntityType::AttributeEntity(_) => "ATTRIB", - acadrust::EntityType::Leader(_) => "LEADER", - acadrust::EntityType::Tolerance(_) => "TOLERANCE", - acadrust::EntityType::Shape(_) => "SHAPE", - _ => "ENTITY", - } -} @@ -5399,7 +5365,7 @@ fn build_data_extraction_csv(doc: &acadrust::CadDocument) -> String { if !ms_handle.is_null() && e.common().owner_handle != ms_handle { continue; } - let type_name = entity_type_name(e); + let type_name = crate::entities::names::dxf_name(e); let handle = format!("{:X}", e.common().handle.value()); let layer = csv_escape(&e.common().layer); let color = format!("{}", e.common().color); diff --git a/src/app/helpers.rs b/src/app/helpers.rs index e712a5da2..791a7e0c1 100644 --- a/src/app/helpers.rs +++ b/src/app/helpers.rs @@ -164,7 +164,7 @@ pub(super) fn next_group_auto_name(scene: &crate::scene::Scene) -> String { // ── Entity type labels ───────────────────────────────────────────────────── pub(super) fn entity_type_label(entity: &acadrust::EntityType) -> String { - crate::scene::properties::entity_type_name(entity).to_string() + crate::entities::names::ui_name(entity).to_string() } pub(super) fn entity_type_key(entity: &acadrust::EntityType) -> String { diff --git a/src/entities/mod.rs b/src/entities/mod.rs index 275208f24..0a1d1d932 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -13,6 +13,7 @@ pub mod mesh; pub mod mline; pub mod mtext; pub mod multileader; +pub mod names; pub mod ole2frame; pub mod point; pub mod polyline; diff --git a/src/entities/names.rs b/src/entities/names.rs new file mode 100644 index 000000000..14b262dd1 --- /dev/null +++ b/src/entities/names.rs @@ -0,0 +1,96 @@ +//! Human-readable and DXF-canonical names for each `EntityType` variant. +//! +//! Two functions because they're used for different audiences: +//! - `ui_name` — properties panel / status bar (mixed-case, friendly). +//! - `dxf_name` — command-line output / file format (uppercase, matches +//! the DXF entity record type name). +//! +//! Co-located so adding a new variant only requires updating one file. + +use acadrust::EntityType; + +/// Mixed-case display name shown to the user in panels, tooltips, etc. +pub fn ui_name(e: &EntityType) -> &'static str { + match e { + EntityType::Point(_) => "Point", + EntityType::Line(_) => "Line", + EntityType::Circle(_) => "Circle", + EntityType::Arc(_) => "Arc", + EntityType::Ellipse(_) => "Ellipse", + EntityType::Spline(_) => "Spline", + EntityType::LwPolyline(_) => "Polyline", + EntityType::Polyline(_) => "Polyline", + EntityType::Polyline2D(_) => "Polyline2D", + EntityType::Polyline3D(_) => "Polyline3D", + EntityType::PolyfaceMesh(_) => "PolyfaceMesh", + EntityType::PolygonMesh(_) => "PolygonMesh", + EntityType::Text(_) => "Text", + EntityType::MText(_) => "MText", + EntityType::Dimension(_) => "Dimension", + EntityType::Leader(_) => "Leader", + EntityType::MultiLeader(_) => "MultiLeader", + EntityType::Tolerance(_) => "Tolerance", + EntityType::Insert(_) => "Block Reference", + EntityType::Block(_) => "Block", + EntityType::BlockEnd(_) => "Block End", + EntityType::Hatch(_) => "Hatch", + EntityType::Solid(_) => "Solid", + EntityType::Face3D(_) => "3D Face", + EntityType::Solid3D(_) => "3D Solid", + EntityType::Region(_) => "Region", + EntityType::Body(_) => "Body", + EntityType::Mesh(_) => "Mesh", + EntityType::Ray(_) => "Ray", + EntityType::XLine(_) => "XLine", + EntityType::MLine(_) => "MLine", + EntityType::Viewport(_) => "Viewport", + EntityType::RasterImage(_) => "Raster Image", + EntityType::Wipeout(_) => "Wipeout", + EntityType::Underlay(_) => "Underlay", + EntityType::Shape(_) => "Shape", + EntityType::Table(_) => "Table", + EntityType::AttributeDefinition(_) => "Attribute Definition", + EntityType::AttributeEntity(_) => "Attribute", + EntityType::Ole2Frame(_) => "OLE Frame", + EntityType::Seqend(_) => "Seqend", + EntityType::Unknown(_) => "Unknown", + } +} + +/// Canonical DXF entity type record name (uppercase), as used by AutoCAD's +/// command-line LIST output and the DXF file format. Variants without a +/// well-defined DXF name fall back to "ENTITY". +pub fn dxf_name(e: &EntityType) -> &'static str { + match e { + EntityType::Line(_) => "LINE", + EntityType::Circle(_) => "CIRCLE", + EntityType::Arc(_) => "ARC", + EntityType::LwPolyline(_) => "LWPOLYLINE", + EntityType::Polyline(_) => "POLYLINE", + EntityType::Polyline2D(_) => "POLYLINE2D", + EntityType::Polyline3D(_) => "POLYLINE3D", + EntityType::Text(_) => "TEXT", + EntityType::MText(_) => "MTEXT", + EntityType::Insert(_) => "INSERT", + EntityType::Hatch(_) => "HATCH", + EntityType::Dimension(_) => "DIMENSION", + EntityType::Viewport(_) => "VIEWPORT", + EntityType::Spline(_) => "SPLINE", + EntityType::Ellipse(_) => "ELLIPSE", + EntityType::Point(_) => "POINT", + EntityType::Ray(_) => "RAY", + EntityType::XLine(_) => "XLINE", + EntityType::Face3D(_) => "3DFACE", + EntityType::Table(_) => "TABLE", + EntityType::MLine(_) => "MLINE", + EntityType::RasterImage(_) => "RASTERIMAGE", + EntityType::Wipeout(_) => "WIPEOUT", + EntityType::Underlay(_) => "UNDERLAY", + EntityType::AttributeDefinition(_) => "ATTDEF", + EntityType::AttributeEntity(_) => "ATTRIB", + EntityType::Leader(_) => "LEADER", + EntityType::Tolerance(_) => "TOLERANCE", + EntityType::Shape(_) => "SHAPE", + _ => "ENTITY", + } +} diff --git a/src/scene/properties.rs b/src/scene/properties.rs index 1f9223651..0f431d9b9 100644 --- a/src/scene/properties.rs +++ b/src/scene/properties.rs @@ -62,54 +62,8 @@ pub fn fallback_properties(_handle: Handle, entity: &EntityType) -> PropSection props: vec![Property { label: "Type".into(), field: "type", - value: PropValue::ReadOnly(entity_type_name(entity).into()), + value: PropValue::ReadOnly(crate::entities::names::ui_name(entity).into()), }], } } -pub fn entity_type_name(e: &EntityType) -> &'static str { - match e { - EntityType::Point(_) => "Point", - EntityType::Line(_) => "Line", - EntityType::Circle(_) => "Circle", - EntityType::Arc(_) => "Arc", - EntityType::Ellipse(_) => "Ellipse", - EntityType::Spline(_) => "Spline", - EntityType::LwPolyline(_) => "Polyline", - EntityType::Polyline(_) => "Polyline", - EntityType::Polyline2D(_) => "Polyline2D", - EntityType::Polyline3D(_) => "Polyline3D", - EntityType::PolyfaceMesh(_) => "PolyfaceMesh", - EntityType::PolygonMesh(_) => "PolygonMesh", - EntityType::Text(_) => "Text", - EntityType::MText(_) => "MText", - EntityType::Dimension(_) => "Dimension", - EntityType::Leader(_) => "Leader", - EntityType::MultiLeader(_) => "MultiLeader", - EntityType::Tolerance(_) => "Tolerance", - EntityType::Insert(_) => "Block Reference", - EntityType::Block(_) => "Block", - EntityType::BlockEnd(_) => "Block End", - EntityType::Hatch(_) => "Hatch", - EntityType::Solid(_) => "Solid", - EntityType::Face3D(_) => "3D Face", - EntityType::Solid3D(_) => "3D Solid", - EntityType::Region(_) => "Region", - EntityType::Body(_) => "Body", - EntityType::Mesh(_) => "Mesh", - EntityType::Ray(_) => "Ray", - EntityType::XLine(_) => "XLine", - EntityType::MLine(_) => "MLine", - EntityType::Viewport(_) => "Viewport", - EntityType::RasterImage(_) => "Raster Image", - EntityType::Wipeout(_) => "Wipeout", - EntityType::Underlay(_) => "Underlay", - EntityType::Shape(_) => "Shape", - EntityType::Table(_) => "Table", - EntityType::AttributeDefinition(_) => "Attribute Definition", - EntityType::AttributeEntity(_) => "Attribute", - EntityType::Ole2Frame(_) => "OLE Frame", - EntityType::Seqend(_) => "Seqend", - EntityType::Unknown(_) => "Unknown", - } -}