SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Feature editor: OK accepts the joint placements a roll back re-solves (#11094) (#11095)
Kai Evans9d1ad9f0b998
diff --git a/crates/engine/src/cmd/joints_coupling_tests.rs b/crates/engine/src/cmd/joints_coupling_tests.rsindex 9eba99aab5..57e78995b3 100644--- a/crates/engine/src/cmd/joints_coupling_tests.rs+++ b/crates/engine/src/cmd/joints_coupling_tests.rs@@ -408,3 +408,24 @@ fn a_motion_link_takes_its_driven_joints_freedom_with_nothing_grounded() {}}}++/// Rolling the marker back works a gear's ratio out from the faces as they were then, so the+/// editor's pinned model and its source differ in the link's ratio, and the edit still goes+/// through.+#[test]+fn an_editor_accepts_the_ratios_rolling_the_marker_works_out() {+ let mut s = gear_train();+ let before = s.doc.features.len();+ // G1's wall moves out to a radius of 12, so the link's ratio goes from -0.5 to -0.6.+ run(&mut s, "solid.offset_face", json!({"faces": [[10, 0, 2.5]], "distance": 2}));+ let ratio = |s: &Session| s.doc.assembly.links.first().map(|l| l.ratio).unwrap_or(f64::NAN);+ assert!(close_to(ratio(&s), -0.6), "{}", ratio(&s));+ let original = s.scratch();+ run(&mut s, "timeline.roll_to", json!({"position": before}));+ let source = s.scratch();+ assert!(close_to(ratio(&source), -0.5), "before the offset, the pitch radius is 10: {}", ratio(&source));+ let prepared = s.scratch().compute_editor_commands(&[], &source, original).unwrap();+ s.accept_commands(prepared).unwrap();+ assert_eq!(s.doc.marker, None);+ assert!(close_to(ratio(&s), -0.6), "{}", ratio(&s));+}diff --git a/crates/engine/src/computed_commands_tests.rs b/crates/engine/src/computed_commands_tests.rsindex 04b6d7df2c..9529499c17 100644--- a/crates/engine/src/computed_commands_tests.rs+++ b/crates/engine/src/computed_commands_tests.rs@@ -280,3 +280,41 @@ fn cancelling_an_editor_with_visibility_changes_restores_an_existing_history_marassert_eq!(session.doc.marker, Some(1));assert!(session.visibility.hidden_origin.is_empty());}++/// Rolling the marker back before a move of the body a joint seats on solves the joints again,+/// which puts the seated occurrence back where the body was: the editor's pinned model differs+/// from its source there, and only there, and the edit still goes through.+#[test]+fn an_editor_accepts_the_placements_rolling_the_marker_solves() {+ let mut session = Session::default();+ for (name, x) in [("A", 0), ("B", 20)] {+ session.execute("component.activate", &json!({"component": "root"})).unwrap();+ session.execute("component.create", &json!({"name": name})).unwrap();+ session.execute("solid.box", &json!({"length": 10, "width": 10, "height": 10, "corner": [x, 0, 0]})).unwrap();+ }+ let component = |s: &Session, name: &str| s.doc.components.iter().find(|c| c.name == name).map(|c| c.id).unwrap();+ let occurrence = |s: &Session, name: &str| {+ let component = component(s, name);+ s.doc.occurrences.iter().find(|o| o.component == component).cloned().unwrap()+ };+ session.execute("occurrence.ground", &json!({"occurrence": occurrence(&session, "A").id, "grounded": true})).unwrap();+ session+ .execute("joint.create", &json!({"type": "rigid", "a": {"face": [5, 5, 10]}, "b": {"face": [25, 5, 0]}, "offset": 5, "name": "Seat"}))+ .unwrap();+ let seated = occurrence(&session, "B").transform;+ // A's box moves along, and B, seated on it, with it.+ session.execute("component.activate", &json!({"component": "A"})).unwrap();+ let a = component(&session, "A");+ let body = session.model.state().bodies.iter().find(|b| b.component == a).map(|b| b.name.clone()).unwrap();+ session.execute("solid.move", &json!({"bodies": [body], "translate": [30, 0, 0]})).unwrap();+ let moved = occurrence(&session, "B").transform;+ assert_ne!(moved, seated, "B follows the box it is seated on");+ let original = session.scratch();+ session.execute("timeline.roll_to", &json!({"position": 2})).unwrap();+ let source = session.scratch();+ assert_eq!(occurrence(&session, "B").transform, seated, "before the move, B sits where the box was");+ let prepared = session.scratch().compute_editor_commands(&[], &source, original).unwrap();+ session.accept_commands(prepared).unwrap();+ assert_eq!(session.doc.marker, None);+ assert_eq!(occurrence(&session, "B").transform, moved);+}diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex e4581a0ccc..802cd1c3d5 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -1961,6 +1961,23 @@ impl Session {}let mut expected = (*original.doc).clone();expected.marker = source.doc.marker;+ // Rolling the marker solves the joints again and stores where that puts each occurrence.+ if expected.occurrences.len() == source.doc.occurrences.len() {+ for (e, s) in expected.occurrences.iter_mut().zip(&source.doc.occurrences) {+ if e.id == s.id {+ e.transform = s.transform;+ }+ }+ }+ // ...and works out each coupled joint's ratio and lift from the faces at that marker.+ if expected.assembly.links.len() == source.doc.assembly.links.len() {+ for (e, s) in expected.assembly.links.iter_mut().zip(&source.doc.assembly.links) {+ if (e.a, e.ia, e.b, e.ib) == (s.a, s.ia, s.b, s.ib) {+ e.ratio = s.ratio;+ e.lift = s.lift.clone();+ }+ }+ }if expected != *source.doc {return Err(EngineError::Other("the original editor model does not match its source design".into()));}