408d30ea56
* Joint drive moves parts without evaluating them A joint drive (also the Drive dialog and motion steps) changes only occurrence transforms, yet it re-evaluated nearly the whole timeline: every feature that might read another component's geometry (a sketch with any link, even to its own axis) hashed every occurrence's transform into its fingerprint, so any motion invalidated it and everything after it, and no new pose was ever in the cache. - Placement digest: a feature now hashes only where the geometry it actually reads lies relative to its own frame (link sources, anchors, profiles and paths from other components, mirror placements; To Object and face/edge-picked planes read every component, relatively). Moving parts that keep those relative placements leaves every result in place: nothing is evaluated or re-meshed. In-context features whose referenced part really moved still rebuild. - Evaluated ahead, applied once: `Ahead::evaluate` returns what it evaluated and `Session::prime` lets the window-thread pass take it (history commands and dialog OK), so an off-thread command no longer costs twice on designs past the cache's budget. - Contact meshes are kept per body geometry across drives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Joint drive: booleans read only their input bodies' placements A join, cut or intersect with named targets, and a Combine, read every placement, so a joined part transferred to a component re-ran its boolean at each new joint pose. Each now hashes only the placements of the bodies it actually takes as inputs, resolved in its timeline input state (before any later BodyTransfer), relative to the frame that evaluates it; Combine reads its tools relative to its target. Unresolved and legacy component or path reads keep the conservative dependency. 24 new joint_pose_ tests cover new angles, transfers, targets, save/reopen, undo and real relative motion (900 -> 800 mm3). Supplement offered on #3397 by takuto-NA. Co-Authored-By: takuto-NA <183465875+takuto-NA@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Creating a component recomputes nothing A new, empty component changes nothing a feature reads, yet it changed the placement fingerprint of every targeted boolean, Combine and To Object feature, so `component.create` evaluated the timeline again: - the first component of a design: `placement_digest` returned 0 while the design had no placements and a nonzero value once it had one; - To / From Object and legacy face- or edge-picked planes hashed every component, not just those holding the bodies, sketches and construction geometry the feature can reach. Co-Authored-By: Tyler Chiriboga <18270301+Tyler-Chiriboga@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test: creating a component after a legacy face sketch recomputes nothing A face extruded after its construction certificate is gone (a patterned cut, a pad joined flush with it, then one more cut) is sketched on a legacy face plane, which reads every placed body. A new, empty component must not change what it reads either (reported by Tyler Chiriboga). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: takuto-NA <183465875+takuto-NA@users.noreply.github.com> Co-authored-by: Tyler Chiriboga <18270301+Tyler-Chiriboga@users.noreply.github.com>
142 lines
6.3 KiB
Rust
142 lines
6.3 KiB
Rust
//! OK off the window thread: a feature that takes longer than the app's wait is computed beside
|
||
//! the window, the dialog saying so, and applied once it is in; Cancel drops it.
|
||
|
||
use std::time::Duration;
|
||
|
||
use serde_json::json;
|
||
|
||
use crate::scenario::Harness;
|
||
|
||
/// A 60 × 20 × 10 block and, just finished on its top, a 10 × 10 square: Extrude takes it.
|
||
fn square_on_a_block() -> Harness {
|
||
let mut h = Harness::new();
|
||
h.app.home.open = false;
|
||
for (id, p) in [
|
||
("sketch.create", json!({"plane": "XY"})),
|
||
("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [60, 20]})),
|
||
("sketch.finish", json!({})),
|
||
("solid.extrude", json!({"distance": 10})),
|
||
("sketch.create", json!({"plane": {"origin": [0, 0, 10], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}})),
|
||
("sketch.rectangle.two_point", json!({"p0": [5, 5], "p1": [15, 15]})),
|
||
] {
|
||
h.app.run(id, p).unwrap();
|
||
}
|
||
h.app.finish_sketch();
|
||
h.app.start("solid.extrude");
|
||
h.frames(2);
|
||
h
|
||
}
|
||
|
||
/// Frames until OK's evaluation is in and applied (a few seconds at most).
|
||
fn until_applied(h: &mut Harness) {
|
||
for _ in 0..500 {
|
||
if h.app.applying.is_none() {
|
||
break;
|
||
}
|
||
h.frames(1);
|
||
std::thread::sleep(Duration::from_millis(10));
|
||
}
|
||
h.frames(1);
|
||
}
|
||
|
||
#[test]
|
||
fn ok_computes_off_the_window_thread_saying_so_then_applies() {
|
||
let mut h = square_on_a_block();
|
||
h.app.apply_off_thread = Some(Duration::ZERO);
|
||
// The evaluation is held until the dialog has been seen saying so (it is in the cache all
|
||
// the same), so no frame can apply it before the checks below.
|
||
let (finish, gate) = std::sync::mpsc::channel();
|
||
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
|
||
h.step(&json!({"key": "Enter"})).unwrap();
|
||
assert!(h.app.applying.is_some() && h.app.dialog.is_some(), "computing, the dialog open");
|
||
h.frames(1);
|
||
assert!(h.widget("Computing… 0 s").is_some(), "the dialog says it computes");
|
||
// Enter again does not start it twice.
|
||
h.step(&json!({"key": "Enter"})).unwrap();
|
||
finish.send(()).unwrap();
|
||
until_applied(&mut h);
|
||
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().and_then(|d| d.error.clone()));
|
||
h.step(&json!({"expect": {"bodies": 1, "volume": 13000}})).unwrap();
|
||
assert_eq!(h.app.session.doc.features.len(), 4, "one extrude added");
|
||
}
|
||
|
||
#[test]
|
||
fn cancel_while_computing_applies_nothing() {
|
||
let mut h = square_on_a_block();
|
||
h.app.apply_off_thread = Some(Duration::ZERO);
|
||
// Held, as the preview's evaluation is in the cache and would otherwise be in before OK's
|
||
// wait is over, applying at once.
|
||
let (finish, gate) = std::sync::mpsc::channel();
|
||
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
|
||
let features = h.app.session.doc.features.len();
|
||
h.step(&json!({"key": "Enter"})).unwrap();
|
||
assert!(h.app.applying.is_some());
|
||
h.step(&json!({"key": "Escape"})).unwrap();
|
||
assert!(h.app.applying.is_none() && h.app.dialog.is_none());
|
||
finish.send(()).unwrap();
|
||
h.frames(5);
|
||
assert_eq!(h.app.session.doc.features.len(), features);
|
||
}
|
||
|
||
/// #2929: the feature must not appear in the frame OK starts computing in. The window thread
|
||
/// can be held up between starting the evaluation and the check that takes it up, and the
|
||
/// feature then appears where the dialog says it is computing - which is what made
|
||
/// `cancel_while_computing_applies_nothing` fail under load.
|
||
#[test]
|
||
fn ok_computing_off_the_window_thread_does_not_apply_in_the_frame_it_starts() {
|
||
let mut h = square_on_a_block();
|
||
h.app.apply_off_thread = Some(Duration::ZERO);
|
||
// Held past OK's wait (the evaluation is in the cache), then let go before the next frame.
|
||
let (finish, gate) = std::sync::mpsc::channel();
|
||
h.app.apply_gate = Some(std::sync::Arc::new(std::sync::Mutex::new(gate)));
|
||
let features = h.app.session.doc.features.len();
|
||
h.step(&json!({"key": "Enter"})).unwrap();
|
||
assert!(h.app.applying.is_some(), "the dialog is computing");
|
||
finish.send(()).unwrap();
|
||
assert_eq!(h.app.session.doc.features.len(), features, "nothing applied in the frame it started");
|
||
// A frame later the evaluation is in and the feature is applied.
|
||
until_applied(&mut h);
|
||
assert_eq!(h.app.session.doc.features.len(), features + 1);
|
||
}
|
||
|
||
#[test]
|
||
fn the_dialog_holds_its_inputs_while_ok_computes() {
|
||
let mut h = square_on_a_block();
|
||
h.app.fit_view();
|
||
h.frames(2);
|
||
let picked = h.app.dialog.as_ref().map(|d| d.inputs[0].items.clone()).unwrap();
|
||
// OK computing, until the test lets it finish.
|
||
let (finish, done) = std::sync::mpsc::channel();
|
||
let cmds = h.app.dialog.as_ref().and_then(|d| crate::dialogs::apply_commands(&h.app, d).ok()).unwrap();
|
||
h.app.applying = Some(crate::dialogs::Applying::computing(done, cmds));
|
||
// A click on the square picked would take it out of the profiles.
|
||
h.step(&json!({"click": {"world": [10, 10, 10]}})).unwrap();
|
||
h.frames(2);
|
||
assert_eq!(h.app.dialog.as_ref().map(|d| d.inputs[0].items.clone()), Some(picked), "no pick while computing");
|
||
finish.send(None).unwrap();
|
||
until_applied(&mut h);
|
||
assert!(h.app.dialog.is_none());
|
||
h.step(&json!({"expect": {"bodies": 1, "volume": 13000}})).unwrap();
|
||
}
|
||
|
||
/// Inputs that changed while OK computed (nothing should change them) are computed in turn, off
|
||
/// the window thread too, then applied: run as OK finished, they would hold the window for the
|
||
/// whole boolean.
|
||
#[test]
|
||
fn inputs_changed_while_ok_computes_are_computed_off_the_thread_too() {
|
||
let mut h = square_on_a_block();
|
||
h.app.apply_off_thread = Some(Duration::ZERO);
|
||
let features = h.app.session.doc.features.len();
|
||
// OK computing other commands than the dialog's, until the test lets it finish.
|
||
let (finish, done) = std::sync::mpsc::channel();
|
||
h.app.applying = Some(crate::dialogs::Applying::computing(done, Vec::new()));
|
||
finish.send(None).unwrap();
|
||
h.frames(1);
|
||
assert!(h.app.applying.is_some(), "the dialog's own commands are computing");
|
||
assert_eq!(h.app.session.doc.features.len(), features, "nothing applied on the window thread");
|
||
until_applied(&mut h);
|
||
assert!(h.app.dialog.is_none());
|
||
assert_eq!(h.app.session.doc.features.len(), features + 1);
|
||
h.step(&json!({"expect": {"bodies": 1, "volume": 13000}})).unwrap();
|
||
}
|