Skip to content

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

Extrude: a sketch picked in the Browser or History takes all its profiles (#6106) (#6154)

rlartotdfdad35d08c8
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index afa33ccfd7..7a8b6acff6 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -2170,6 +2170,16 @@ fn dialog_takes_body(app: &SolveApp) -> bool {
app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::BODIES != 0)
}
+/// A plain click on a sketch (a Browser row or a History item) while Extrude, Revolve or Emboss
+/// is open gives the dialog every profile of that sketch (#6106). False when it is not one: the
+/// click then selects as usual.
+pub(crate) fn pick_sketch_into_dialog(app: &mut SolveApp, id: u64) -> bool {
+ let Some(mut d) = app.dialog.take() else { return false };
+ let taken = d.pick_sketch(&app.session, id);
+ app.dialog = Some(d);
+ taken
+}
+
/// Browser picks go only into compatible active dialog inputs. Outside a dialog, planes and
/// axes become the selection; body rows use the ordinary Ctrl/Shift-aware selection path.
fn pick_from_browser(app: &mut SolveApp, x: Sel) {
@@ -2860,6 +2870,12 @@ fn entry_row(
}
pick_from_browser(app, s);
}
+ } else if folder == "sketches"
+ && !ui.input(|i| i.modifiers.any())
+ && let Some(Sel::Feature { id }) = e.sel
+ && pick_sketch_into_dialog(app, id)
+ {
+ // Extrude, Revolve or Emboss took all the sketch's profiles (#6106).
} else {
click_select(app, ui, e.row_key.clone(), e.sel.clone());
}
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index dfebd3f98c..76632b0ce5 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -1593,6 +1593,35 @@ impl Dialog {
self.restore_value_focus = true;
}
+ /// A sketch clicked in the Browser or the History while Extrude, Revolve or Emboss is open
+ /// (#6106): Profiles takes every profile of the sketch, as when the sketch is selected before
+ /// the command starts. The island inside another profile's hole is left out, or it would fill
+ /// the hole. False when the click is not one of those (the caller selects it as usual).
+ pub fn pick_sketch(&mut self, s: &Session, id: u64) -> bool {
+ if self.active != 0
+ || !matches!(self.kind, Kind::Extrude { .. } | Kind::Revolve { .. } | Kind::Emboss { .. })
+ || !self.inputs.first().is_some_and(|i| i.accept & PROFILES != 0)
+ || !s.doc.feature(id).is_some_and(|f| matches!(f.kind, FeatureKind::Sketch { .. }))
+ {
+ return false;
+ }
+ let profiles: Vec<Sel> = s
+ .world_state()
+ .sketch(id)
+ .map(|ss| outermost_profiles(&ss.profiles).map(|index| Sel::Profile { sketch: id, index }).collect())
+ .unwrap_or_default();
+ let Some(input) = self.inputs.first_mut() else { return false };
+ if profiles.is_empty() {
+ return false;
+ }
+ input.items = profiles;
+ self.profile_selection_changed = true;
+ self.focus = true;
+ self.error = None;
+ self.sync_thread(s);
+ true
+ }
+
/// A pick in the viewport (already accepted by the active input).
pub fn pick(&mut self, s: &Session, sel: Sel) {
if self.take_extrude_target(s, &sel) {
@@ -1771,6 +1800,19 @@ fn fillet_edges(s: &Session, sel: &Sel, chain: bool) -> Vec<Sel> {
picked
}
+/// The profiles of a sketch that aren't the island inside another profile's hole: a circle in a
+/// rectangle gives the rectangle-with-hole and the disc, and taking both would fill the hole.
+/// Loops are compared as sets of curve ids, so where a loop starts or which way it runs doesn't matter.
+fn outermost_profiles(profiles: &[solidcraft_engine::sketch::Profile]) -> impl Iterator<Item = usize> + '_ {
+ let key = |ids: &[String]| {
+ let mut v = ids.to_vec();
+ v.sort();
+ v
+ };
+ let holes: Vec<Vec<String>> = profiles.iter().flat_map(|p| p.hole_curves.iter().map(|h| key(h))).collect();
+ (0..profiles.len()).filter(move |&i| profiles.get(i).is_some_and(|p| !holes.contains(&key(&p.outer_curves))))
+}
+
/// Profiles of the sketch a feature would use, when there is just one: the active sketch's, else
/// the last sketch's while no feature builds from it yet. A used profile (a cube's sketch on its
/// bottom face) is only taken when it is picked.
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs
index 87cbe13570..88a510baad 100644
--- a/crates/ui-egui/src/preselect_tests.rs
+++ b/crates/ui-egui/src/preselect_tests.rs
@@ -2957,3 +2957,30 @@ fn construction_points_fill_three_point_plane_dialog() {
assert!((planes[0].2.origin.z - 10.0).abs() < 1e-9);
assert!(planes[0].2.normal().dot(Vec3::Z).abs() > 1.0 - 1e-9);
}
+
+/// #6106: with Extrude open, a sketch clicked in the Browser fills Profiles with all of its
+/// profiles, so one OK extrudes every area.
+#[test]
+fn extrude_takes_every_profile_of_a_sketch_clicked_in_the_browser() {
+ let mut h = crate::scenario::Harness::new();
+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [20, 10]})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [40, 0], "p1": [50, 10]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
+ h.app.run("sketch.circle.center", json!({"center": [0, 40], "radius": 5})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.session.selection.clear();
+ h.app.start("solid.extrude");
+ h.frames(2);
+ h.step(&json!({"click": {"browser": "Sketch1"}})).unwrap();
+ h.frames(2);
+ let d = h.app.dialog.as_ref().expect("Extrude stays open");
+ let first =
+ h.app.session.doc.features.iter().find(|f| matches!(f.kind, solidcraft_engine::doc::FeatureKind::Sketch { .. })).map(|f| f.id).unwrap();
+ assert_eq!(
+ d.inputs[0].items,
+ vec![Sel::Profile { sketch: first, index: 0 }, Sel::Profile { sketch: first, index: 1 }],
+ "both rectangles of the clicked sketch, not the last sketch's circle"
+ );
+}
diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs
index d7a421e74f..d78b5840f1 100644
--- a/crates/ui-egui/src/timeline.rs
+++ b/crates/ui-egui/src/timeline.rs
@@ -999,6 +999,8 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {
select_range(app, &order, *id, modifiers.command || modifiers.ctrl);
} else if modifiers.command || modifiers.ctrl {
toggle_feature(app, *id);
+ } else if !modifiers.any() && crate::browser::pick_sketch_into_dialog(app, *id) {
+ // Extrude, Revolve or Emboss took every profile of the sketch (#6106).
} else {
select_one(app, *id);
}