Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sheet metal: a cut leaves sheets it cannot reach untouched without a check (#10301)

kaltenbrunnermarkusa0ec7dbdf069
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index e560d2c0b2..24c2b4b4a0 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -3212,10 +3212,25 @@ fn apply_traced_with(
return Ok(());
}
if matches!(op, Operation::Cut | Operation::Intersect) {
+ // A cut that cannot reach a sheet leaves it as it is (#10226): a sheet whose box lies
+ // clear of every tool's, in its own frame, needs no boolean to show it. An intersect
+ // removes the sheets it misses, and checks each one as before.
+ let mut reach: Option<Vec<Option<solidcraft_geom::Aabb3>>> = None;
for &i in &target_idx {
if let Some(mb) = state.bodies.get(i).filter(|b| state.sheets.iter().any(|s| s.body == b.name)) {
let m = tool_frame(&mb.name);
+ if op == Operation::Cut && m.is_none() && !mb.body.is_mesh() && !tools.iter().any(|t| t.body.is_mesh()) {
+ let reach = reach.get_or_insert_with(|| tools.iter().map(|t| more::body_box(&t.body)).collect());
+ if !reach.is_empty()
+ && let Some(target) = more::mesh_box(mb)
+ && reach.iter().all(|tool| more::boxes_apart(&Some(target), tool))
+ {
+ continue;
+ }
+ }
let bodies: Vec<Body> = tools.iter().map(|t| tool_in(t, m).map(|t| t.body)).collect::<Result<_>>()?;
+ #[cfg(test)]
+ cost_tests::count(|c| c.cut += 1);
sheet_boolean_unchanged(&mb.body, &bodies, op)?;
}
}
diff --git a/crates/doc/src/eval_cost_tests.rs b/crates/doc/src/eval_cost_tests.rs
index 7cbaa0025d..027bfd7bc4 100644
--- a/crates/doc/src/eval_cost_tests.rs
+++ b/crates/doc/src/eval_cost_tests.rs
@@ -1344,3 +1344,34 @@ fn a_tap_marking_still_searches_the_bodies_within_its_reach() {
assert_eq!(threads[0].internal, internal);
}
}
+
+/// A flat sheet of the default rule (2.5 mm steel) on a `w` x `h` rectangle from `corner` on XY.
+fn flat_sheet(doc: &mut Document, corner: Vec2, w: f64, h: f64) {
+ let mut sk = Sketch::new();
+ let p = [corner, corner + Vec2::new(w, 0.0), corner + Vec2::new(w, h), corner + Vec2::new(0.0, h)].map(|q| sk.add_point(q, None).unwrap());
+ for k in 0..4 {
+ sk.add_line_pts(p[k], p[(k + 1) % 4], None).unwrap();
+ }
+ let sketch = doc.add_feature(FeatureKind::Sketch { plane: PlaneRef::Origin { name: "XY".into() }, sketch: sk }, None).unwrap();
+ doc.add_feature(FeatureKind::SheetBase { sketch: SketchId(sketch), profiles: ProfileSel::All, rule: None, flip: false }, None).unwrap();
+}
+
+/// The sheet metal bodies of a model.
+fn sheet_bodies(model: &Model) -> Vec<String> {
+ model.state().sheets.iter().map(|s| s.body.clone()).collect()
+}
+
+/// A cut leaves the sheets it cannot reach as they were, without checking that it would leave
+/// each one unchanged (#10226).
+#[test]
+fn a_cut_leaves_sheets_it_cannot_reach_as_they_were() {
+ let mut doc = Document::new("far sheets");
+ for i in 0..5 {
+ flat_sheet(&mut doc, Vec2::new(200.0 * i as f64, 0.0), 150.0, 100.0);
+ }
+ block(&mut doc, "Plate", Vec3::new(0.0, -200.0, 0.0), [60.0, 60.0, 12.0]);
+ let work = cut_work(&mut doc, cutter(Vec3::new(30.0, -170.0, -1.0), 3.0, 20.0));
+ assert_eq!(work.cut, 1, "only the plate goes through a boolean");
+ assert_eq!(work.kept, sheet_bodies(&work.model), "every sheet is left as it was");
+ assert!(volume(&work.model, "Plate") < 43_200.0 - 300.0, "and the plate is cut");
+}