Skip to content

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

Hole: an option to put the holes one Hole command makes into a History folder (#12492) (#12493)

Daniel Dimitrov0bb09d0b13bc
diff --git a/assets/locales/pending/hole-group-folder.json b/assets/locales/pending/hole-group-folder.json
new file mode 100644
index 0000000000..03063ed92a
--- /dev/null
+++ b/assets/locales/pending/hole-group-folder.json
@@ -0,0 +1,34 @@
+{
+ "en": {
+ "prefs.design_tools.hole_group": "Group holes made together",
+ "prefs.design_tools.hole_group_help": "Holes made in one go share a folder in History, closed at first; open it to edit a hole on its own."
+ },
+ "ar": {
+ "prefs.design_tools.hole_group": "تجميع الثقوب المصنوعة معًا",
+ "prefs.design_tools.hole_group_help": "الثقوب المصنوعة دفعة واحدة تشترك في مجلد في السجل، مغلق في البداية؛ افتحه لتحرير كل ثقب على حدة."
+ },
+ "de": {
+ "prefs.design_tools.hole_group": "Gemeinsam erstellte Bohrungen gruppieren",
+ "prefs.design_tools.hole_group_help": "In einem Schritt erstellte Bohrungen teilen sich einen Ordner im Verlauf, zunächst geschlossen; öffnen Sie ihn, um eine Bohrung einzeln zu bearbeiten."
+ },
+ "he": {
+ "prefs.design_tools.hole_group": "קיבוץ חורים שנוצרו יחד",
+ "prefs.design_tools.hole_group_help": "חורים שנוצרו בפעולה אחת חולקים תיקייה בהיסטוריה, סגורה בהתחלה; פתחו אותה כדי לערוך חור בנפרד."
+ },
+ "ja": {
+ "prefs.design_tools.hole_group": "一緒に作成した穴をまとめる",
+ "prefs.design_tools.hole_group_help": "一度に作成した穴は履歴で1つのフォルダーにまとめられ、最初は閉じています。開くと穴を個別に編集できます。"
+ },
+ "ko": {
+ "prefs.design_tools.hole_group": "함께 만든 구멍 그룹화",
+ "prefs.design_tools.hole_group_help": "한 번에 만든 구멍은 기록에서 하나의 폴더를 공유하며, 처음에는 닫혀 있습니다. 폴더를 열어 각 구멍을 개별적으로 편집하세요."
+ },
+ "vi": {
+ "prefs.design_tools.hole_group": "Nhóm các lỗ được tạo cùng lúc",
+ "prefs.design_tools.hole_group_help": "Các lỗ được tạo trong một lần dùng chung một thư mục trong Lịch sử, ban đầu được đóng; mở thư mục để sửa từng lỗ."
+ },
+ "zh": {
+ "prefs.design_tools.hole_group": "将一起创建的孔分组",
+ "prefs.design_tools.hole_group_help": "一次创建的孔在历史中共用一个文件夹,初始为折叠;展开后可单独编辑每个孔。"
+ }
+}
diff --git a/attribution/pending/hole-group-folder.md b/attribution/pending/hole-group-folder.md
new file mode 100644
index 0000000000..e558d0aae4
--- /dev/null
+++ b/attribution/pending/hole-group-folder.md
@@ -0,0 +1,3 @@
+| File | Author | Source | Licence |
+| --- | --- | --- | --- |
+| `assets/locales/pending/hole-group-folder.json` | SolidCraft contributors | Original Hole grouping preference labels and translations | MIT OR Apache-2.0 |
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 16f3f941a8..b635422fb2 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -615,12 +615,13 @@ impl DialogComputation {
}
}
-fn adopt_dialog(app: &mut SolveApp, prepared: solidcraft_engine::ComputedCommands) -> Result<(), String> {
+fn adopt_dialog(app: &mut SolveApp, prepared: solidcraft_engine::ComputedCommands, d: &Dialog) -> Result<(), String> {
if app.file_load.busy() || app.file_picker_busy() {
return Err("a file operation is in progress".into());
}
let replies = app.session.accept_commands(prepared).map_err(|e| e.to_string())?;
app.big_operation = true;
+ let made = crate::hole_place::holes_made(&replies);
for (id, reply) in replies {
let stop = (id == "joint.drive").then(|| crate::dialogs_assembly::drive_stop(&reply)).flatten();
app.command_completed(&id, Ok(reply))?;
@@ -628,6 +629,7 @@ fn adopt_dialog(app: &mut SolveApp, prepared: solidcraft_engine::ComputedCommand
app.set_status(why, false);
}
}
+ crate::hole_place::group_made(app, d, made);
Ok(())
}
@@ -4138,7 +4140,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
Err(error) => d.refuse(app, error),
}
} else {
- let run = result.and_then(|prepared| adopt_dialog(app, prepared));
+ let run = result.and_then(|prepared| adopt_dialog(app, prepared, &d));
match run {
Ok(()) => {
cancel = !apply_again;
@@ -4888,16 +4890,18 @@ pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> {
}
if d.previews() {
let prepared = DialogComputation::new(app, d)?.compute()?;
- return adopt_dialog(app, prepared);
+ return adopt_dialog(app, prepared, d);
}
let commands = apply_commands(app, d)?;
if let Some((_, marker)) = d.editing {
// Record the actual pre-edit timeline state in the command's undo snapshot.
roll_marker(app, marker)?;
}
+ let mut replies = Vec::new();
for (cmd, params) in commands {
match app.run(&cmd, params) {
Ok(reply) => {
+ replies.push((cmd.clone(), reply.clone()));
// A drive that stopped short says where, and why.
if cmd == "joint.drive"
&& let Some(why) = crate::dialogs_assembly::drive_stop(&reply)
@@ -4914,6 +4918,8 @@ pub(crate) fn run_dialog(app: &mut SolveApp, d: &Dialog) -> Result<(), String> {
}
}
}
+ let made = crate::hole_place::holes_made(&replies);
+ crate::hole_place::group_made(app, d, made);
if let Kind::Section { offset, flip, hatch } = &d.kind
&& let Some(cut) = app.session.section
{
diff --git a/crates/ui-egui/src/hole_place.rs b/crates/ui-egui/src/hole_place.rs
index f11e542cf6..9b9895dd76 100644
--- a/crates/ui-egui/src/hole_place.rs
+++ b/crates/ui-egui/src/hole_place.rs
@@ -14,6 +14,8 @@
//!
//! Create Hole › Several holes on one face (`hole_several`): a pick elsewhere on a face that already
//! has a hole adds another hole there (rather than moving it), and a pick on a hole takes it out.
+//! Create Hole › Group holes made together (`hole_group`): the holes one Hole dialog makes, two or
+//! more, go into a feature folder in History, closed at first.
use crate::ui_kit::BackingTooltipExt as _;
use solidcraft_engine::geom::prelude::*;
@@ -349,6 +351,42 @@ pub(crate) fn pick_several(app: &SolveApp, d: &mut Dialog, sel: &Sel) -> bool {
true
}
+/// The features the Hole commands among `replies` made, in order.
+pub(crate) fn holes_made(replies: &[(String, serde_json::Value)]) -> Vec<u64> {
+ replies.iter().filter(|(id, _)| id == "solid.hole").filter_map(|(_, reply)| reply.get("feature").and_then(serde_json::Value::as_u64)).collect()
+}
+
+/// With Group holes made together on (Preferences), the holes one Hole dialog made (two or more)
+/// go into a feature folder in History, closed at first: opened, each hole is edited on its own.
+/// The folder sits where the holes went (inside the folder they were added to, if any).
+pub(crate) fn group_made(app: &mut SolveApp, d: &Dialog, made: Vec<u64>) {
+ if !app.preferences.hole_group || d.editing.is_some() || !matches!(d.kind, Kind::Hole { .. }) || made.len() < 2 {
+ return;
+ }
+ let parent = made.first().and_then(|first| app.session.doc.timeline_groups.iter().find(|g| g.features.contains(first))).map(|g| g.id);
+ let made_count = made.len();
+ match app.run("timeline.group", serde_json::json!({"name": "Holes", "features": made, "parent": parent})) {
+ Ok(reply) => {
+ if let Some(id) = reply.get("group").and_then(serde_json::Value::as_u64) {
+ crate::timeline_folders::set_open(app, id, false);
+ }
+ // Keep one Undo step for all holes from this dialog, with folder creation after it.
+ let undo = &mut app.session.undo;
+ let first_hole =
+ undo.len().checked_sub(made_count + 1).filter(|&first| undo[first..undo.len() - 1].iter().all(|step| step.label == "Hole"));
+ if let Some(first_hole) = first_hole {
+ let folder_step = undo.pop();
+ if let Some(folder_step) = folder_step {
+ drop(undo.drain(first_hole + 1..));
+ undo.push(folder_step);
+ }
+ }
+ }
+ // The holes stand; only the folder is missing.
+ Err(error) => app.set_status(error, true),
+ }
+}
+
/// The hovered face's snap marks, and the face places' handles when holes move by dragging.
/// Called after the canvas draws the dialog's arrows, so a press on a hole's centre takes the
/// hole, not the depth arrow.
diff --git a/crates/ui-egui/src/hole_place_ui_tests.rs b/crates/ui-egui/src/hole_place_ui_tests.rs
index 2e20549855..a593e040d7 100644
--- a/crates/ui-egui/src/hole_place_ui_tests.rs
+++ b/crates/ui-egui/src/hole_place_ui_tests.rs
@@ -288,7 +288,7 @@ fn editing_a_hole_drags_it_to_a_new_place() {
fn snaps_and_moves_are_off_by_default_and_picks_behave_as_before() {
let mut h = block_as_installed();
assert!(
- !h.app.preferences.hole_snaps && !h.app.preferences.hole_moves && !h.app.preferences.hole_several,
+ !h.app.preferences.hole_snaps && !h.app.preferences.hole_moves && !h.app.preferences.hole_several && !h.app.preferences.hole_group,
"a new installation places holes as it always did"
);
h.step(&json!({"start": "solid.hole"})).unwrap();
@@ -622,3 +622,54 @@ fn edit_holes_on_a_folder_changes_what_was_edited_in_every_hole_and_keeps_the_re
assert!(crate::hole_folder::holes(&h.app, mixed).is_none());
assert!(h.step(&json!({"call": "ui.editFolder", "params": {"folder": "Mixed"}})).is_err());
}
+
+/// Single holes on the block's top and front faces, made with OK; the new Hole features' ids.
+fn holes_on_two_faces(h: &mut Harness) -> Vec<u64> {
+ let before = h.app.session.doc.features.len();
+ h.step(&json!({"start": "solid.hole"})).unwrap();
+ for p in [Vec3::new(30.0, 20.0, 20.0), Vec3::new(25.0, 0.0, 10.0)] {
+ let at = screen(h, p);
+ h.step(&json!({"click": at})).unwrap();
+ }
+ h.step(&json!({"click": {"handle": "dialog:ok"}})).unwrap();
+ h.settle();
+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
+ h.app.session.doc.features[before..].iter().filter(|f| matches!(f.kind, FeatureKind::Hole { .. })).map(|f| f.id).collect()
+}
+
+#[test]
+fn holes_made_together_share_a_closed_folder_when_preferences_say_so() {
+ let mut h = block_as_installed();
+ h.step(&json!({"call": "ui.view", "params": {"view": "iso"}})).unwrap();
+ h.settle();
+ // Off (the default): each hole is its own entry in History, as before.
+ assert_eq!(holes_on_two_faces(&mut h).len(), 2);
+ assert!(h.app.session.doc.timeline_groups.is_empty(), "no folder");
+ // On: the two holes go into one folder, closed at first.
+ crate::prefs::set(&mut h.app, &json!({"hole_group": true})).unwrap();
+ let made = holes_on_two_faces(&mut h);
+ assert_eq!(made.len(), 2);
+ let [folder] = h.app.session.doc.timeline_groups.as_slice() else { panic!("one folder: {:?}", h.app.session.doc.timeline_groups) };
+ assert_eq!((folder.name.as_str(), &folder.features, folder.parent), ("Holes", &made, None));
+ assert!(!crate::timeline_folders::is_open(&h.app, folder.id, true), "closed at first, in both Histories");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(h.app.session.doc.timeline_groups.is_empty(), "first Undo removes the folder");
+ assert_eq!(h.app.session.doc.features.iter().filter(|f| made.contains(&f.id)).count(), 2, "holes remain");
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(h.app.session.doc.features.iter().filter(|f| made.contains(&f.id)).count(), 0, "second Undo removes both holes");
+ h.app.run("edit.redo", json!({})).unwrap();
+ h.app.run("edit.redo", json!({})).unwrap();
+ // One hole alone, or a hole edited, stays out of any new folder.
+ h.step(&json!({"start": "solid.hole"})).unwrap();
+ let at = screen(&mut h, Vec3::new(5.0, 25.0, 20.0));
+ h.step(&json!({"click": at})).unwrap();
+ h.step(&json!({"click": {"handle": "dialog:ok"}})).unwrap();
+ h.settle();
+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
+ h.step(&json!({"call": "ui.editFeature", "params": {"feature": made[0]}})).unwrap();
+ h.frames(4);
+ h.step(&json!({"click": {"handle": "dialog:ok"}})).unwrap();
+ h.settle();
+ assert_eq!(h.app.session.doc.timeline_groups.len(), 1, "still the one folder");
+ assert_eq!(h.app.session.doc.timeline_groups[0].features, made, "holding the same holes");
+}
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index 7b2012e80a..4ae5328f74 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -1496,6 +1496,9 @@ preference_settings! {
/// and a pick on a hole takes it out (`hole_place`). Off by default: a face takes one Single
/// hole, and a second pick on it takes the hole out (or moves it, with `hole_moves`).
hole_several: bool = false, PAGE_TOOLS => check_id("prefs.design_tools.hole_several");
+ /// The holes one Hole command makes (two or more) go into a feature folder in History, closed
+ /// at first (`hole_place`). Off by default: each hole is its own entry in History, as before.
+ hole_group: bool = false, PAGE_TOOLS => check_id("prefs.design_tools.hole_group");
/// The browser's Origin folder starts hidden in designs that don't keep its eye themselves.
hide_origin: bool = false, PAGE_DESIGN => check_tr("ui.hide_origin_by_default");
/// Handles on the preview of a feature placed on a face (Rest, Boss, Snap Fit): a marker that
@@ -6412,6 +6415,7 @@ mod tests {
("hole_snaps", json!(true), PAGE_TOOLS),
("hole_moves", json!(true), PAGE_TOOLS),
("hole_several", json!(true), PAGE_TOOLS),
+ ("hole_group", json!(true), PAGE_TOOLS),
("extrude_arrow_face_stops", json!(false), PAGE_TOOLS),
("extrude_auto_to_object", json!(false), PAGE_TOOLS),
("extrude_view_isometric", json!(true), PAGE_TOOLS),
diff --git a/crates/ui-egui/src/prefs/tools.rs b/crates/ui-egui/src/prefs/tools.rs
index d4551d5bf1..d8502d7c93 100644
--- a/crates/ui-egui/src/prefs/tools.rs
+++ b/crates/ui-egui/src/prefs/tools.rs
@@ -17,6 +17,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
),
(setting::hole_moves, "prefs.design_tools.hole_moves_help", "hole_moves", "Move holes by clicking or dragging"),
(setting::hole_several, "prefs.design_tools.hole_several_help", "hole_several", "Several holes on one face"),
+ (setting::hole_group, "prefs.design_tools.hole_group_help", "hole_group", "Group holes made together"),
] {
ui.horizontal_wrapped(|ui| {
let response = setting(app, ui).backing_on_hover_text(app.tr(help));
diff --git a/crates/ui-egui/src/prefs_search.rs b/crates/ui-egui/src/prefs_search.rs
index 5b92fc6ad5..85cd57053d 100644
--- a/crates/ui-egui/src/prefs_search.rs
+++ b/crates/ui-egui/src/prefs_search.rs
@@ -1561,6 +1561,7 @@ mod tests {
("Snap to face and edge centres", "Snap to face and edge centres", crate::prefs::PAGE_TOOLS, "prefs:hole_snaps"),
("Move holes by clicking or dragging", "Move holes by clicking or dragging", crate::prefs::PAGE_TOOLS, "prefs:hole_moves"),
("Several holes on one face", "prefs.design_tools.hole_several", crate::prefs::PAGE_TOOLS, "prefs:hole_several"),
+ ("Group holes made together", "prefs.design_tools.hole_group", crate::prefs::PAGE_TOOLS, "prefs:hole_group"),
("Show moved parts' old place as a ghost", "prefs.design_tools.ghost", crate::prefs::PAGE_TOOLS, "prefs:drive_joints_ghost"),
("Near-axis rotation step (°)", "joint_move.coarse", crate::prefs::PAGE_TOOLS, "prefs:joint_rotation_coarse"),
("Far-axis rotation step (°)", "joint_move.fine", crate::prefs::PAGE_TOOLS, "prefs:joint_rotation_fine"),
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index b4f784d0cc..0f03f1c5d0 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -895,6 +895,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `ground_shadow_follows_model` (Graphics, default false): raised models cast their ground shadow on the origin ground plane; true restores the shadow below the lowest visible body. Both modes keep the shadow below bodies extending beneath the origin, and follow the selected up axis.
- `hidden_toolbar_tabs` (default `[]`: all existing tabs, including Sheet Metal and Weldments, stay visible; lists tabs to hide, each once, e.g. `["SURFACE", "SHEET METAL"]`; hidden tabs stay hidden regardless of the design's features; [ribbon layout](ribbon-layout.md))
- `history_sketches` (`in_order` (default), `under_feature`: the History at the left lists a sketch under the first feature built from it, #6489; the timeline at the bottom keeps the creation order)
+- `hole_group` (default false: the holes one Hole command makes, two or more, go into a feature folder in History, closed at first)
- `hole_moves` (default false: a placed Single hole has a drag handle (`hole:<n>`), and a pick on a face that has a hole moves it there)
- `hole_several` (default false: a face takes several Single holes; a pick elsewhere on a face that has a hole adds another, and a pick on a hole takes it out)
- `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres)
diff --git a/docs/design/preferences/pages/tools.md b/docs/design/preferences/pages/tools.md
index e1b32b800c..bd2dcb4d40 100644
--- a/docs/design/preferences/pages/tools.md
+++ b/docs/design/preferences/pages/tools.md
@@ -13,6 +13,7 @@ Each group is a 120x64 figure at the left of its checkboxes, with a group name u
| Hole: Snap to centres | Checkbox | `Prefs.hole_snaps` | `false` | "The middle of a face and the centres of its round edges." | `tool-hole` | Today's label "Snap to face and edge centres". |
| Hole: Move by click or drag | Checkbox | `Prefs.hole_moves` | `false` | "Picking the face again moves the hole instead of removing it." | `tool-hole` | Today's label "Move holes by clicking or dragging". |
| Hole: Several per face | Checkbox | `Prefs.hole_several` | `false` | "Picking elsewhere on a face adds another hole; picking a hole removes it." | `tool-hole` | Label "Several holes on one face". |
+| Hole: Group holes made together | Checkbox | `Prefs.hole_group` | `false` | "Holes made in one go share a folder in History, closed at first; open it to edit a hole on its own." | `tool-hole` | Label "Group holes made together". |
| Extrude: Extrude to a picked target | Checkbox | `Prefs.extrude_auto_to_object` | `true` | "A face, vertex or parallel plane switches the extent to To Object." | `tool-extrude` | |
| Extrude: Choose the operation automatically | Checkbox | `Prefs.auto_operation` | `true` | "Join, New Body or Cut, from what the material touches." | `tool-extrude` | |
| Extrude: Turn the view to isometric when Extrude opens | Checkbox | `Prefs.extrude_view_isometric` | `false` | none | `tool-extrude` | Retained newer control, directly after automatic operation in the same group. |