Skip to content

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

Loft: profiles picked one after another in one sketch are one section (#11720) (#11906)

Brett Lawson4faf63e48a50
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 4da9d95393..aebc662be1 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -4704,6 +4704,23 @@ pub fn apply_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>
params["profiles"] = json!("all");
}
}
+ // A Loft section that was every profile of its sketch stays "all" while the picks are
+ // unchanged: "all" keeps text counters as holes, which its indices would fill.
+ if let FeatureKind::Loft { sections, .. } = &feature.kind
+ && !d.profile_selection_changed
+ && let Some(edited) = params.get_mut("sections").and_then(Value::as_array_mut)
+ && edited.len() == sections.len()
+ {
+ let world = crate::open_meshing::session_world(&app.session);
+ for (sec, out) in sections.iter().zip(edited.iter_mut()) {
+ let Some(ss) = world.sketch(sec.sketch.0).filter(|_| sec.profiles == ProfileSel::All && sec.point.is_none()) else { continue };
+ let all: Vec<Value> = (0..ss.profiles.len()).map(|i| json!(i)).collect();
+ if out.get("sketch").and_then(Value::as_u64) == Some(sec.sketch.0) && out.get("profiles").and_then(Value::as_array) == Some(&all)
+ {
+ out["profiles"] = json!("all");
+ }
+ }
+ }
}
return Ok(vec![("timeline.redefine".into(), json!({"feature": id, "command": cmd, "params": params}))]);
}
@@ -5102,15 +5119,20 @@ 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")?;
- // Each picked profile is a section, in pick order, two of them from one sketch
- // included (#8221); a sketch point is a section of its own, an apex the loft closes
- // to (#4830).
+ // Sections follow the picks. Profiles picked one after another in one sketch are one
+ // section, such as both halves of a split outline (#11720); a later return to that
+ // sketch is a section of its own, so a loft can go there and back (#8221). A sketch
+ // point is a section of its own, an apex the loft closes to (#4830).
let mut sections: Vec<Value> = Vec::new();
let (mut profile_sketches, mut apexes) = (Vec::new(), 0);
for x in sels(d, 0) {
match x {
Sel::Profile { sketch, index } => {
- sections.push(json!({"sketch": sketch, "profiles": [index]}));
+ let last = sections.last_mut().filter(|sec| sec.get("sketch").and_then(Value::as_u64) == Some(*sketch));
+ match last.and_then(|sec| sec.get_mut("profiles")).and_then(Value::as_array_mut) {
+ Some(profiles) => profiles.push(json!(index)),
+ None => sections.push(json!({"sketch": sketch, "profiles": [index]})),
+ }
profile_sketches.push(*sketch);
}
Sel::SketchPoint { id } => {
diff --git a/crates/ui-egui/src/loft_rails_dialog_tests.rs b/crates/ui-egui/src/loft_rails_dialog_tests.rs
index 5b3ef259fe..f7d054f316 100644
--- a/crates/ui-egui/src/loft_rails_dialog_tests.rs
+++ b/crates/ui-egui/src/loft_rails_dialog_tests.rs
@@ -1,6 +1,7 @@
//! The Loft and Surface Loft dialogs' guide rails (#201): rails picked in the dialog reach the
//! commands with their sketches and the fit, and editing the loft brings them back and keeps them.
-//! Their sections follow the picks, two of them from one sketch included (#8221).
+//! Their sections follow the picks, two of them from one sketch included (#8221), and profiles
+//! picked one after another in one sketch are one section (#11720).
use crate::dialogs::Kind;
use crate::dialogs_surface::Surf;
use crate::scenario::Harness;
@@ -217,3 +218,64 @@ fn loft_profiles_from_one_sketch_stay_apart() {
assert_eq!(commands[0].1["params"]["sections"], expected);
ok(&mut h);
}
+
+/// Both halves of a split outline, picked one after the other, are one section (#11720): a
+/// 40 mm square split at x = 0 lofted to a 30 mm one split the same way makes one body, and an
+/// edit keeps the two sections. With one half picked above, the two halves below stay one section.
+#[test]
+fn loft_profiles_picked_together_in_one_sketch_are_one_section() {
+ let mut h = Harness::new();
+ let split =
+ |r: i32| [("sketch.rectangle.two_point", json!({"p0": [-r, -r], "p1": [r, r]})), ("sketch.line", json!({"points": [[0, -r], [0, r]]}))];
+ let low = sketch_at(&mut h, "Low", 0, &split(20));
+ let high = sketch_at(&mut h, "High", 30, &split(15));
+ h.step(&json!({"call":"ui.start","params":{"command":"solid.loft"}})).unwrap();
+ h.frames(3);
+ let pick = |sketch, index| Sel::Profile { sketch, index };
+ let d = h.app.dialog.as_mut().unwrap();
+ d.inputs[0].items = vec![pick(low, 0), pick(low, 1), pick(high, 0)];
+ let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(commands[0].1["sections"], json!([{"sketch": low, "profiles": [0, 1]}, {"sketch": high, "profiles": [0]}]));
+ let d = h.app.dialog.as_mut().unwrap();
+ d.inputs[0].items.push(pick(high, 1));
+ let expected = json!([{"sketch": low, "profiles": [0, 1]}, {"sketch": high, "profiles": [0, 1]}]);
+ let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(commands[0].1["sections"], expected);
+ ok(&mut h);
+ let ws = h.app.session.world_state().unwrap();
+ assert_eq!(ws.bodies.len(), 1, "{:?}", h.app.session.log);
+ // Frustum of a 40 mm square to a 30 mm one, 30 mm tall: h/3 (A + B + sqrt(AB)) = 37000 mm³.
+ let volume = solidcraft_engine::doc::kernel::measure(&ws.bodies[0].body).unwrap().volume;
+ assert!((volume - 37000.0).abs() < 1.0, "{volume}");
+ let name = h.app.session.doc.features.last().unwrap().name.clone();
+ h.step(&json!({"call":"ui.editFeature","params":{"feature":name}})).unwrap();
+ h.frames(8);
+ let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(commands[0].1["params"]["sections"], expected);
+ ok(&mut h);
+}
+
+/// A section that is every profile of its sketch stays "all" through an unchanged edit, now that
+/// the edit's picks of it make one section again (#11720): "all" keeps a letter's counter a hole,
+/// which the profiles' indices would fill.
+#[test]
+fn an_unchanged_loft_edit_keeps_a_section_of_all_profiles() {
+ let mut h = Harness::new();
+ let split = [("sketch.rectangle.two_point", json!({"p0": [-20, -20], "p1": [20, 20]})), ("sketch.line", json!({"points": [[0, -20], [0, 20]]}))];
+ let low = sketch_at(&mut h, "Low", 0, &split);
+ let high = sketch_at(&mut h, "High", 30, &[("sketch.circle.center", json!({"center": [0, 0], "radius": 10}))]);
+ h.app.run("solid.loft", json!({"sections": [{"sketch": low, "profiles": "all"}, {"sketch": high, "profiles": [0]}]})).unwrap();
+ let name = h.app.session.doc.features.last().unwrap().name.clone();
+ let sections = |h: &Harness| match &h.app.session.doc.find_feature(&name).unwrap().kind {
+ FeatureKind::Loft { sections, .. } => sections.iter().map(|s| s.profiles.clone()).collect::<Vec<_>>(),
+ k => panic!("{k:?}"),
+ };
+ let stored = sections(&h);
+ assert_eq!(stored[0], solidcraft_engine::doc::ProfileSel::All);
+ h.step(&json!({"call":"ui.editFeature","params":{"feature":name}})).unwrap();
+ h.frames(8);
+ let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
+ assert_eq!(commands[0].1["params"]["sections"], json!([{"sketch": low, "profiles": "all"}, {"sketch": high, "profiles": [0]}]));
+ ok(&mut h);
+ assert_eq!(sections(&h), stored);
+}