Skip to content

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

Loft: a sketch point picked in the window is an apex (#4830) (#5207)

dudedagger4239951a22fff3
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 377d40c46f..d34d1a2743 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -801,7 +801,7 @@ impl Dialog {
),
"solid.loft" => Dialog::new(Kind::Loft { operation: usize::from(has_bodies), rail_fit: 0 }, {
let [rail, rail2] = crate::dialogs_sweep::rail_inputs();
- vec![SelInput::new("Profiles", PROFILES, true), rail, rail2]
+ vec![SelInput::new("Profiles", PROFILES | selection::POINTS, true), rail, rail2]
}),
"solid.sweep" => Dialog::new(Kind::Sweep { operation: usize::from(has_bodies), opts: crate::dialogs_sweep::SweepOpts::default() }, {
let [rail, rail2] = crate::dialogs_sweep::rail_inputs();
@@ -3693,20 +3693,33 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
}
Kind::Loft { operation, rail_fit } => {
need(0, "profiles of two or more sketches")?;
- // One section per sketch, in the order the sketches were first picked.
- let mut sections: Vec<(u64, Vec<usize>)> = Vec::new();
+ // One section per sketch, in the order the sketches were first picked; a sketch point
+ // is a section of its own, an apex the loft closes to (#4830).
+ let mut sections: Vec<(u64, Vec<usize>, Option<&str>)> = Vec::new();
for x in sels(d, 0) {
- if let Sel::Profile { sketch, index } = x {
- match sections.iter_mut().find(|(sk, _)| sk == sketch) {
- Some((_, v)) => v.push(*index),
- None => sections.push((*sketch, vec![*index])),
+ match x {
+ Sel::Profile { sketch, index } => match sections.iter_mut().find(|(sk, _, apex)| sk == sketch && apex.is_none()) {
+ Some((_, v, _)) => v.push(*index),
+ None => sections.push((*sketch, vec![*index], None)),
+ },
+ Sel::SketchPoint { id } => {
+ if let Some((sk, point)) = id.split_once(':').and_then(|(sk, point)| Some((sk.parse::<u64>().ok()?, point))) {
+ sections.push((sk, Vec::new(), Some(point)));
+ }
}
+ _ => {}
}
}
if sections.len() < 2 {
- return Err("pick profiles in two or more sketches".into());
- }
- let sections: Vec<Value> = sections.into_iter().map(|(sk, v)| json!({"sketch": sk, "profiles": v})).collect();
+ return Err("pick profiles in two or more sketches, or a profile and a sketch point".into());
+ }
+ let sections: Vec<Value> = sections
+ .into_iter()
+ .map(|(sk, v, apex)| match apex {
+ Some(point) => json!({"sketch": sk, "point": point}),
+ None => json!({"sketch": sk, "profiles": v}),
+ })
+ .collect();
let mut p = json!({"sections": sections, "operation": OPS.get(*operation).copied().unwrap_or("new")});
crate::dialogs_sweep::rail_params(app, *rail_fit, [sels(d, 1), sels(d, 2)], &mut p)?;
("solid.loft", p)
diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs
index b21acb7225..8009ed0418 100644
--- a/crates/ui-egui/src/preselect_tests.rs
+++ b/crates/ui-egui/src/preselect_tests.rs
@@ -2464,3 +2464,32 @@ fn face_then_revolve_turns_the_face() {
let want = std::f64::consts::PI * 40.0 * 40.0 * 20.0;
assert!((v - want).abs() < want * 1e-3, "{v} vs {want}");
}
+
+/// #4830: the Loft window takes a sketch point as an apex: a 20 × 20 square lofted to a point
+/// 30 above its middle is a pyramid of 20² · 30 / 3 = 4000 mm³.
+#[test]
+fn a_loft_from_a_profile_to_a_sketch_point_is_a_pyramid() {
+ let mut app = app_with(json!([
+ {"command": "sketch.create", "params": {"plane": "XY", "name": "Base"}},
+ {"command": "sketch.rectangle.two_point", "params": {"p0": [-10, -10], "p1": [10, 10]}},
+ {"command": "sketch.finish", "params": {}},
+ {"command": "sketch.create", "params": {"plane": {"origin": [0, 0, 30], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}, "name": "Tip"}},
+ {"command": "sketch.point", "params": {"point": [0, 0], "id": "apex"}},
+ {"command": "sketch.finish", "params": {}},
+ ]));
+ let base = app.session.doc.find_feature("Base").unwrap().id;
+ let tip = app.session.doc.find_feature("Tip").unwrap().id;
+ let mut d = start(&mut app, vec![], "solid.loft");
+ d.inputs[0].items = vec![Sel::Profile { sketch: base, index: 0 }];
+ // A finished sketch's point, as a click on it gives.
+ d.inputs[0].toggle(vec![Sel::SketchPoint { id: format!("{tip}:apex") }]);
+ assert_eq!(d.inputs[0].items.len(), 2, "{:?}", d.inputs[0].items);
+ let cmds = apply_commands(&app, &d).unwrap();
+ assert_eq!(cmds[0].1["sections"][1], json!({"sketch": tip, "point": "apex"}), "{:?}", cmds[0].1);
+ for (cmd, p) in cmds {
+ app.run(&cmd, p).unwrap();
+ }
+ let st = app.session.world_state();
+ let v = solidcraft_engine::doc::kernel::measure(&st.bodies[0].body).unwrap().volume;
+ assert!((v - 4000.0).abs() < 4.0, "{v}");
+}