From 2885898da6fd9eb8a61393d928f5abcec8f83604 Mon Sep 17 00:00:00 2001 From: gianlucafiore Date: Thu, 3 Sep 2026 17:02:06 -0300 Subject: [PATCH] fix(trim): honor preselected cutting boundaries --- src/app/commands/dim.rs | 12 +++++++++- src/modules/draw/modify/trim.rs | 39 ++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/app/commands/dim.rs b/src/app/commands/dim.rs index b697b71df..d03e7cfa3 100644 --- a/src/app/commands/dim.rs +++ b/src/app/commands/dim.rs @@ -1238,8 +1238,18 @@ impl OpenCADStudio { .map(|e| (h, e)) }) .collect(); + let initial_edges: Vec = self.tabs[i] + .scene + .selected_entities() + .into_iter() + .filter_map(|(handle, entity)| { + crate::modules::draw::modify::trim::is_trim_boundary_entity(&entity) + .then_some(handle) + }) + .collect(); let all_entities: Vec<_> = entities.into_iter().map(|(_, e)| e).collect(); - let new_cmd = TrimCommand::new(all_entities); + let new_cmd = + TrimCommand::with_cutting_edges(all_entities, initial_edges); self.command_line.push_info(&new_cmd.prompt()); self.tabs[i].active_cmd = Some(Box::new(new_cmd)); } diff --git a/src/modules/draw/modify/trim.rs b/src/modules/draw/modify/trim.rs index 039db2b9a..d1341013a 100644 --- a/src/modules/draw/modify/trim.rs +++ b/src/modules/draw/modify/trim.rs @@ -149,7 +149,22 @@ impl Geo { } } } - +pub fn is_trim_boundary_entity(entity: &EntityType) -> bool { + matches!( + entity, + EntityType::Line(_) + | EntityType::Arc(_) + | EntityType::Circle(_) + | EntityType::Ellipse(_) + | EntityType::Ray(_) + | EntityType::XLine(_) + | EntityType::Spline(_) + | EntityType::LwPolyline(_) + | EntityType::Polyline(_) + | EntityType::Polyline2D(_) + | EntityType::Polyline3D(_) + ) +} fn build_geos(entities: &[EntityType]) -> Vec { let mut out = Vec::new(); for e in entities { @@ -2169,21 +2184,33 @@ pub struct TrimCommand { impl TrimCommand { pub fn new(all_entities: Vec) -> Self { + Self::with_cutting_edges(all_entities, Vec::new()) + } + + pub fn with_cutting_edges( + all_entities: Vec, + initial_edges: Vec, + ) -> Self { let all_entities: Vec = all_entities .iter() .map(entity_with_lwpolyline_world_xy) .collect(); + let entity_index = ModifyEntityIndex::build(&all_entities); - let geos = build_geos(&all_entities); - Self { + + let mut cmd = Self { all_entities, entity_index, - geos, + geos: Vec::new(), mode: TrimMode::Pick, - edge_set: Vec::new(), + edge_set: initial_edges, implied_edges: false, shift: false, - } + }; + + cmd.rebuild_geos(); + + cmd } /// Boundary geometry from the edge selection (or everything when none),