SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sheet metal: refuse an edge flange on a bend line (#3234) (#3273)
rlartot95de388ba1f5
diff --git a/crates/doc/src/sheet.rs b/crates/doc/src/sheet.rsindex 15ba85342c..b4bfd40afe 100644--- a/crates/doc/src/sheet.rs+++ b/crates/doc/src/sheet.rs@@ -2320,6 +2320,25 @@ impl SheetBody {return Err(DocError::Invalid("pick an edge of the sheet's top or bottom face".into()));}let d = (b - a).normalized().ok_or_else(|| DocError::Invalid("edge".into()))?;+ // A bend line is no free edge: the base's or the parent panel's edge where a flange+ // starts, or the flange panel's edge where its bend ends.+ let outward = Vec2::new(d.y, -d.x);+ let on_bend = self.flanges.iter().enumerate().any(|(i, f)| {+ let (at, facing) = if panel == f.parent {+ (f.p, 1.0)+ } else if panel == Some(i) {+ (f.p + f.n * self.allowance(f), -1.0)+ } else {+ return false;+ };+ let along = |p: Vec2| p.dot(f.d);+ outward.dot(f.n) * facing > 0.99+ && (a - at).dot(f.n).abs() < 1e-6+ && along(a).max(along(b)).min(along(f.p) + f.len) - along(a).min(along(b)).max(along(f.p)) > 1e-6+ });+ if on_bend {+ return Err(DocError::Invalid(format!("{}that edge is the bend line of a flange; pick a free edge of the sheet", on(k))));+ }let (s0, s1) = self.edge_left(panel, a, b, e.pick, &cuts).ok_or_else(|| DocError::Invalid(format!("{}a cut-out has taken that edge away; pick an edge the sheet still has", on(k))))?;diff --git a/crates/engine/src/cmd/sheet_tests.rs b/crates/engine/src/cmd/sheet_tests.rsindex 334e3fd2e4..6db0520ab8 100644--- a/crates/engine/src/cmd/sheet_tests.rs+++ b/crates/engine/src/cmd/sheet_tests.rs@@ -1494,6 +1494,25 @@ fn an_edge_flange_on_a_flange_runs_along_what_a_flat_cut_left_of_its_far_edge()assert!(contains(&s, [130.0, 6.0, 42.0]) && !contains(&s, [30.0, 6.0, 42.0]));}+#[test]+fn an_edge_flange_is_refused_on_the_bend_line_of_a_flange() {+ // The flange's bend runs between the plate's edge (y = 5) and the panel's edge (y = 2.5,+ // z = 5). Either is a bend line, not a free edge: a flange there left a second flange with a+ // gap and a sheet of two shells.+ let mut s = Session::default();+ plate_with_flange(&mut s);+ let before = volume(&mut s);+ for pick in [[50.0, 5.0, 2.5], [50.0, 5.0, 0.0], [50.0, 2.5, 5.0], [50.0, 0.0, 5.0]] {+ let e = s.execute("sheet.flange", &json!({"edges": [pick], "height": 10}));+ assert!(e.as_ref().is_err_and(|e| e.to_string().contains("bend line")), "{pick:?}: {e:?}");+ assert!(rel(volume(&mut s), before) < 1e-9, "{pick:?} changed the sheet");+ }+ // A free edge still takes one, and the sheet stays in one piece.+ run(&mut s, "sheet.flange", json!({"edges": [[50, 60, 2.5]], "height": 10}));+ assert!(no_errors_or_warnings(&s), "{:?}", s.model.results);+ assert!(volume(&mut s) > before);+}+#[test]fn a_flange_bent_inside_keeps_the_base_sketchs_arcs_in_the_flat_pattern_and_the_dxf() {// A 200 x 100 plate with its corners rounded 8, drawn as arcs, and a 40 high flange on its