Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Feature edits: OK computes off the window thread in a dialog without a live preview too (#7388)

Kai Evans9efcb461f859
diff --git a/crates/ui-egui/src/apply_off_thread_tests.rs b/crates/ui-egui/src/apply_off_thread_tests.rs
index b177fef687..ec98b12034 100644
--- a/crates/ui-egui/src/apply_off_thread_tests.rs
+++ b/crates/ui-egui/src/apply_off_thread_tests.rs
@@ -336,6 +336,42 @@ fn changed_first_cut_adopts_its_entire_suffix_without_window_evaluation() {
assert!((redone - after_volume).abs() < 0.001);
}
+/// An edit in a dialog without a live preview (Offset Plane) is computed off the window thread
+/// too: OK evaluates nothing here, the features after the plane included.
+#[test]
+fn an_edit_without_a_preview_adopts_its_suffix_without_window_evaluation() {
+ let mut h = Harness::new();
+ h.app.home.open = false;
+ h.app.apply_off_thread = Some(Duration::ZERO);
+ h.app.run("construct.plane.offset", json!({"base":"XY","offset":10,"name":"Shelf"})).unwrap();
+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();
+ h.app.run("solid.box", json!({"corner":[5,5,20],"length":10,"width":10,"height":5,"operation":"join"})).unwrap();
+ let plane = h.app.session.doc.find_feature("Shelf").unwrap().id;
+ let undo = h.app.session.undo.len();
+ h.call("ui.editFeature", json!({"feature":plane}));
+ h.frames(2);
+ assert!(h.app.dialog.as_ref().is_some_and(|d| !d.previews()), "Offset Plane has no live preview");
+ if let Some(crate::dialogs::Kind::OffsetPlane { offset }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
+ *offset = "15".into();
+ }
+ let window = std::sync::Arc::new(solidcraft_engine::doc::progress::Progress::default());
+ solidcraft_engine::doc::progress::watch(window.clone(), || {
+ h.step(&json!({"click":{"handle":"dialog:OK"}})).unwrap();
+ assert!(h.app.applying.is_some(), "computing beside the window");
+ until_applied(&mut h);
+ });
+ assert_eq!(window.features(), (0, 0), "nothing evaluated on the window thread");
+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().and_then(|d| d.error.clone()));
+ assert_eq!(h.app.session.doc.marker, None);
+ assert_eq!(h.app.session.undo.len(), undo + 1);
+ let shelf = &h.app.session.doc.feature(plane).unwrap().kind;
+ assert!(
+ matches!(shelf, solidcraft_engine::doc::FeatureKind::ConstructionPlane { plane: solidcraft_engine::doc::PlaneRef::Offset { distance, .. } } if *distance == "15"),
+ "{shelf:?}"
+ );
+ h.step(&json!({"expect":{"bodies":1,"volume":24500}})).unwrap();
+}
+
#[test]
fn cancelling_an_edit_restores_pinned_geometry_without_evaluating_an_evicted_suffix() {
let (mut h, target) = cut_chain();
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 98ef7c920b..3f827d9e3b 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -548,8 +548,11 @@ impl DialogComputation {
session,
cmds,
marker: d.editing.map(|(_, marker)| marker),
+ // The editor's pinned original is for a dialog that previews (as `open_feature_edit`
+ // keeps it); one that no longer does (Modeled unticked) edits the design as it is.
editing: d
.editing
+ .filter(|_| d.previews())
.and(app.editing_state.as_ref())
.map(|state| EditingState { source: state.source.scratch(), original: state.original.scratch() }),
})
@@ -619,12 +622,13 @@ fn display_quality(app: &SolveApp) -> solidcraft_engine::doc::display_quality::D
solidcraft_engine::doc::display_quality::DisplayQuality::parse(&app.preferences.display_quality).unwrap_or_default()
}
-/// Desktop feature dialogs evaluate the entire command and its dependent suffix once.
-/// Results wait until a later frame before adoption, keeping the computing state visible.
+/// Desktop feature dialogs evaluate the entire command and its dependent suffix once; so does
+/// any feature edit, with a live preview or without. Results wait until a later frame before
+/// adoption, keeping the computing state visible.
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn begin_applying(app: &SolveApp, d: &Dialog) -> Option<Applying> {
let wait = app.apply_off_thread?;
- if !d.previews() {
+ if !d.previews() && d.editing.is_none() {
return None;
}
let computation = DialogComputation::new(app, d).ok()?;
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs
index 713e311f99..8c633f0a97 100644
--- a/crates/ui-egui/src/preselect_tests.rs
+++ b/crates/ui-egui/src/preselect_tests.rs
@@ -1699,6 +1699,39 @@ fn modeled_thread_survives_timeline_double_click_and_ok() {
}
}
+/// A modeled thread's editor previews; unticking Modeled makes it a plain edit, so its OK
+/// computes off the window thread from the design as it is: a body hidden meanwhile doesn't
+/// refuse it as a changed design.
+#[test]
+fn a_thread_edit_switched_to_cosmetic_applies_after_a_body_is_hidden() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.home.open = false;
+ h.app.apply_off_thread = Some(std::time::Duration::ZERO);
+ h.app.run("solid.cylinder", json!({"radius":4,"height":4})).unwrap();
+ h.app.run("solid.box", json!({"corner":[20,0,0],"length":4,"width":4,"height":4})).unwrap();
+ let Sel::Face { point, .. } = thread_face(&h.app, "Body1") else { panic!("face") };
+ let id = h.app.run("solid.thread", json!({"face":point,"designation":"M8x1","modeled":true})).unwrap()["feature"].as_u64().unwrap();
+ h.frames(4);
+ h.step(&json!({"click":{"handle":"timeline:Thread1"},"double":true})).unwrap();
+ h.frames(4);
+ assert!(h.app.dialog.as_ref().unwrap().previews(), "a modeled thread previews");
+ h.app.dialog.as_mut().unwrap().extra["modeled"] = json!(false);
+ assert!(!h.app.dialog.as_ref().unwrap().previews());
+ h.app.run("browser.visibility", json!({"items":["Body2"],"visible":false})).unwrap();
+ h.step(&json!({"widget":"OK"})).unwrap();
+ for _ in 0..500 {
+ if h.app.applying.is_none() {
+ break;
+ }
+ h.frames(1);
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ h.frames(4);
+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().and_then(|d| d.error.clone()));
+ assert_eq!(h.app.session.doc.marker, None);
+ assert!(matches!(h.app.session.doc.feature(id).unwrap().kind, solidcraft_engine::doc::FeatureKind::Thread { modeled: false, .. }));
+}
+
#[test]
fn planar_face_reopen_keeps_the_tight_pick_tolerance() {
for (command, mut params, point) in [