SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch: the Fix constraint accepts a box selection that includes dimensions (#11663) (#11671)
thocsmith7139ee9d20b5
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rsindex 45c553b42f..0a9a210e3c 100644--- a/crates/ui-egui/src/preselect_tests.rs+++ b/crates/ui-egui/src/preselect_tests.rs@@ -3796,3 +3796,66 @@ fn shell_lists_the_faces_its_chip_counts() {assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![back]);assert!(h.widget("1 selected").is_some());}++/// #11663: Fix started with only points selected (no curve to fix them through) gives each of+/// them its own Fix constraint, so a selection of loose points is not silently dropped.+#[test]+fn fix_takes_a_selection_of_only_points() {+ let mut h = crate::scenario::Harness::new();+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.app.run("sketch.point", json!({"point": [10, 10]})).unwrap();+ h.app.run("sketch.point", json!({"point": [30, 20]})).unwrap();+ let sid = h.app.session.active_sketch.unwrap();+ let ids: Vec<String> = h.app.session.doc.sketch(sid).unwrap().points.iter().skip(1).map(|p| p.id.clone()).collect();+ assert_eq!(ids.len(), 2, "two loose points to select");+ let fixes = |h: &crate::scenario::Harness| h.app.session.doc.sketch(sid).unwrap().constraints.iter().filter(|c| c.kind.name() == "Fix").count();+ let before = fixes(&h);+ h.app.session.selection = ids.iter().map(|id| Sel::SketchPoint { id: id.clone() }).collect();+ h.app.start("sketch.constraint.fix");+ assert_eq!(fixes(&h), before + 2, "each selected point got a Fix constraint ({:?})", h.app.status);+ assert!(h.app.tool.is_none(), "Fix applied at once, no pick tool left running");+}++/// #11663: a curve of another sketch is named by its sketch, and its bare id could be a curve of+/// the active one; Fix leaves such a selection to the pick tool and changes nothing.+#[test]+fn fix_leaves_a_curve_of_another_sketch_to_the_pick_tool() {+ let mut h = crate::scenario::Harness::new();+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.app.run("sketch.line", json!({"points": [[0, 0], [20, 2]], "infer": false, "connect": false})).unwrap();+ let sid = h.app.session.active_sketch.unwrap();+ h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into(), sketch: Some(sid + 1000) }];+ h.app.start("sketch.constraint.fix");+ assert!(h.app.tool.is_some(), "the pick tool is left to ask ({:?})", h.app.status);+ let sk = h.app.session.doc.sketch(sid).unwrap();+ assert!(sk.curves.iter().all(|c| !c.fixed), "the active sketch's l1 was not fixed by a bare id");+}++/// #11663: a box drawn over a sketch takes its dimensions and constraint icons along with its+/// lines and points. Fix started with that selection fixes the lines and points; it does not fall+/// back to the pick tool. Hundreds of entities (more than the 200 a constraint pick takes) too.+#[test]+fn fix_takes_a_boxed_selection_with_its_dimensions_and_hundreds_of_entities() {+ for lines in [3, 110] {+ let mut h = crate::scenario::Harness::new();+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ for i in 0..lines {+ let y = 5 * i;+ h.app.run("sketch.line", json!({"points": [[0, y], [20, y + 2]], "infer": false, "connect": false})).unwrap();+ }+ h.app.run("sketch.dimension", json!({"entities": ["l1"], "value": "21 mm"})).unwrap();+ let sid = h.app.session.active_sketch.unwrap();+ let sk = h.app.session.doc.sketch(sid).unwrap();+ let mut selection: Vec<Sel> = sk.curves.iter().map(|c| Sel::SketchCurve { id: c.id.clone(), sketch: None }).collect();+ selection.extend(sk.points.iter().skip(1).map(|p| Sel::SketchPoint { id: p.id.clone() }));+ selection.extend(sk.constraints.iter().map(|c| Sel::SketchConstraint { id: c.id.clone() }));+ assert!(selection.iter().any(|s| matches!(s, Sel::SketchConstraint { .. })), "the box holds the dimension");+ h.app.session.selection = selection;+ h.app.start("sketch.constraint.fix");+ let sk = h.app.session.doc.sketch(sid).unwrap();+ let loose: Vec<&str> = sk.curves.iter().filter(|c| !c.fixed).map(|c| c.id.as_str()).collect();+ assert!(loose.is_empty(), "{lines} lines: not fixed {loose:?} ({:?})", h.app.status);+ assert!(h.app.tool.is_none(), "{lines} lines: Fix applied at once, no pick tool left running");+ assert!(h.app.session.selection.is_empty(), "{lines} lines: the selection is used up");+ }+}diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rsindex 4fe9b1bb0b..e3b6ac3af6 100644--- a/crates/ui-egui/src/tools.rs+++ b/crates/ui-egui/src/tools.rs@@ -732,7 +732,7 @@ pub(crate) fn constraint_preselection((unique.len() == ids.len()).then_some(ids)};match (command, selection) {- ("sketch.constraint.fix", _) => selected_ids(false, 1).map(|ids| json!({"entities":ids})),+ ("sketch.constraint.fix", _) => fix_preselection(selection).map(|ids| json!({"entities":ids})),("sketch.constraint.polygon", _) => selected_ids(true, 3).map(|ids| json!({"lines":ids})),// Three or more curves: all of them equal, in pick order (#4985). Two keep the `a, b` form.("sketch.constraint.equal", _) if selection.len() >= 3 => selected_ids(true, 3).map(|ids| json!({"curves":ids})),@@ -772,6 +772,30 @@ pub(crate) fn constraint_preselection(}}+/// The sketch points and curves Fix takes from a selection (#11663). A box drawn over a sketch+/// also takes its dimensions and constraint icons; those cannot be fixed and are passed over, so+/// the geometry boxed with them is still fixed at once. Anything else selected (a body, a+/// midpoint, a curve of another sketch) leaves the choice to the pick tool. As many entities as the command takes.+fn fix_preselection(selection: &[solidcraft_engine::Sel]) -> Option<Vec<&str>> {+ use solidcraft_engine::Sel::{SketchConstraint, SketchCurve, SketchPoint};+ const MAX_ENTITIES: usize = 10_000;+ let mut ids = Vec::new();+ let mut seen = std::collections::BTreeSet::new();+ for s in selection {+ let id = match s {+ SketchCurve { id, sketch: None } | SketchPoint { id } => id.as_str(),+ // A curve of another sketch: its id alone would name a curve of this one (#3726).+ SketchCurve { .. } => return None,+ SketchConstraint { .. } => continue,+ _ => return None,+ };+ if seen.insert(id) {+ ids.push(id);+ }+ }+ (1..=MAX_ENTITIES).contains(&ids.len()).then_some(ids)+}+pub(crate) fn projection_preselection(selection: &[solidcraft_engine::Sel]) -> Option<Vec<Value>> {use solidcraft_engine::Sel;// The projection command processes at most 1000 references; never consume a subset.