From 035d31e2011cf9592bb71cf1f1069e905c46a7a4 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 10 Sep 2026 17:00:16 +0300 Subject: [PATCH] fix(section): preserve selected slice depth --- src/app/update/command.rs | 37 +++++++++++++++++++------------------ src/entities/extended.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/app/update/command.rs b/src/app/update/command.rs index c91e0f3e6..43074fa72 100644 --- a/src/app/update/command.rs +++ b/src/app/update/command.rs @@ -1443,24 +1443,25 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task { } } // One-shot action — apply immediately. - let unchanged = self.tabs[i] - .scene - .document - .get_entity(popup.handle) - .is_some_and(|entity| match (item.action, entity) { - (GripMenuAction::ShowFit, acadrust::EntityType::Spline(spline)) => { - !spline.cv_frame_visible - && crate::entities::spline::uses_fit_method(spline) - } - ( - GripMenuAction::ShowControlVertices, - acadrust::EntityType::Spline(spline), - ) => { - spline.cv_frame_visible - || !crate::entities::spline::uses_fit_method(spline) - } - _ => false, - }); + let unchanged = item.label.starts_with('✓') + || self.tabs[i] + .scene + .document + .get_entity(popup.handle) + .is_some_and(|entity| match (item.action, entity) { + (GripMenuAction::ShowFit, acadrust::EntityType::Spline(spline)) => { + !spline.cv_frame_visible + && crate::entities::spline::uses_fit_method(spline) + } + ( + GripMenuAction::ShowControlVertices, + acadrust::EntityType::Spline(spline), + ) => { + spline.cv_frame_visible + || !crate::entities::spline::uses_fit_method(spline) + } + _ => false, + }); if unchanged { return Task::none(); } diff --git a/src/entities/extended.rs b/src/entities/extended.rs index f82a5e261..3712029a3 100644 --- a/src/entities/extended.rs +++ b/src/entities/extended.rs @@ -2179,6 +2179,12 @@ impl Grippable for ExtendedEntity { GripMenuAction::SectionVolume => "Volume", _ => return, }; + let ExtendedEntityData::SectionObject(data) = &self.data else { + return; + }; + if section_kind(self, data) == value { + return; + } apply_section_prop(self, "ext_section_state", value); } } @@ -2198,3 +2204,35 @@ impl Transformable for ExtendedEntity { apply_transform(self, transform); } } + +#[cfg(test)] +mod tests { + use super::*; + use acadrust::entities::EntityCommon; + use acadrust::types::Color; + + #[test] + fn reselecting_slice_keeps_its_depth() { + let mut entity = ExtendedEntity { + common: EntityCommon::new(), + data: ExtendedEntityData::SectionObject(SectionObjectData { + state: 1, + flags: 5, + name: String::new(), + vertical_direction: Vector3::UNIT_Z, + top_height: 1.0, + bottom_height: 1.0, + indicator_alpha: 70, + indicator_color: Color::from_index(9), + back_line_vertices: Vec::new(), + vertices: vec![Vector3::ZERO, Vector3::new(60.0, 0.0, 0.0)], + settings_handle: Handle::NULL, + }), + }; + set_section_slice_metadata(&mut entity, true, 0.25); + + entity.apply_grip_menu(SECTION_GRIP_STATE, GripMenuAction::SectionSlice); + + assert_eq!(section_slice_depth(&entity), Some(0.25)); + } +}