SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Timeline: moving a construction axis now updates the features that use it (#9544) (#9545)
austin62jake3c1074cfc6ec
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex 25a49daf7e..803b18bf8a 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -659,7 +659,7 @@ impl ModelState {}/// A digest of everything later features can read: bodies (by content identity), sketches,- /// the body counter, threads and sheet bodies.+ /// the body counter, threads, sheet bodies and construction geometry.fn digest(&self) -> u64 {let mut h = std::collections::hash_map::DefaultHasher::new();for b in &self.bodies {@@ -701,6 +701,12 @@ impl ModelState {}serde_json::to_string(&self.threads).unwrap_or_default().hash(&mut h);serde_json::to_string(&self.sheets).unwrap_or_default().hash(&mut h);+ // Construction axes, planes and points so far: features find them here by name, and a+ // result taken from the cache brings back the ones it was made with, so one moved past+ // a feature must change the key (#9544). A state without any hashes as before.+ if !self.construct.is_empty() {+ serde_json::to_string(&self.construct).unwrap_or_default().hash(&mut h);+ }h.finish()}diff --git a/crates/engine/src/cmd/revolve_convention_tests.rs b/crates/engine/src/cmd/revolve_convention_tests.rsindex 3a395f6339..5a677507fa 100644--- a/crates/engine/src/cmd/revolve_convention_tests.rs+++ b/crates/engine/src/cmd/revolve_convention_tests.rs@@ -378,6 +378,29 @@ fn construction_axis_revolve_follows_the_axis() {assert!((volume(&s) - 80.0 * PI).abs() < 0.05, "{}", volume(&s));}+/// A revolve finds its construction axis among the features before it, so moving the axis+/// behind the revolve breaks it, and moving it back mends it, at once (#9544).+#[test]+fn construction_axis_moved_behind_its_revolve_and_back() {+ let mut s = Session::default();+ run(&mut s, "construct.axis.two_points", json!({"a":{"point":[0,0,0]},"b":{"point":[0,30,0]},"name":"Axis1"}));+ profile(&mut s, false);+ run(&mut s, "solid.revolve", json!({"sketch":"Profile","axis":"Axis1","angle":"180 deg","operation":"new","profiles":[0],"name":"Turn"}));+ let error = s.execute("timeline.reorder", &json!({"feature":"Axis1","position":2})).unwrap_err().to_string();+ assert!(error.contains("moving Axis1 there breaks Turn"), "{error}");+ assert_eq!(s.doc.features[0].name, "Axis1");+ let moved = run(&mut s, "timeline.reorder", json!({"feature":"Axis1","position":2,"allow_errors":true}));+ assert_eq!(moved["broken"][0]["feature"], "Turn", "{moved}");+ let turn = s.doc.find_feature("Turn").unwrap().id;+ let error = |s: &Session| s.model.result(turn).and_then(|r| r.error.clone());+ assert!(error(&s).is_some_and(|e| e.contains("Axis1")), "{:?}", error(&s));+ assert!(s.model.state().bodies.is_empty());+ // Moved back, the revolve finds its axis again.+ run(&mut s, "timeline.reorder", json!({"feature":"Axis1","position":0}));+ assert_eq!(error(&s), None);+ assert!((solidcraft_kernel::measure(&s.model.state().bodies[0].body).unwrap().volume - 60.0 * PI).abs() < 0.05);+}+#[test]fn construction_axis_revolve_rejects_invalid_axes_atomically() {for (a, b, message) in [diff --git a/crates/engine/src/cmd/sketch_project_tests.rs b/crates/engine/src/cmd/sketch_project_tests.rsindex 7d2bf069f9..b5bbcfa189 100644--- a/crates/engine/src/cmd/sketch_project_tests.rs+++ b/crates/engine/src/cmd/sketch_project_tests.rs@@ -251,13 +251,17 @@ fn a_construction_axis_projects_and_stays_linked() {let link = &state.sketch(sketch).unwrap().sketch.links[0];assert_eq!(link.source, solidcraft_sketch::LinkSource::Axis { name: "Hinge axis".into() });assert!(!link.lost, "renamed, the axis is still found");- // A design with the axis after the sketch opens with the link lost, saying why.+ // Moved after the sketch, the axis can't be found from it: the link is lost, saying why, at+ // once and when the design is opened again (#9544). Moved back, it is found again.run(&mut s, "timeline.reorder", json!({"feature": "Hinge axis", "position": 1}));let opened = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());- assert!(opened.model.state().sketch(sketch).unwrap().sketch.links[0].lost);- let warnings = opened.model.result(sketch).and_then(|r| r.warning.clone()).unwrap_or_default();- assert!(warnings.contains("it must come earlier in the timeline"), "{warnings}");+ for session in [&s, &opened] {+ assert!(session.model.state().sketch(sketch).unwrap().sketch.links[0].lost);+ let warnings = session.model.result(sketch).and_then(|r| r.warning.clone()).unwrap_or_default();+ assert!(warnings.contains("it must come earlier in the timeline"), "{warnings}");+ }run(&mut s, "timeline.reorder", json!({"feature": "Hinge axis", "position": 0}));+ assert!(!s.model.state().sketch(sketch).unwrap().sketch.links[0].lost);// An axis that is no origin axis and no construction axis is refused, by its name.run(&mut s, "sketch.edit", json!({"sketch": sketch}));let error = s.execute("sketch.project", &json!({"refs": [{"axis": "Axis9"}]})).unwrap_err().to_string();