Joints: the model is evaluated for the placements a solve leaves (#7084) (#7085)

Session::refresh evaluated the model and then solved the joints, which
writes the solved placements into the design. A feature that reads where
a part is placed kept the result made for the placement before the
solve: a mirror of a jointed part's body, made from the root, ended up
4 mm below the part after a move the slider took back.

When the solve moves parts, the model is now evaluated again for the
placements the design holds, and the joints solved for that model, at
most three rounds. Features that don't read placements come from the
cache.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
semmelrinde
2026-10-27 12:40:29 +00:00
committed by GitHub
parent 0f8593b180
commit ad749d3399
2 changed files with 47 additions and 1 deletions
+32
View File
@@ -301,6 +301,38 @@ fn faces_mate_by_default() {
assert!(near(place(&s, "B", Vec3::new(25.0, 5.0, 10.0)), Vec3::new(5.0, 5.0, 0.0)), "{:?}", place(&s, "B", Vec3::new(25.0, 5.0, 10.0)));
}
/// A move of a jointed part that the joint takes back: the model is evaluated for the
/// placements the solve leaves, so a mirror of the part's body, made from the root, is where a
/// fresh evaluation of the design puts it. The model was the one evaluated for the move before
/// the solve took it back, and its mirror didn't match the part.
#[test]
fn a_feature_reading_a_jointed_parts_placement_follows_the_solve() {
let mut s = Session::default();
for (cmd, p) in [
("component.create", json!({"grounded": true, "name": "Base"})),
("solid.box", json!({"corner": [-11, -25, 0], "height": 9, "length": 11, "width": 14})),
("component.create", json!({"grounded": false, "name": "Slide"})),
("solid.cylinder", json!({"base": [-2, -10, 7], "height": 7, "radius": 2})),
("component.activate", json!({"component": "root"})),
("joint.as_built", json!({"a": "Base:1", "b": "Slide:1", "name": "Rail", "type": "slider"})),
("solid.mirror", json!({"bodies": ["Body2"], "plane": "XY"})),
("occurrence.move", json!({"occurrence": "Slide:1", "translate": [-10, -18, 2]})),
] {
s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd}: {e}"));
}
let boxes = |st: &solidcraft_doc::ModelState| {
st.bodies
.iter()
.map(|b| (b.name.clone(), b.body.outline_bounds()))
.map(|(n, bb)| format!("{n} {:.6?} {:.6?}", bb.min, bb.max))
.collect::<Vec<_>>()
};
let mut fresh = solidcraft_doc::Model::new();
fresh.no_cache = true;
fresh.evaluate(&s.doc);
assert_eq!(boxes(&s.model.state()), boxes(&fresh.state()));
}
/// #1239: two parts as bodies of one component (a multi-body STEP import). The refusal names the
/// way out, and after Create Components from Bodies the same origins make the joint.
#[test]
+15 -1
View File
@@ -831,7 +831,21 @@ impl Session {
self.prune_occurrence_state();
// Joints follow the geometry their origins snap to.
if !self.doc.assembly.joints.is_empty() {
self.solve_joints();
// A solve that moves parts changes what features reading where a part is placed
// (a mirror of a placed body) make: the model is evaluated again for the placements
// the design now holds, and the joints solved for that model, a few times at most.
for _ in 0..3 {
let before = self.doc.clone();
self.solve_joints();
if Arc::ptr_eq(&before, &self.doc) || before.occurrences == self.doc.occurrences {
break;
}
self.model.evaluate(&self.doc);
#[cfg(test)]
{
self.evaluations += 1;
}
}
}
cmd::motion::associative::refresh(self);
if let Some(id) = self.active_sketch