Files
OneCAD-Draft/src/entities/names.rs
T
Hakan SevenandClaude Opus 4.7 5da32ff202 refactor(entities): collocate ui_name + dxf_name into entities/names.rs
Two near-identical match-on-EntityType tables lived far apart:
scene/properties.rs::entity_type_name returned mixed-case UI labels;
app/commands.rs::entity_type_name returned uppercase DXF record names.
Both enumerated ~30 variants; adding a new entity meant remembering to
touch two files in two crates' worth of source layout.

Move both into a single entities/names.rs as `ui_name()` and
`dxf_name()`. Adjacent so a new variant gets both labels added at once;
function names make the intended audience explicit at the callsite.

scene/properties.rs and app/commands.rs each lose their local match
plus one re-export, gaining a `crate::entities::names::*` call.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 17:18:47 +03:00

97 lines
4.0 KiB
Rust

//! 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",
}
}