diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index ee5a46b5f..cac9943ad 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -6421,13 +6421,38 @@ fn replay(
}
}
if op == Operation::Cut {
- for instance in instances {
- if let Some(tools) = copies.get(instance) {
+ for instance in &instances {
+ if let Some(tools) = copies.get(instance.clone()) {
total += 1;
missed += usize::from(copy_misses(st, f, &targets, tools));
}
}
}
+ // Copies of a cut through sheet metal are cut-outs of its flat pattern, as the cut is
+ // (#6841): each machined into the sheets in turn, then cut from the other targets.
+ if op == Operation::Cut && matches!(src.kind, FeatureKind::Extrude { .. }) && !st.sheets.is_empty() && instances.len() == mats.len() {
+ let mut handled = Vec::with_capacity(mats.len());
+ for (m, instance) in mats.iter().zip(&instances) {
+ let bodies: Vec
= copies.get(instance.clone()).unwrap_or_default().iter().map(|t| t.body.clone()).collect();
+ handled.push(more::sheet_cut_copy(f, src, m, st, &bodies, &targets, warning)?);
+ }
+ if handled.iter().any(|h| !h.is_empty()) {
+ // Copies the same sheets took are cut from the rest at once.
+ let mut groups: Vec<(Vec, Vec)> = Vec::new();
+ let mut rest = copies.into_iter();
+ for (done, instance) in handled.into_iter().zip(&instances) {
+ let tools: Vec = rest.by_ref().take(instance.len()).collect();
+ match groups.iter_mut().find(|(d, _)| *d == done) {
+ Some((_, all)) => all.extend(tools),
+ None => groups.push((done, tools)),
+ }
+ }
+ for (done, tools) in groups {
+ apply_beside_sheet_cut(doc, st, f, tools, op, &targets, &done)?;
+ }
+ continue;
+ }
+ }
// New bodies from a pattern join their source when they touch it (as one feature would).
if f.body_names.is_empty() {
apply_traced(doc, st, f, copies, op, &targets)?;
diff --git a/crates/doc/src/eval_more.rs b/crates/doc/src/eval_more.rs
index 12b84ca81..6e3748490 100644
--- a/crates/doc/src/eval_more.rs
+++ b/crates/doc/src/eval_more.rs
@@ -933,13 +933,61 @@ pub(super) fn sheet_cut(
constructor: Option<&ExtrudeConstructor>,
warning: &mut Option,
) -> Result> {
- let FeatureKind::Extrude { sketch, profiles, operation, extent, .. } = &f.kind else { return Ok(Vec::new()) };
- if extent.taper.is_some() || !any_eligible_sheet(f, st, targets) {
+ if !any_eligible_sheet(f, st, targets) {
return Ok(Vec::new());
}
- let Some(ss) = st.sketch(sketch.0).cloned() else { return Ok(Vec::new()) };
- let regions = solidcraft_sketch::merge_regions(&select_profiles(&ss, profiles)?);
- // The outlines of the sketch's text: the sheet remembers where its letters went.
+ let Some(cut) = extrude_cut(st, f)? else { return Ok(Vec::new()) };
+ sheet_prism_cut(f, st, &cut.plane, &cut.regions, cut.operation, tools, targets, constructor, cut.bound, &cut.text, warning)
+}
+
+/// A copy of the extrude cut `src` that the pattern `f` makes, moved by `m`: machined into the
+/// sheets as the cut itself is, in the moved sketch plane (#6841). `tools` are the copy's. Only
+/// for a cut moved without turning over: a mirrored copy, and any other feature, comes back
+/// unhandled (no sheets) for the caller to apply as before.
+pub(super) fn sheet_cut_copy(
+ f: &Feature,
+ src: &Feature,
+ m: &Mat,
+ st: &mut ModelState,
+ tools: &[Body],
+ targets: &[String],
+ warning: &mut Option,
+) -> Result> {
+ if !any_eligible_sheet(f, st, targets) {
+ return Ok(Vec::new());
+ }
+ let Some(cut) = extrude_cut(st, src)? else { return Ok(Vec::new()) };
+ if cut.operation != Operation::Cut {
+ return Ok(Vec::new());
+ }
+ let (x, y) = (crate::apply_vector(m, cut.plane.x), crate::apply_vector(m, cut.plane.y));
+ if x.cross(y).dot(crate::apply_vector(m, cut.plane.normal())) <= 0.0 {
+ return Ok(Vec::new());
+ }
+ let Some(plane) = Plane::new(apply_point(m, cut.plane.origin), x, y) else { return Ok(Vec::new()) };
+ sheet_prism_cut(f, st, &plane, &cut.regions, cut.operation, tools, targets, None, cut.bound, &cut.text, warning)
+}
+
+/// What an untapered extrude cut (or intersect) machines into a sheet.
+struct ExtrudeCut {
+ plane: Plane,
+ regions: Vec,
+ /// The outlines of the sketch's text: the sheet remembers where its letters went.
+ text: Vec,
+ operation: Operation,
+ /// Up to a face: the tools' own footprints bound it.
+ bound: bool,
+}
+
+/// The sketch plane, regions and text of `f`'s extrude; None for any other feature, a tapered
+/// extrude or a missing sketch.
+fn extrude_cut(st: &ModelState, f: &Feature) -> Result