refactor(commands): per-entity MassProps + TextContent traits

Two free helpers in app/commands.rs lived as big match-on-EntityType
blocks: massprop_entity (Circle/Arc/Line/LwPolyline/Ellipse area +
perimeter + centroid, ~140 lines) and entity_text_content /
replace_entity_text (Text/MText/AttributeDefinition/AttributeEntity).

Move each to its own trait in entities/traits.rs and implement
per-entity:

  MassPropsCalc  — Circle, Arc, Line, LwPolyline, Ellipse
  TextContent    — Text, MText, AttributeDefinition, AttributeEntity

EntityTypeOps gets dispatch shims that route to the trait via the
existing macro, so callsites just call entity.mass_props() /
entity.text_content() / entity.replace_text(search, rep).

The remaining free helpers in commands.rs (entity_list_details,
entity_extra_info, entity_type_name, build_data_extraction_csv) are
single-command formatting helpers tightly coupled to LIST / EXTRACT /
text-format output. Distributing them as per-entity methods would
inflate every entity file with command-side formatting concerns
without making the command-side any cleaner — left in place.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-05-23 23:30:34 +03:00
commit e78321190a
10 changed files with 266 additions and 193 deletions

View file

@ -792,3 +792,28 @@ impl Transformable for AttributeEntity {
});
}
}
impl crate::entities::traits::TextContent for acadrust::entities::AttributeDefinition {
fn text_content(&self) -> Option<String> {
Some(self.default_value.clone())
}
fn replace_text(&mut self, search: &str, rep: &str) {
let search_lc = search.to_lowercase();
if self.default_value.to_lowercase().contains(&search_lc) {
self.default_value = self.default_value.replace(search, rep);
}
}
}
impl crate::entities::traits::TextContent for acadrust::entities::AttributeEntity {
fn text_content(&self) -> Option<String> {
Some(self.get_value().to_string())
}
fn replace_text(&mut self, search: &str, rep: &str) {
let search_lc = search.to_lowercase();
let cur = self.get_value().to_string();
if cur.to_lowercase().contains(&search_lc) {
self.set_value(cur.replace(search, rep));
}
}
}