diff --git a/crates/doc/src/face_anchor.rs b/crates/doc/src/face_anchor.rs index d32f962c1..4f502b1ae 100644 --- a/crates/doc/src/face_anchor.rs +++ b/crates/doc/src/face_anchor.rs @@ -211,8 +211,16 @@ impl Document { let indices = self.configuration_face_indices(body, &target)?; // A copy a pattern or mirror made on the same body carries its seed's certificate, // which finds the seed's face: the copy is attached by its own history name below. + // A face that is no copy, on the plane of the pieces the certificate finds, is + // another piece of that face (a piece a later join left bordering another body, + // and named after it): the certificate stands for it too (#9465). if !indices.contains(&index) { - return Err(DocError::Invalid("this face has no supported construction certificate; choose a fixed plane instead".into())); + let names = crate::naming::names(body); + let copy = names.faces.get(index).is_none_or(|name| crate::persistent_name::is_copy(name)); + let all: Vec = indices.iter().copied().chain([index]).collect(); + if copy || self.coplanar_pieces(body, &all, |_| true).is_err() { + return Err(DocError::Invalid("this face has no supported construction certificate; choose a fixed plane instead".into())); + } } self.coplanar_pieces(body, &indices, |_| true)?; Ok(target) diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rs index f6d195c99..4b8b2795b 100644 --- a/crates/engine/src/cmd/sketch_face_tests.rs +++ b/crates/engine/src/cmd/sketch_face_tests.rs @@ -792,3 +792,32 @@ fn a_sketch_on_the_mirrored_half_of_a_combined_body_sits_on_that_half() { assert!((plane.origin - point).dot(normal).abs() < 1e-6, "{name}: origin {:?}", plane.origin); } } +/// The sensor enclosure's lid rests on the case, and its lip, joined below it, parts its underside +/// into a ring and a panel. The ring is named after the case's top it rests on, so the lid's cap +/// certificate finds only the panel: the ring is another piece of the same face and takes a sketch +/// attached by that certificate, as it did before #8278 (#9465, nightly action matrix). +#[test] +fn a_sketch_on_the_ring_of_a_lid_underside_parted_by_its_lip_keeps_the_cap() { + let mut s = Session::default(); + let script: Value = serde_json::from_str(include_str!("../../../../examples/acceptance/sensor_enclosure.json")).unwrap(); + s.run_script(&script).unwrap(); + let world = s.world_state(); + let lid = world.body("Lid").unwrap(); + let names = solidcraft_doc::naming::face_names(lid); + let down: Vec = (0..names.len()) + .filter(|index| lid.body.planar_face(*index).is_some_and(|plane| plane.normal().dot(-Vec3::Z) > 0.999 && (plane.origin.z - 25.).abs() < 1e-6)) + .collect(); + assert!(down.len() > 1, "the lip parts the lid's underside: {down:?}"); + let ring = *down.iter().find(|index| names[**index] == "F2:top").unwrap_or_else(|| panic!("the ring, among {names:?}")); + let pick = json!({"body":"Lid","index":ring,"face":[12.0, 29.266_666_666_665, 25.0]}); + drop(world); + let id = run(&mut s, "sketch.create", json!({"name":"On ring","plane":pick,"project_edges":false}))["sketch"].as_u64().unwrap(); + run(&mut s, "sketch.finish", json!({})); + let plane = s.model.state().sketch(id).unwrap().plane; + assert!(plane.normal().dot(-Vec3::Z) > 0.999 && (plane.origin.z - 25.).abs() < 1e-6, "{plane:?}"); + // The attachment survives an edit that widens the lid. + run(&mut s, "parameters.change", json!({"name": "board_w", "expression": "(60 mm) * 1.1"})); + assert!(timeline_errors(&s).is_empty(), "{:?}", timeline_errors(&s)); + let plane = s.model.state().sketch(id).unwrap().plane; + assert!(plane.normal().dot(-Vec3::Z) > 0.999 && (plane.origin.z - 25.).abs() < 1e-6, "{plane:?}"); +}