Skip to content

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

Sketch: Intersect can pick sketch lines (#10484) (#10512)

kaltenbrunnermarkus2a410c2d76f1
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 0cf27ab749..4a3ff51cc8 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -99,6 +99,9 @@ const EXTRUDE_ACCEPT: Accept = PROFILES | PLANAR_FACES;
const THIN_ACCEPT: Accept = PROFILES | CURVES;
const PROJECT_GEOMETRY: Accept =
EDGES | FACES | selection::VERTICES | PLANES | AXES | selection::SKETCH_LINES | selection::EXTERNAL_POINTS | selection::ORIGIN;
+/// What Intersect cuts with the sketch plane, picked one by one: faces, model edges and the
+/// curves of other sketches (#10484); an edge or a sketch line gives the points where it crosses.
+const INTERSECT_GEOMETRY: Accept = EDGES | FACES | selection::SKETCH_LINES;
const HOLE_TYPES: [&str; 3] = ["simple", "counterbore", "countersink"];
const HOLE_LABELS: [&str; 3] = ["Simple", "Counterbore", "Countersink"];
@@ -819,7 +822,7 @@ impl Dialog {
let bodies = s.selection.iter().any(|sel| matches!(sel, Sel::Body { .. }));
Dialog::new(
Kind::SketchIntersect { bodies, projection_link: true },
- vec![SelInput::new("ui.sketch_intersect_geometry", if bodies { BODIES } else { FACES }, true)],
+ vec![SelInput::new("ui.sketch_intersect_geometry", if bodies { BODIES } else { INTERSECT_GEOMETRY }, true)],
)
}
"sketch.project" => {
@@ -5108,13 +5111,15 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
Kind::Rename { feature, name } => ("timeline.rename", json!({"feature": feature, "name": name})),
Kind::ConfirmDelete { features, groups, .. } => ("timeline.delete", crate::timeline::delete_params(features, groups)),
Kind::SketchIntersect { projection_link, .. } => {
- need(0, "faces or bodies")?;
+ need(0, "geometry or bodies")?;
let refs = sels(d, 0)
.iter()
.map(|sel| match sel {
Sel::Body { name } => Ok(json!({"body": name})),
Sel::Face { body, point, .. } => Ok(json!({"face": [point.x, point.y, point.z], "body": body})),
- _ => Err("select faces or bodies".to_string()),
+ Sel::Edge { body, point, .. } => Ok(json!({"edge": [point.x, point.y, point.z], "body": body})),
+ Sel::ExternalSketchCurve { sketch, id } => Ok(json!({"sketch": sketch, "curve": id})),
+ _ => Err("select geometry or bodies".to_string()),
})
.collect::<Result<Vec<_>, _>>()?;
("sketch.intersect", json!({"refs": refs, "projection_link": projection_link}))
diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs
index 9262a62024..9ec672b859 100644
--- a/crates/ui-egui/src/dialogs_dense.rs
+++ b/crates/ui-egui/src/dialogs_dense.rs
@@ -219,11 +219,11 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
Kind::SketchIntersect { bodies, projection_link } => {
let mut selected = if *bodies { 1 } else { 0 };
let changed = ui_kit::row(ui, tr("ui.sketch_intersect_selection_filter"), |ui| {
- ui_kit::segmented(ui, &mut selected, &[tr("Faces"), tr("Bodies")], Default::default())
+ ui_kit::segmented(ui, &mut selected, &[tr("Geometry"), tr("Bodies")], Default::default())
});
if changed && let Some(input) = d.inputs.first_mut() {
*bodies = selected == 1;
- input.accept = if *bodies { BODIES } else { FACES };
+ input.accept = if *bodies { BODIES } else { super::INTERSECT_GEOMETRY };
input.items.clear();
}
ui_kit::row(ui, tr("ui.sketch_intersect_projection_link"), |ui| ui_kit::checkbox(ui, "", projection_link));
diff --git a/crates/ui-egui/src/dialogs_sketch_tests.rs b/crates/ui-egui/src/dialogs_sketch_tests.rs
index fb9ad5766f..545b94b2ac 100644
--- a/crates/ui-egui/src/dialogs_sketch_tests.rs
+++ b/crates/ui-egui/src/dialogs_sketch_tests.rs
@@ -186,7 +186,7 @@ fn create_sketch_uses_card_and_still_starts_immediately_on_plane_pick() {
}
#[test]
-fn intersect_dialog_filters_faces_or_whole_bodies_and_controls_projection_link() {
+fn intersect_dialog_filters_geometry_or_whole_bodies_and_controls_projection_link() {
let mut h = Harness::new();
h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Post"})).unwrap();
h.app.run("sketch.create", json!({"plane":"XY","offset":10})).unwrap();
@@ -199,13 +199,14 @@ fn intersect_dialog_filters_faces_or_whole_bodies_and_controls_projection_link()
assert_eq!(d.inputs[0].accept, super::BODIES);
assert_eq!(d.inputs[0].items, vec![Sel::Body { name: "Post".into() }]);
assert!(scenario::rect_of("dialog:row:ui.sketch_intersect_geometry").is_some());
- assert!(scenario::handle_at("dialog:Selection Filter:Faces").is_some());
- assert!(scenario::handle_at("dialog:Selection Filter:Bodies").is_some());
+ assert!(scenario::handle_at("dialog:Selection Filter").is_some());
assert!(scenario::rect_of("dialog:row:Projection Link").is_some());
- h.step(&json!({"click":{"handle":"dialog:Selection Filter:Faces"}})).unwrap();
- assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].accept, super::FACES);
+ h.step(&json!({"click":{"handle":"dialog:Selection Filter"}})).unwrap();
+ h.step(&json!({"click":{"handle":"dialog:Selection Filter:Geometry"}})).unwrap();
+ assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].accept, super::INTERSECT_GEOMETRY);
assert!(h.app.dialog.as_ref().unwrap().inputs[0].items.is_empty());
+ h.step(&json!({"click":{"handle":"dialog:Selection Filter"}})).unwrap();
h.step(&json!({"click":{"handle":"dialog:Selection Filter:Bodies"}})).unwrap();
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].accept, super::BODIES);
h.step(&json!({"click":{"handle":"dialog:Projection Link"}})).unwrap();
@@ -217,6 +218,45 @@ fn intersect_dialog_filters_faces_or_whole_bodies_and_controls_projection_link()
}
let d = h.app.dialog.as_ref().unwrap();
assert_eq!(apply_commands(&h.app, d).unwrap(), vec![("sketch.intersect".into(), json!({"refs":[{"body":"Post"}],"projection_link":false}))]);
+ // A model edge is cut with the plane too (#10484).
+ let d = h.app.dialog.as_mut().unwrap();
+ d.inputs[0].items = vec![Sel::Edge { body: "Post".into(), index: 0, point: solidcraft_engine::geom::Vec3::new(0.0, 0.0, 10.0) }];
+ let cmds = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(cmds, vec![("sketch.intersect".into(), json!({"refs":[{"edge":[0.0,0.0,10.0],"body":"Post"}],"projection_link":false}))]);
+}
+
+/// Intersect takes the lines of another sketch (#10484): a rectangle on XY, a sketch on a plane
+/// across it, and a click on one of the rectangle's sides gives the point where it crosses.
+#[test]
+fn intersect_dialog_takes_a_line_of_another_sketch() {
+ let mut h = Harness::new();
+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[40,30]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ let rectangle = h.app.session.doc.features.last().unwrap().id;
+ h.app.run("sketch.create", json!({"plane":"YZ","offset":20})).unwrap();
+ h.app.run("view.home", json!({})).unwrap();
+ h.app.start("sketch.intersect");
+ h.settle();
+ let d = h.app.dialog.as_ref().expect("Intersect opens an options dialog");
+ assert!(matches!(d.kind, Kind::SketchIntersect { bodies: false, .. }));
+ assert_eq!(d.inputs[0].accept, super::INTERSECT_GEOMETRY);
+
+ h.step(&json!({"click":{"world":[10,0,0]}})).unwrap();
+ let d = h.app.dialog.as_ref().unwrap();
+ let [Sel::ExternalSketchCurve { sketch, id }] = d.inputs[0].items.as_slice() else { panic!("the side is picked: {:?}", d.inputs[0].items) };
+ assert_eq!(*sketch, rectangle);
+ let cmds = apply_commands(&h.app, d).unwrap();
+ assert_eq!(cmds, vec![("sketch.intersect".into(), json!({"refs":[{"sketch":rectangle,"curve":id}],"projection_link":true}))]);
+ h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap();
+ h.settle();
+ assert!(h.app.dialog.is_none());
+ let state = h.app.session.world_state();
+ let sk = state.sketch(h.app.session.active_sketch.unwrap()).unwrap();
+ let link = &sk.sketch.links[0].id;
+ let at: Vec<_> = sk.sketch.link_points(link).iter().filter_map(|p| sk.sketch.point(*p)).map(|p| sk.plane.to_world(p)).collect();
+ assert_eq!(at.len(), 1, "{at:?}");
+ assert!(at[0].dist(solidcraft_engine::geom::Vec3::new(20.0, 0.0, 0.0)) < 1e-6, "{at:?}");
}
#[test]
diff --git a/crates/ui-egui/src/sketch_tools.rs b/crates/ui-egui/src/sketch_tools.rs
index 5d0a21cced..b7c4b79264 100644
--- a/crates/ui-egui/src/sketch_tools.rs
+++ b/crates/ui-egui/src/sketch_tools.rs
@@ -792,7 +792,7 @@ pub fn hint(id: &str) -> Option<String> {
Some(
match id {
"sketch.project" => "Project: click edges, faces, vertices, other sketches' curves, axes or planes",
- "sketch.intersect" => "Intersect: click faces or edges to cut with the sketch plane",
+ "sketch.intersect" => "Intersect: click faces, edges or other sketches' curves to cut with the sketch plane",
"sketch.include_3d" => "Include 3D Geometry: click edges or vertices",
"sketch.fit_curves_to_section" => "Fit Curves to Mesh Section: click a body",
"sketch.isoparametric_curve" => "Isoparametric Curve: click a point on a face (Shift: along)",