Skip to content

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

Extrude: picking a face, vertex or parallel plane off the profile switches the extent to To Object (#2855)

Diogo Soares Rodrigues1ed394f8d6ec
diff --git a/assets/locales/en.json b/assets/locales/en.json
index 89346efff1..e06f293751 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -1822,6 +1822,8 @@
"ui.extract_design_changed": "The design changed while choosing a file. Start Extract to File again.",
"ui.extract_done": "The component is now its own design, linked here.",
"ui.extrude": "Extrude",
+ "ui.extrude_auto_to_object": "Extrude to a picked target",
+ "ui.extrude_auto_to_object_tip": "In Extrude, with a profile picked, picking a face, vertex or parallel plane off its plane switches the extent to To Object",
"ui.factor": "Factor",
"ui.feature_history": "Feature history",
"ui.feature_options": "Feature Options",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index f7ac2c22e9..e23187eb0c 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -1822,6 +1822,8 @@
"ui.extract_design_changed": "ファイルの選択中にデザインが変更されました。ファイルへの抽出をやり直してください。",
"ui.extract_done": "コンポーネントは独立したデザインになり、ここにリンクされました。",
"ui.extrude": "押し出し",
+ "ui.extrude_auto_to_object": "選択した対象まで押し出し",
+ "ui.extrude_auto_to_object_tip": "押し出しでプロファイルを選択した後、その平面外の面・頂点・平行な平面を選ぶと、範囲タイプが「オブジェクトまで」に切り替わります",
"ui.factor": "倍率",
"ui.feature_history": "フィーチャー履歴",
"ui.feature_options": "フィーチャーオプション",
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index 10b2344004..78bd0be6a7 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -1822,6 +1822,8 @@
"ui.extract_design_changed": "选择文件时设计已更改。请重新开始提取到文件。",
"ui.extract_done": "该组件现在是独立的设计,并已在此处链接。",
"ui.extrude": "拉伸",
+ "ui.extrude_auto_to_object": "拉伸到所选目标",
+ "ui.extrude_auto_to_object_tip": "在拉伸中选择轮廓后,选取其平面外的面、顶点或平行平面会将延伸类型切换为“到对象”",
"ui.factor": "系数",
"ui.feature_history": "特征历史",
"ui.feature_options": "特征选项",
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 736606537c..188ce822ce 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -624,7 +624,7 @@ impl Dialog {
direction: 0,
operation: usize::from(has_bodies),
auto_op: true,
- smart: Default::default(),
+ smart: crate::smart_extrude::Smart { auto_to_object: app.preferences.extrude_auto_to_object, ..Default::default() },
distance2: "10 mm".into(),
taper: "0 deg".into(),
taper_present: false,
@@ -1135,6 +1135,9 @@ impl Dialog {
if matches!(self.kind, Kind::SketchModify(_)) {
return crate::sketch_modify_ui::candidate(self, s, h);
}
+ if let Some(target) = self.extrude_target(s, h) {
+ return Some(target);
+ }
let inp = self.active_input()?;
// Features are also picked on the canvas: a face stands for the feature that made it.
if inp.accept == selection::FEATURES {
@@ -1153,8 +1156,67 @@ impl Dialog {
inp.accepts(h, |body, face| snap.and_then(|f| f.planar(body, face)).unwrap_or_else(|| planar_face(s, body, face).is_some()))
}
+ /// Extrude's automatic To Object: with profiles picked, a face or vertex off their plane, or
+ /// a plane parallel to it, is the object to extrude to rather than another profile. While the
+ /// To Object input is active, a parallel plane is taken too (as a place on it).
+ fn extrude_target(&self, s: &Session, h: &Hit) -> Option<Sel> {
+ if !matches!(self.kind, Kind::Extrude { thin: false, smart: crate::smart_extrude::Smart { auto_to_object: true, .. }, .. }) {
+ return None;
+ }
+ let to_active = self.active_input().is_some_and(|i| i.label == TO_OBJECT);
+ if self.active != 0 && !to_active {
+ return None;
+ }
+ let reference = profile_plane(s, self.inputs.first()?.items.first()?)?;
+ let sel = match h {
+ // A place on the plane: its origin (a browser pick carries no point).
+ Hit::Plane { name, .. } => {
+ let plane = plane_by_name(s, name)?;
+ if plane.normal().dot(reference.normal()).abs() < 1.0 - 1e-9 {
+ return None;
+ }
+ Sel::Vertex { body: String::new(), point: plane.origin }
+ }
+ _ if to_active => return None,
+ Hit::Face { body, index, point } => Sel::Face { body: body.clone(), index: *index, point: *point },
+ Hit::Vertex { body, point } => Sel::Vertex { body: body.clone(), point: *point },
+ _ => return None,
+ };
+ object_target(s, &reference, &sel).then_some(sel)
+ }
+
+ /// Take a pick as the extrude's To Object (see [`Dialog::extrude_target`]): the extent turns to
+ /// To Object with it. False when the pick is not one.
+ fn take_extrude_target(&mut self, s: &Session, sel: &Sel) -> bool {
+ if self.active != 0
+ || !matches!(self.kind, Kind::Extrude { thin: false, smart: crate::smart_extrude::Smart { auto_to_object: true, .. }, .. })
+ {
+ return false;
+ }
+ let Some(reference) = self.inputs.first().and_then(|i| i.items.first()).and_then(|first| profile_plane(s, first)) else { return false };
+ if !object_target(s, &reference, sel) {
+ return false;
+ }
+ set_to_object(&mut self.inputs, &mut self.active, true);
+ let Some(at) = self.inputs.iter().position(|i| i.label == TO_OBJECT) else { return false };
+ if let Some(input) = self.inputs.get_mut(at) {
+ input.items = vec![sel.clone()];
+ }
+ self.active = at;
+ if let Kind::Extrude { all, .. } = &mut self.kind {
+ *all = false;
+ }
+ 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) {
+ return;
+ }
if let Some(key) = feature_pattern_reference_key(self, self.active) {
self.extra.remove(key);
}
@@ -2219,6 +2281,38 @@ pub(crate) fn shown_distance(r: &Value, show: Option<Shown>) -> Option<(Shown, f
show.and_then(get).or_else(|| get(default)).or_else(|| get(Shown::Min))
}
+/// A new To Object target of a new extrude sets the distance to how far it is, so the length
+/// shows and stays when the extent goes back to Distance.
+fn sync_reach(app: &SolveApp, d: &mut Dialog) {
+ let Kind::Extrude { smart, start, to_offset, .. } = &d.kind else { return };
+ if !smart.auto_to_object {
+ return;
+ }
+ let target = d.inputs.iter().find(|i| i.label == TO_OBJECT).and_then(|i| i.items.first()).cloned();
+ if smart.target == target {
+ return;
+ }
+ // A start offset, a To offset or a From Object move the ends: the distance stays as it is.
+ let plain = d.editing.is_none() && start.trim().is_empty() && to_offset.trim().is_empty() && !object_on(&d.inputs, FROM_OBJECT);
+ // Picks and the profiles' plane are both in world space.
+ let reach = match &target {
+ Some(Sel::Face { point, .. } | Sel::Vertex { point, .. }) if plain => {
+ d.inputs.first().and_then(|i| i.items.first()).and_then(|first| profile_plane(&app.session, first)).map(|plane| plane.height(*point))
+ }
+ _ => None,
+ };
+ let Kind::Extrude { smart, distance, direction, .. } = &mut d.kind else { return };
+ smart.target = target;
+ if let Some(reach) = reach.filter(|r| r.is_finite() && r.abs() > 1e-9) {
+ let text = format!("{:.6}", reach.abs());
+ *distance = format!("{} mm", text.trim_end_matches('0').trim_end_matches('.'));
+ // The side the target is on, for when the extent goes back to Distance.
+ if *direction < 2 {
+ *direction = usize::from(reach < 0.0);
+ }
+ }
+}
+
/// Smart Extrude (#1257, see [`crate::smart_extrude`]): a new pick sets the direction from the
/// side it was picked from, and the automatic operation follows the geometry, latched per side.
fn auto_operation(app: &SolveApp, d: &mut Dialog) {
@@ -2297,6 +2391,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
{
return;
}
+ sync_reach(app, &mut d);
auto_operation(app, &mut d);
d.sync_thread(&app.session);
update_measure(app, &mut d);
@@ -2671,6 +2766,33 @@ fn set_object(inputs: &mut Vec<SelInput>, active: &mut usize, label: &'static st
}
}
+/// The plane an extrude's picked profiles lie in: the first pick's sketch plane, or its planar face.
+fn profile_plane(s: &Session, first: &Sel) -> Option<solidcraft_engine::geom::Plane> {
+ let st = s.world_state();
+ match first {
+ Sel::Profile { sketch, .. } => st.sketch(*sketch).map(|ss| ss.plane),
+ Sel::Face { body, index, .. } => st.body(body)?.body.planar_face(*index),
+ _ => None,
+ }
+}
+
+/// Is a pick an object to extrude to from profiles in `reference` (not one more profile)? A face
+/// is unless it is planar and in that plane; a vertex or a place is unless it lies in it.
+fn object_target(s: &Session, reference: &solidcraft_engine::geom::Plane, sel: &Sel) -> bool {
+ const TOLERANCE: f64 = 1e-6;
+ match sel {
+ Sel::Face { body, index, .. } => {
+ let st = s.world_state();
+ let Some(b) = st.body(body) else { return false };
+ b.body
+ .planar_face(*index)
+ .is_none_or(|face| reference.normal().dot(face.normal()).abs() < 1.0 - 1e-9 || reference.height(face.origin).abs() > TOLERANCE)
+ }
+ Sel::Vertex { point, .. } => reference.height(*point).abs() > TOLERANCE,
+ _ => false,
+ }
+}
+
/// The picked To Object place.
fn to_object_point(inputs: &[SelInput]) -> Option<Value> {
object_point(inputs, TO_OBJECT)
@@ -2858,7 +2980,7 @@ pub fn start_sketch(app: &mut SolveApp, sel: &Sel) -> Result<(), String> {
/// behind the plane's normal, the in-plane axis to turn the plane about (`"x"` or `"y"`), chosen
/// so the sketch's y axis stays as upright on screen as it can (x then runs to the right).
fn flip_toward_viewer(app: &SolveApp, name: &str) -> Option<&'static str> {
- let plane = plane_by_name(app, name)?;
+ let plane = plane_by_name(&app.session, name)?;
let n = plane.normal();
// Where the eye is: in perspective its position, in orthographic only its direction counts.
let side = if app.cam.fov > 0.0 { (app.cam.eye() - plane.origin).dot(n) } else { app.cam.basis().2.dot(n) };
@@ -2884,15 +3006,21 @@ fn shown_origin_plane(app: &SolveApp, name: &str) -> Option<Value> {
}
/// The world plane of an origin plane or a construction plane by name, where it is shown.
-fn plane_by_name(app: &SolveApp, name: &str) -> Option<solidcraft_engine::geom::Plane> {
+fn plane_by_name(s: &Session, name: &str) -> Option<solidcraft_engine::geom::Plane> {
if let Some(p) = solidcraft_engine::geom::Plane::named(name) {
return Some(p);
}
- let st = app.session.world_state();
- st.construct.iter().find(|c| c.name == name).and_then(|c| match &c.geom {
- solidcraft_engine::doc::construct::ConstructGeom::Plane(pl) => Some(*pl),
- _ => None,
- })
+ let st = s.world_state();
+ st.construct
+ .iter()
+ .find(|c| c.name == name)
+ .and_then(|c| match &c.geom {
+ solidcraft_engine::doc::construct::ConstructGeom::Plane(pl) => Some(*pl),
+ _ => None,
+ })
+ // With occurrences the world state leaves construction geometry out; the viewport's
+ // planes are evaluated in place.
+ .or_else(|| solidcraft_engine::view::construction_planes(s).into_iter().find(|(_, n, _)| n == name).map(|(_, _, pl)| pl))
}
/// Animate the camera to look straight at the active sketch plane.
@@ -4239,7 +4367,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
},
operation: op_index(operation),
auto_op: false,
- smart: crate::smart_extrude::Smart { manual_dir: true, ..Default::default() },
+ smart: crate::smart_extrude::Smart { manual_dir: true, auto_to_object: app.preferences.extrude_auto_to_object, ..Default::default() },
distance2: extent.distance2.as_deref().map(str::to_string).unwrap_or_else(|| "10 mm".into()),
taper: extent.taper.as_deref().map(str::to_string).unwrap_or_else(|| "0 deg".into()),
taper_present: extent.taper.is_some(),
diff --git a/crates/ui-egui/src/extrude_auto_to_object_tests.rs b/crates/ui-egui/src/extrude_auto_to_object_tests.rs
new file mode 100644
index 0000000000..d1f894b64c
--- /dev/null
+++ b/crates/ui-egui/src/extrude_auto_to_object_tests.rs
@@ -0,0 +1,196 @@
+//! Extrude's automatic To Object: with profiles picked, a pick off their plane is the object to
+//! extrude to, and the extent turns to To Object without the Extent Type choice.
+use serde_json::json;
+use solidcraft_engine::Sel;
+use solidcraft_engine::geom::Vec3;
+
+use crate::dialogs::{Dialog, Kind, apply_commands, face_sel};
+use crate::scenario::Harness;
+use crate::viewport::Hit;
+
+/// A 10 x 10 profile on XY, a 20 mm box beside it (x 30..50), a cylinder further on (x 65..75)
+/// and construction planes 25 mm above and 12.345678 mm below XY; the Extrude dialog open with
+/// the profile picked and the automatic To Object preference on.
+fn scene() -> Harness {
+ scene_with(true)
+}
+
+fn scene_with(auto_to_object: bool) -> Harness {
+ let mut h = Harness::new();
+ h.app.preferences.extrude_auto_to_object = auto_to_object;
+ h.app.run("solid.box", json!({"length": 20, "width": 20, "height": 20, "corner": [30, 0, 0]})).unwrap();
+ h.app.run("solid.cylinder", json!({"radius": 5, "height": 30, "base": [70, 10, 0], "operation": "new_body"})).unwrap();
+ h.app.run("construct.plane.offset", json!({"base": "XY", "offset": 25, "name": "Lid"})).unwrap();
+ h.app.run("construct.plane.offset", json!({"base": "XY", "offset": -12.345678, "name": "Under"})).unwrap();
+ h.app.run("sketch.create", json!({"plane": "XY", "name": "Base"})).unwrap();
+ h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [10, 10]})).unwrap();
+ h.app.run("sketch.finish", json!({})).unwrap();
+ h.app.start("solid.extrude");
+ h.frames(2);
+ let sketch = h.app.session.doc.find_feature("Base").unwrap().id;
+ let d = h.app.dialog.as_mut().unwrap();
+ d.inputs[0].items = vec![Sel::Profile { sketch, index: 0 }];
+ d.active = 0;
+ h.frames(2);
+ h
+}
+
+fn dialog(h: &Harness) -> &Dialog {
+ h.app.dialog.as_ref().unwrap()
+}
+
+/// A click on `hit` as the viewport makes it: the dialog's candidate, then its pick.
+fn click(h: &mut Harness, hit: impl FnOnce(&Harness) -> Hit) -> bool {
+ let hit = hit(h);
+ let mut d = h.app.dialog.take().unwrap();
+ let sel = d.candidate(&h.app.session, &hit);
+ if let Some(sel) = sel.clone() {
+ d.pick(&h.app.session, sel);
+ }
+ h.app.dialog = Some(d);
+ h.frames(2);
+ sel.is_some()
+}
+
+fn face_hit(h: &Harness, p: Vec3) -> Hit {
+ let Some(Sel::Face { body, index, point }) = face_sel(&h.app.session, p) else { panic!("no face at {p:?}") };
+ Hit::Face { body, index, point }
+}
+
+fn to_object(d: &Dialog) -> Option<&Sel> {
+ d.inputs.iter().find(|i| i.label == "To Object").and_then(|i| i.items.first())
+}
+
+fn distance(d: &Dialog) -> String {
+ let Kind::Extrude { distance, .. } = &d.kind else { panic!("extrude") };
+ distance.clone()
+}
+
+#[test]
+fn face_off_the_profile_plane_turns_the_extent_to_that_face() {
+ let mut h = scene();
+ assert!(to_object(dialog(&h)).is_none(), "Distance first");
+ assert!(click(&mut h, |h| face_hit(h, Vec3::new(40.0, 10.0, 20.0))));
+ let d = dialog(&h);
+ assert!(matches!(to_object(d), Some(Sel::Face { .. })));
+ assert_eq!(d.inputs[0].items.len(), 1, "the profile stays the only profile");
+ assert_eq!(d.active, 1, "the To Object input is active");
+ assert_eq!(distance(d), "20 mm", "the length is the target's");
+ let commands = apply_commands(&h.app, d).unwrap();
+ let params = &commands[0].1;
+ assert!(params.get("to").is_some());
+ let reach = solidcraft_engine::extrude_reach(&h.app.session, params).unwrap();
+ assert!((reach - 20.0).abs() < 1e-9, "{reach}");
+ // OK builds the extrude up to the face.
+ h.step(&json!({"widget": "OK"})).unwrap();
+ h.frames(4);
+ let state = h.app.session.world_state();
+ let volume: f64 = state.bodies.iter().filter_map(|b| solidcraft_engine::doc::kernel::measure(&b.body).ok()).map(|m| m.volume).sum();
+ // The box, the cylinder and the 10 x 10 x 20 extrude.
+ let expected = 8000.0 + std::f64::consts::PI * 25.0 * 30.0 + 2000.0;
+ assert!((volume - expected).abs() < 1.0, "{volume}");
+}
+
+#[test]
+fn coplanar_face_stays_a_profile() {
+ let mut h = scene();
+ assert!(click(&mut h, |h| face_hit(h, Vec3::new(40.0, 10.0, 0.0))));
+ let d = dialog(&h);
+ assert!(to_object(d).is_none());
+ assert_eq!(d.inputs[0].items.len(), 2, "the bottom face joins the profiles");
+ assert_eq!(distance(d), "10 mm");
+}
+
+#[test]
+fn vertex_and_curved_face_are_targets() {
+ let mut h = scene();
+ // A vertex in the profile plane is not something to go to.
+ assert!(!click(&mut h, |h| Hit::Vertex { body: dialog_body(h), point: Vec3::new(50.0, 20.0, 0.0) }));
+ assert!(to_object(dialog(&h)).is_none());
+ assert!(click(&mut h, |h| Hit::Vertex { body: dialog_body(h), point: Vec3::new(50.0, 20.0, 20.0) }));
+ assert!(matches!(to_object(dialog(&h)), Some(Sel::Vertex { .. })));
+
+ let mut h = scene();
+ assert!(click(&mut h, curved_hit));
+ assert!(matches!(to_object(dialog(&h)), Some(Sel::Face { .. })));
+}
+
+/// The cylinder's side, at the middle of one of its triangles.
+fn curved_hit(h: &Harness) -> Hit {
+ let st = h.app.session.world_state();
+ for b in &st.bodies {
+ let m = b.mesh();
+ for (t, f) in m.triangles.iter().zip(&m.tri_face) {
+ let Some([p, q, r]) = m.tri(t) else { continue };
+ if b.body.planar_face(*f as usize).is_none() {
+ return Hit::Face { body: b.name.clone(), index: *f as usize, point: (p + q + r) * (1.0 / 3.0) };
+ }
+ }
+ }
+ panic!("no curved face")
+}
+
+fn dialog_body(h: &Harness) -> String {
+ h.app.session.world_state().bodies.first().unwrap().name.clone()
+}
+
+#[test]
+fn parallel_construction_plane_is_a_target_and_a_crossing_one_is_not() {
+ let mut h = scene();
+ assert!(!click(&mut h, |_| Hit::Plane { name: "YZ".into(), point: Vec3::new(0.0, 5.0, 5.0) }));
+ assert!(to_object(dialog(&h)).is_none());
+ assert!(click(&mut h, |_| Hit::Plane { name: "Lid".into(), point: Vec3::new(5.0, 5.0, 25.0) }));
+ let d = dialog(&h);
+ assert!(matches!(to_object(d), Some(Sel::Vertex { body, .. }) if body.is_empty()));
+ assert_eq!(distance(d), "25 mm");
+ // The profile plane itself is nowhere to go: the target stays.
+ assert!(!click(&mut h, |_| Hit::Plane { name: "XY".into(), point: Vec3::new(5.0, 5.0, 0.0) }));
+ assert!(matches!(to_object(dialog(&h)), Some(Sel::Vertex { point, .. }) if (point.z - 25.0).abs() < 1e-9));
+}
+
+#[test]
+fn without_profiles_a_face_is_a_profile() {
+ let mut h = scene();
+ h.app.dialog.as_mut().unwrap().inputs[0].items.clear();
+ assert!(click(&mut h, |h| face_hit(h, Vec3::new(40.0, 10.0, 20.0))));
+ let d = dialog(&h);
+ assert!(to_object(d).is_none());
+ assert!(matches!(d.inputs[0].items.as_slice(), [Sel::Face { .. }]));
+}
+
+#[test]
+fn thin_extrude_keeps_its_picks() {
+ let mut h = scene();
+ if let Some(Kind::Extrude { thin, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
+ *thin = true;
+ }
+ click(&mut h, |h| face_hit(h, Vec3::new(40.0, 10.0, 20.0)));
+ assert!(to_object(dialog(&h)).is_none());
+}
+
+#[test]
+fn target_below_keeps_its_side_and_exact_length() {
+ let mut h = scene();
+ // As the browser picks a plane: no place on it.
+ assert!(click(&mut h, |_| Hit::Plane { name: "Under".into(), point: Vec3::ZERO }));
+ let d = dialog(&h);
+ assert!(matches!(to_object(d), Some(Sel::Vertex { point, .. }) if (point.z + 12.345678).abs() < 1e-9));
+ assert_eq!(distance(d), "12.345678 mm");
+ assert!(matches!(d.kind, Kind::Extrude { direction: 1, .. }), "the target is below the profile");
+}
+
+#[test]
+fn off_by_default_a_face_off_the_profile_plane_joins_the_profiles() {
+ let h = Harness::new();
+ assert!(!h.app.preferences.extrude_auto_to_object, "the preference starts off");
+ let mut h = scene_with(false);
+ assert!(click(&mut h, |h| face_hit(h, Vec3::new(40.0, 10.0, 20.0))));
+ let d = dialog(&h);
+ assert!(to_object(d).is_none(), "the extent stays Distance");
+ assert_eq!(d.inputs[0].items.len(), 2, "the top face joins the profiles, as before");
+ assert_eq!(distance(d), "10 mm");
+ // A parallel construction plane is not taken as a target either.
+ let mut h = scene_with(false);
+ assert!(!click(&mut h, |_| Hit::Plane { name: "Lid".into(), point: Vec3::new(5.0, 5.0, 25.0) }));
+ assert!(to_object(dialog(&h)).is_none());
+}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 1f93bda841..9286f44e79 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -138,6 +138,8 @@ mod status_tests {
mod apply_off_thread_tests;
mod expression_complete;
#[cfg(test)]
+mod extrude_auto_to_object_tests;
+#[cfg(test)]
mod extrude_edit_tests;
mod extrude_preview;
mod file_load;
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index e06ccbd5ad..85ff372b07 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -535,6 +535,9 @@ preference_settings! {
up_axis: String = "z".into(), PAGE_DESIGN;
/// After a STEP or IGES file opens, offer to stand a Y-up part up (`stand_up`).
offer_stand_up: bool = true, PAGE_DESIGN => check("Offer to stand up Y-up files", "After a STEP or IGES file opens with Z up, offer a quarter turn about X");
+ /// Extrude: with a profile picked, a face, vertex or parallel plane picked off its plane
+ /// switches the extent to To Object (off: picks only add profiles, as before).
+ extrude_auto_to_object: bool = false, PAGE_DESIGN => check("Extrude to a picked target", "In Extrude, with a profile picked, picking a face, vertex or parallel plane off its plane switches the extent to To Object");
/// What a middle-button double-click in the view does: `home`, `fit` or `off`.
middle_double_click: String = "home".into(), PAGE_NAVIGATION;
/// Colour vision mode (#778): `off`, `protan`, `deutan` or `tritan`.
diff --git a/crates/ui-egui/src/prefs/design.rs b/crates/ui-egui/src/prefs/design.rs
index 40acab12c2..b41a982e20 100644
--- a/crates/ui-egui/src/prefs/design.rs
+++ b/crates/ui-egui/src/prefs/design.rs
@@ -51,5 +51,6 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
);
setting::offer_stand_up(app, ui);
ui_kit::text(ui, app.tr("prefs.stand_up_note"), ui_kit::Text::Hint("stand_up"));
+ setting::extrude_auto_to_object(app, ui);
});
}
diff --git a/crates/ui-egui/src/smart_extrude.rs b/crates/ui-egui/src/smart_extrude.rs
index 47b4cace29..03c31cd260 100644
--- a/crates/ui-egui/src/smart_extrude.rs
+++ b/crates/ui-egui/src/smart_extrude.rs
@@ -26,6 +26,10 @@ pub struct Smart {
pub manual_dir: bool,
/// The automatic operation (an index into the operations) and the side it was chosen for.
pub latch: Option<(usize, i8)>,
+ /// The To Object target the distance was last set from.
+ pub target: Option<Sel>,
+ /// Picks off the profile plane become the To Object target (Preferences › Design).
+ pub auto_to_object: bool,
}
/// One-side direction for a new pick: 0 (along the normal) or 1 (reversed). `ray` is the view
diff --git a/docs/book/src/guide/features.md b/docs/book/src/guide/features.md
index 6d91b167bb..2ce1718a6a 100644
--- a/docs/book/src/guide/features.md
+++ b/docs/book/src/guide/features.md
@@ -18,6 +18,15 @@ Extruding into existing material selects **Cut**. In an empty component it selec
choose **New Body** explicitly to keep an addition separate. Changing the default does not alter
operations already saved in a design.
+**Extrude to a picked target** (Preferences › Design, off by default) lets a pick choose the
+extent. With it on and a profile selected in the solid Extrude dialog, picking a face away from
+its plane, a curved face, an off-plane vertex or a parallel plane automatically switches
+**Distance** to **To Object**. Coplanar faces still join the profile selection; non-parallel
+planes are not targets. The extent can still be chosen manually. For a new extrusion without
+start or end offsets or a From Object input, the target also sets the stored distance and
+one-sided direction, so returning to **Distance** keeps that reach. Thin Extrude keeps its
+existing picks. With the setting off, picks only add profiles, as before.
+
A taper slopes the sides of any profile, sketch text included: lines, arcs and spline or conic
curves move in or out together, and a flat tip shorter than the taper closes to a point. On
spline and conic sides the slope is approximate: the moved outline is a curve of the same kind
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 359f6ea445..def9c3b1be 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -229,7 +229,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
| `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs |
| `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) |
| `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text |
-| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` |
+| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` |
| `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits |
| `ui.window` | `action`: minimize, maximize, restore, toggle, close | what the title bar's caption buttons do (on Windows and Linux the application bar is the title bar); close asks about unsaved designs first |
| `ui.agent_cursor` | `show` (bool), `speed`: a number from 1 to 5 (times the normal speed) or `"instant"` (no animation: the command runs at once and the pointer jumps to where it acted), `follow_camera` (bool); all optional | the settings. While the cursor is shown, `engine.execute` first glides to the command's toolbar button and to each pick, then runs and replies; later requests wait their turn. It also follows the pointer input sent with `ui.move`, `ui.click`, `ui.drag` and `ui.scroll`, as each event reaches the app, and a press leaves a ripple. `"animate": false` on a call skips it |