Skip to content

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

Resolve #159 against current sketch preselection

bherbruck78aa2aacfb7b
diff --cc crates/ui-egui/src/tools.rs
index 5c16b3647d,167c5af192..14d2aaae20
--- a/crates/ui-egui/src/tools.rs
+++ b/crates/ui-egui/src/tools.rs
@@@ -323,41 -323,6 +323,43 @@@ fn run_shape(app: &mut SolveApp, t: &To
Ok(result["curves"].as_array().into_iter().flatten().filter_map(|c| c.as_str().map(str::to_string)).collect())
}
+/// Only consume a complete, unambiguous selection; command validation owns geometry.
+pub(crate) fn constraint_preselection(command: &str, selection: &[solvecraft_engine::Sel]) -> Option<Value> {
+ use solvecraft_engine::Sel::{SketchCurve, SketchPoint};
+ match (command, selection) {
++ ("sketch.constraint.horizontal_vertical", [SketchCurve { id }]) => Some(json!({"line":id})),
++ ("sketch.constraint.horizontal_vertical", [SketchPoint { id: a }, SketchPoint { id: b }]) if a != b => Some(json!({"points":[a,b]})),
+ ("sketch.constraint.coincident", [a, b]) => {
+ let entity = |s: &solvecraft_engine::Sel| match s {
+ SketchPoint { id } | SketchCurve { id } => Some(id.clone()),
+ _ => None,
+ };
+ let (a, b) = (entity(a)?, entity(b)?);
+ (a != b).then(|| json!({"a":a,"b":b}))
+ }
+ (
+ "sketch.constraint.midpoint",
+ [SketchPoint { id: point }, SketchCurve { id: line }] | [SketchCurve { id: line }, SketchPoint { id: point }],
+ ) => Some(json!({"point":point,"line":line})),
+ ("sketch.constraint.symmetry", [a, b, c]) => {
+ let mut points = Vec::new();
+ let mut lines = Vec::new();
+ for entity in [a, b, c] {
+ match entity {
+ SketchPoint { id } => points.push(id),
+ SketchCurve { id } => lines.push(id),
+ _ => return None,
+ }
+ }
+ match (points.as_slice(), lines.as_slice()) {
+ ([a, b], [line]) if a != b => Some(json!({"a":a,"b":b,"line":line})),
+ _ => None,
+ }
+ }
+ _ => None,
+ }
+}
+
fn run_pick(app: &mut SolveApp, t: &Tool) {
let k = &t.picks;
let params = match t.cmd {
diff --cc docs/book/src/guide/sketching.md
index 298345846f,009f15ce17..08b0d0a1b1
--- a/docs/book/src/guide/sketching.md
+++ b/docs/book/src/guide/sketching.md
@@@ -91,11 -91,9 +91,14 @@@ midpoint, symmetry, fix, curvature (G2
aligned, horizontal, vertical, radius, diameter and angle dimensions. Each is a parameter
(`d1`, `d2`, …), so it can hold an expression.
+For **Coincident**, pick two points, a point and a curve (in either order), or two
+distinct straight lines. Two lines join their closest pair of endpoints; the first
+picked line stays in place when the existing constraints allow it. Pick endpoints
+explicitly when you want to connect a different pair.
+
+ Horizontal/Vertical also applies immediately to one selected line or two distinct selected
+ points. Shift-click to add the second point before choosing the constraint.
+
For Parallel, Perpendicular, Equal, Tangent, Concentric and Collinear, select exactly two
sketch curves (Shift-click to add the second) and choose the constraint to apply it immediately.
You can also start the constraint first and then pick its curves. An incomplete or mixed