Skip to content

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

Sheet metal: a base or contour flange hides its sketch (#6804) (#7151)

sascha2101f5bfd6d1f298
diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rs
index 640b478c11..faaab35f05 100644
--- a/crates/engine/src/cmd/browser.rs
+++ b/crates/engine/src/cmd/browser.rs
@@ -1620,6 +1620,33 @@ mod tests {
assert!(s.visibility.hidden_bodies.is_empty());
}
+ #[test]
+ fn a_sheet_metal_flange_hides_its_sketch_as_an_extrude_does() {
+ // #6804: the base flange's sketch stayed shown; its line on the plate's bottom edge then
+ // took the Flange dialog's click and made a flat contour wall with no bend.
+ let mut s = Session::default();
+ let base = run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Base"}))["sketch"].as_u64().unwrap();
+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-33.5, -37], "p1": [27.5, -7]}));
+ run(&mut s, "sketch.finish", json!({}));
+ let wall = run(&mut s, "sketch.create", json!({"plane": "XZ", "name": "Wall"}))["sketch"].as_u64().unwrap();
+ run(&mut s, "sketch.line", json!({"points": [[0, 0], [40, 0], [40, 30]], "ids": ["l1", "l2"]}));
+ run(&mut s, "sketch.finish", json!({}));
+ assert!(crate::view::sketch_shown(&s, base) && crate::view::sketch_shown(&s, wall));
+ run(&mut s, "sheet.flange", json!({"sketch": "Base"}));
+ assert!(!crate::view::sketch_shown(&s, base), "the base flange used its sketch");
+ run(&mut s, "sheet.flange", json!({"sketch": "Wall", "curves": ["l1", "l2"], "distance": 20}));
+ assert!(!crate::view::sketch_shown(&s, wall), "the contour flange used its sketch");
+ let d = run(&mut s, "document.inspect", json!({}));
+ assert!(d["sketches"].as_array().unwrap().iter().all(|x| x["visible"] == false), "{d}");
+ assert_eq!(s.doc.features.iter().filter(|f| matches!(f.kind, solidcraft_doc::FeatureKind::SheetContour { .. })).count(), 1);
+ // Shown on their own, or while their flange is edited, they are drawn again.
+ s.feature_edit_sketch = Some(base);
+ assert!(crate::view::sketch_shown(&s, base));
+ s.feature_edit_sketch = None;
+ run(&mut s, "browser.visibility", json!({"items": [wall], "visible": true}));
+ assert!(crate::view::sketch_shown(&s, wall) && !crate::view::sketch_shown(&s, base));
+ }
+
#[test]
fn helper_sketches_hide_and_show() {
let mut s = Session::default();
diff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rs
index 58eba1f15a..48b42e69a5 100644
--- a/crates/engine/src/view.rs
+++ b/crates/engine/src/view.rs
@@ -848,10 +848,15 @@ fn sketch_component_visible(s: &Session, id: u64) -> bool {
s.occurrence_visible(&path)
}
-/// Is a sketch used by a later feature?
+/// Is a sketch used by a later feature? A sheet metal base or contour flange uses its sketch as
+/// an Extrude does: shown, its lines lie on the sheet's edges and take the clicks meant for
+/// them (#6804).
pub fn sketch_consumed(s: &Session, id: u64) -> bool {
use solidcraft_doc::FeatureKind;
- s.doc.features.iter().any(|f| matches!(f.kind, FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. } if sketch == id))
+ s.doc.features.iter().any(|f| {
+ matches!(f.kind, FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. }
+ | FeatureKind::SheetBase { sketch, .. } | FeatureKind::SheetContour { sketch, .. } if sketch == id)
+ })
}
/// Camera framing the model (iso view).
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 0d288fa605..398c7902c2 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -2716,12 +2716,15 @@ fn picked_side(app: &SolveApp, d: &Dialog, first: &Sel) -> Option<usize> {
Some(crate::smart_extrude::picked_direction(crate::smart_extrude::view_ray(&app.cam, at), normal, false))
}
-/// Show the sketch of the Extrude or Revolve the open dialog edits, and only while it is open:
-/// whichever way the dialog closed (OK, Cancel, another tool, another design), the sketch
-/// returns to its own visibility.
+/// Show the sketch of the Extrude, Revolve or sheet metal base or contour flange the open dialog
+/// edits, and only while it is open: whichever way the dialog closed (OK, Cancel, another tool,
+/// another design), the sketch returns to its own visibility.
pub(crate) fn sync_feature_edit_sketch(app: &mut SolveApp) {
app.session.feature_edit_sketch = app.dialog.as_ref().and_then(|d| d.editing).and_then(|(id, _)| match &app.session.doc.feature(id)?.kind {
- FeatureKind::Extrude { sketch, .. } | FeatureKind::Revolve { sketch, .. } => Some(**sketch),
+ FeatureKind::Extrude { sketch, .. }
+ | FeatureKind::Revolve { sketch, .. }
+ | FeatureKind::SheetBase { sketch, .. }
+ | FeatureKind::SheetContour { sketch, .. } => Some(**sketch),
_ => None,
});
}
diff --git a/crates/ui-egui/src/dialogs_sheet_tests.rs b/crates/ui-egui/src/dialogs_sheet_tests.rs
index a3c1c4260d..26b8630024 100644
--- a/crates/ui-egui/src/dialogs_sheet_tests.rs
+++ b/crates/ui-egui/src/dialogs_sheet_tests.rs
@@ -69,6 +69,29 @@ fn flange_follows_the_picks() {
}
}
+/// A click on the plate's bottom edge picks the edge, not the base flange's sketch line lying on
+/// it: the flange is an edge flange with a bend, not a flat contour wall (#6804).
+#[test]
+fn a_click_on_the_bottom_edge_makes_an_edge_flange() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.set_origin_shown(false);
+ h.app.run("sketch.create", json!({"plane": "XY", "name": "Base"})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [100, 60]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.run("sheet.flange", json!({"sketch": "Base"})).unwrap();
+ h.step(&json!({"call": "ui.view", "params": {"view": "front"}})).unwrap();
+ h.settle();
+ h.app.start("sheet.flange");
+ h.frames(3);
+ // The bottom edge lies on the sketch plane, under the sketch's line from (0, 0) to (100, 0).
+ let at = h.at(&json!({"world": [50, 0, 0]})).unwrap();
+ h.step(&json!({"click": at})).unwrap();
+ let items = h.app.dialog.as_ref().unwrap().inputs[0].items.clone();
+ assert!(matches!(items.as_slice(), [Sel::Edge { point, .. }] if point.z.abs() < 1e-9 && point.y.abs() < 1e-9), "{items:?}");
+ let c = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(c[0].1["type"], "edge", "{:?}", c[0].1);
+}
+
/// Hem takes edges and an optional gap; rules make and pick a rule with its expressions.
#[test]
fn hem_and_rules() {