Preview modeled threads using the desktop background worker (#2264)
Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
committed by
GitHub
parent
07be3f8852
commit
26dd2548b7
@@ -89,6 +89,9 @@ completed drawings publish atomically. The browser still exports synchronously.
|
||||
|
||||
## Interactive modelling
|
||||
|
||||
- Modelled threads preview their cut before OK using the background worker on desktop.
|
||||
Browser users apply the cut with OK to avoid blocking on every edit.
|
||||
|
||||
- Thread resolves a suggested metric size when a cylindrical face is picked. Diameter and
|
||||
pitch selectors expose the existing metric designation parameter; custom designations stay
|
||||
editable, and Automatic size returns to the face's suggestion. Cosmetic/modelled and
|
||||
|
||||
@@ -857,6 +857,8 @@ impl Dialog {
|
||||
Kind::SketchModify(k) => return k.previews(),
|
||||
Kind::Plastic(k) => return k.previews(),
|
||||
Kind::Part(_) | Kind::PartSize(_) => return true,
|
||||
// Web previews run synchronously; a modelled thread can take seconds.
|
||||
Kind::Thread { .. } => return !cfg!(target_arch = "wasm32") && self.extra.get("modeled").and_then(Value::as_bool).unwrap_or(false),
|
||||
_ => {}
|
||||
}
|
||||
matches!(
|
||||
|
||||
@@ -127,15 +127,26 @@ fn feature_pattern_controls_preview_without_committing_and_cancel_cleanly() {
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn wait_feature_preview(h: &mut crate::scenario::Harness) {
|
||||
for _ in 0..300 {
|
||||
// A large faceted thread can outlive 300 UI frames on a busy CI host. This checks
|
||||
// completion, not preview speed; use a bounded wall-clock wait for the worker.
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(120);
|
||||
while std::time::Instant::now() < deadline {
|
||||
h.frames(2);
|
||||
if h.app.preview.active && !h.app.preview.busy {
|
||||
if !h.app.preview.busy && (h.app.preview.active || h.app.preview.error.is_some()) {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert!(h.app.preview.active && !h.app.preview.busy, "preview failed: {:?}", h.app.preview.error);
|
||||
assert!(
|
||||
h.app.preview.active && !h.app.preview.busy,
|
||||
"preview failed: active={} busy={} error={:?} dialog={:?}",
|
||||
h.app.preview.active,
|
||||
h.app.preview.busy,
|
||||
h.app.preview.error,
|
||||
h.app.dialog
|
||||
);
|
||||
assert!(h.app.preview.error.is_none());
|
||||
}
|
||||
|
||||
@@ -1270,6 +1281,55 @@ fn thread_choices_can_start_without_a_face_and_recover_from_invalid_text() {
|
||||
assert!(apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).is_err(), "a face is still required");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modelled_thread_preview_updates_reports_errors_and_cancels_without_changes() {
|
||||
fn designation(h: &mut crate::scenario::Harness, text: &str) {
|
||||
h.step(&json!({"click":{"handle":"dialog:thread_size"}})).unwrap();
|
||||
h.step(&json!({"key":"A","cmd":true})).unwrap();
|
||||
h.step(&json!({"text":text})).unwrap();
|
||||
}
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.cylinder", json!({"radius":4,"height":2})).unwrap();
|
||||
let saved = h.app.session.doc.to_json();
|
||||
let undo = h.app.session.undo.len();
|
||||
h.app.session.selection = vec![thread_face(&h.app, "Body1")];
|
||||
h.step(&json!({"start":"solid.thread"})).unwrap();
|
||||
designation(&mut h, "M8x1");
|
||||
h.step(&json!({"click":{"handle":"dialog:Modeled"}})).unwrap();
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().extra.get("modeled"), Some(&json!(true)), "{:?}", h.app.dialog);
|
||||
assert!(crate::dialogs::preview_commands(&h.app, h.app.dialog.as_ref().unwrap()).is_ok(), "{:?}", h.app.dialog);
|
||||
wait_feature_preview(&mut h);
|
||||
assert_eq!(h.app.preview.replaced, ["Body1"]);
|
||||
let first_key = h.app.preview.key;
|
||||
designation(&mut h, "M8x1.3");
|
||||
wait_feature_preview(&mut h);
|
||||
assert_ne!(h.app.preview.key, first_key, "changing pitch updates the preview before OK");
|
||||
designation(&mut h, "M6x1.3");
|
||||
for _ in 0..500 {
|
||||
h.frames(2);
|
||||
if !h.app.preview.busy && h.app.preview.error.is_some() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert!(h.app.preview.error.as_deref().is_some_and(|e| e.contains("does not fit")), "{:?}", h.app.preview.error);
|
||||
designation(&mut h, "M8x1.3");
|
||||
wait_feature_preview(&mut h);
|
||||
assert!(h.app.preview.error.is_none());
|
||||
assert_eq!(h.app.session.doc.to_json(), saved);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
h.step(&json!({"click":{"handle":"dialog:Modeled"}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(!h.app.preview.active && h.app.preview.replaced.is_empty(), "cosmetic threads leave the original body visible");
|
||||
h.step(&json!({"click":{"handle":"dialog:Modeled"}})).unwrap();
|
||||
wait_feature_preview(&mut h);
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(h.app.dialog.is_none() && !h.app.preview.active && h.app.preview.replaced.is_empty());
|
||||
assert_eq!(h.app.session.doc.to_json(), saved);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newer_options_reach_their_commands() {
|
||||
let mut app = boxed();
|
||||
|
||||
Reference in New Issue
Block a user