SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
History: Edit Holes on a folder edits all its holes at once (#12520) (#12521)
Daniel Dimitrov46edecca6713
diff --git a/assets/locales/pending/hole-folder-edit.json b/assets/locales/pending/hole-folder-edit.jsonnew file mode 100644index 0000000000..1591da663b--- /dev/null+++ b/assets/locales/pending/hole-folder-edit.json@@ -0,0 +1,30 @@+{+ "en": {+ "Edit Holes": "Edit Holes",+ "hole_folder.applies_to": "Changes apply to the {count} holes in {folder}; each keeps its place."+ },+ "ar": {+ "Edit Holes": "تحرير الثقوب",+ "hole_folder.applies_to": "تنطبق التغييرات على الثقوب الـ {count} في {folder}؛ ويحتفظ كل ثقب بموضعه."+ },+ "de": {+ "Edit Holes": "Bohrungen bearbeiten",+ "hole_folder.applies_to": "Änderungen gelten für die {count} Bohrungen in {folder}; jede behält ihre Position."+ },+ "he": {+ "Edit Holes": "עריכת חורים",+ "hole_folder.applies_to": "השינויים חלים על {count} החורים ב-{folder}; כל חור שומר על מיקומו."+ },+ "ja": {+ "Edit Holes": "穴を編集",+ "hole_folder.applies_to": "変更は {folder} の {count} 個の穴に適用されます。各穴の位置はそのままです。"+ },+ "vi": {+ "Edit Holes": "Sửa các lỗ",+ "hole_folder.applies_to": "Thay đổi áp dụng cho {count} lỗ trong {folder}; mỗi lỗ giữ nguyên vị trí."+ },+ "zh": {+ "Edit Holes": "编辑孔",+ "hole_folder.applies_to": "更改将应用于 {folder} 中的 {count} 个孔;每个孔保持原位置。"+ }+}diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 88d740e4b3..ad44937944 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -1148,6 +1148,19 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->}ok(reply)}+ "ui.editFolder" => {+ let Some(id) = (match p.get("folder") {+ Some(Value::Number(n)) => n.as_u64(),+ Some(Value::String(x)) => app.session.doc.timeline_groups.iter().find(|group| group.name == *x).map(|group| group.id),+ _ => return err("`folder` must be a timeline folder id or name"),+ }) else {+ return err("no such timeline folder");+ };+ if let Err(why) = crate::hole_folder::open(app, id) {+ return err(why);+ }+ ok(started(app))+ }"ui.selection" => ok(json!({"selection": app.session.selection,"dialog": app.dialog.as_ref().map(|d| d.inputs.iter().map(|i| json!({"label": i.label, "items": i.items})).collect::<Vec<_>>()),diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 351ce8fef2..16f3f941a8 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -2834,6 +2834,10 @@ fn placement_row(d: &mut Dialog, ui: &mut egui::Ui, app: &SolveApp) {object_type_row(d, ui);return;}+ if crate::hole_folder::active(d) {+ crate::hole_folder::note(app, d, ui);+ return;+ }let Kind::Hole { opts, .. } = &mut d.kind else { return };let mut m = usize::from(opts.multiple);choice_row(ui, "Placement", "hole_place", &mut m, &["Single", "Multiple"]);@@ -4995,6 +4999,9 @@ pub fn apply_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>let mut cmds = dialog_commands(app, &normalized)?;exact_regions(d, &mut cmds);crate::op_auto::scope_targets(app, d, &mut cmds)?;+ if crate::hole_folder::active(d) {+ return crate::hole_folder::commands(app, d, cmds);+ }if let Some((id, _)) = d.editing {let (cmd, mut params) = cmds.into_iter().next().ok_or("nothing to apply")?;if let Some(feature) = app.session.doc.feature(id) {@@ -5769,14 +5776,20 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S}Kind::Move { .. } => return Ok(vec![("solid.move".into(), crate::dialogs_move::params(app, d)?)]),Kind::Hole { diameter, depth, kind, cb_diameter, cb_depth, cs_diameter, cs_angle, opts } => {- need(0, if opts.multiple { "sketch points" } else { "a face position" })?;+ let folder = crate::hole_folder::active(d);+ if !folder {+ need(0, if opts.multiple { "sketch points" } else { "a face position" })?;+ }let ty = match *kind {0 if opts.angled => "drilled",k => HOLE_TYPES.get(k).copied().unwrap_or("simple"),};// One hole per picked face position, or one Hole feature per sketch for sketch points.let mut places: Vec<Value> = Vec::new();- if opts.multiple {+ if folder {+ // Every hole of a folder keeps its own place (`hole_folder`).+ places.push(json!({}));+ } else if opts.multiple {let mut by_sketch: Vec<(u64, Vec<String>)> = Vec::new();for x in sels(d, 0) {if let Sel::SketchPoint { id } = xdiff --git a/crates/ui-egui/src/hole_folder.rs b/crates/ui-egui/src/hole_folder.rsnew file mode 100644index 0000000000..e788a1374f--- /dev/null+++ b/crates/ui-egui/src/hole_folder.rs@@ -0,0 +1,135 @@+//! Editing every hole in a History folder at once. A folder that holds only holes (and the folders+//! inside it) opens the Hole dialog filled in from its first hole, with nothing to pick: what OK+//! changes there (size, depth, type, thread, …) goes to each hole, and the rest of each hole (its+//! place first of all) stays its own. Each hole is redefined with `timeline.redefine`, as editing+//! it on its own does.++use serde_json::{Value, json};++use crate::SolveApp;+use crate::dialogs::Dialog;++/// Where the folder dialog keeps the folder and its holes, and the parameters it opened with.+const FOLDER: &str = "hole_folder";+const OPENED: &str = "hole_folder_opened";++/// The holes of folder `id`, in History order, when it (with the folders inside it) holds holes+/// only and no joints.+pub(crate) fn holes(app: &SolveApp, id: u64) -> Option<Vec<u64>> {+ let doc = &app.session.doc;+ let mut pending = vec![id];+ let mut seen = std::collections::BTreeSet::new();+ let mut ids = Vec::new();+ while let Some(id) = pending.pop() {+ if !seen.insert(id) {+ continue;+ }+ let group = doc.timeline_groups.iter().find(|group| group.id == id)?;+ if !group.joints.is_empty() {+ return None;+ }+ for feature in &group.features {+ if !matches!(doc.feature(*feature)?.kind, solidcraft_engine::doc::FeatureKind::Hole { .. }) {+ return None;+ }+ ids.push(*feature);+ }+ pending.extend(doc.timeline_groups.iter().filter(|child| child.parent == Some(id)).map(|child| child.id));+ }+ ids.sort_by_key(|feature| doc.feature_index(*feature));+ (!ids.is_empty()).then_some(ids)+}++/// Whether `d` edits a folder of holes.+pub(crate) fn active(d: &Dialog) -> bool {+ d.extra.contains_key(FOLDER)+}++/// How many holes the open folder dialog edits, and the folder's name.+pub(crate) fn summary(app: &SolveApp, d: &Dialog) -> Option<(usize, String)> {+ let folder = d.extra.get(FOLDER)?;+ let id = folder.get("group").and_then(Value::as_u64)?;+ let count = folder.get("holes").and_then(Value::as_array).map_or(0, Vec::len);+ let name = app.session.doc.timeline_groups.iter().find(|group| group.id == id).map(|group| group.name.clone())?;+ Some((count, name))+}++/// Open the Hole dialog for every hole in folder `id`.+pub(crate) fn open(app: &mut SolveApp, id: u64) -> Result<(), String> {+ let ids = holes(app, id).ok_or("the folder holds something other than holes")?;+ let first = *ids.first().ok_or("the folder holds no holes")?;+ crate::dialogs::cancel(app);+ let mut d = crate::dialogs::for_feature(app, first, None).ok_or("the hole can't be edited here")?;+ d.editing = None;+ d.inputs.clear();+ d.active = 0;+ for key in ["direction", "position_exprs", "all_points"] {+ d.extra.remove(key);+ }+ d.extra.insert(FOLDER.into(), json!({"group": id, "holes": ids}));+ let opened = hole_params(&crate::dialogs::apply_commands(app, &d)?)?;+ d.extra.insert(OPENED.into(), opened);+ app.dialog = Some(d);+ Ok(())+}++/// The parameters of the one `solid.hole` command among `cmds`.+fn hole_params(cmds: &[(String, Value)]) -> Result<Value, String> {+ match cmds {+ [(cmd, params)] if cmd == "solid.hole" => Ok(params.clone()),+ _ => Err("the Hole dialog made no hole".into()),+ }+}++/// The folder dialog's commands: `edited` is the one hole its fields make (with no place). Each+/// hole of the folder is redefined from its own parameters with the fields that differ from those+/// the dialog opened with; none at all before the dialog has opened.+pub(crate) fn commands(app: &SolveApp, d: &Dialog, edited: Vec<(String, Value)>) -> Result<Vec<(String, Value)>, String> {+ let Some(opened) = d.extra.get(OPENED) else { return Ok(edited) };+ let edited = hole_params(&edited)?;+ let (Some(opened), Some(edited)) = (opened.as_object(), edited.as_object()) else { return Err("the hole's fields are not a map".into()) };+ let changed: Vec<(&String, Option<&Value>)> =+ opened.keys().chain(edited.keys()).filter(|key| opened.get(*key) != edited.get(*key)).map(|key| (key, edited.get(key))).collect();+ let ids: Vec<u64> = d+ .extra+ .get(FOLDER)+ .and_then(|folder| folder.get("holes"))+ .and_then(Value::as_array)+ .map(|ids| ids.iter().filter_map(Value::as_u64).collect())+ .unwrap_or_default();+ let mut out = Vec::new();+ for id in ids {+ let one = crate::dialogs::for_feature(app, id, None).ok_or("a hole in the folder can't be edited")?;+ let Some((cmd, mut redefine)) = crate::dialogs::apply_commands(app, &one)?.into_iter().next() else { continue };+ let Some(params) = redefine.get_mut("params").and_then(Value::as_object_mut) else { continue };+ // A hole at a point keeps the point it was made at: its edit dialog finds the face there+ // in the model before the hole (History rolled back to it), which this one is not.+ if let Some(solidcraft_engine::doc::FeatureKind::Hole { points: None, position, at, .. }) = app.session.doc.feature(id).map(|f| &f.kind) {+ let place = match at {+ Some(exprs) => json!(exprs.iter().map(|e| e.as_str()).collect::<Vec<_>>()),+ None => json!([position.0.x, position.0.y, position.0.z]),+ };+ params.insert("position".into(), place);+ }+ for (key, value) in &changed {+ match value {+ Some(value) => {+ params.insert((*key).clone(), (*value).clone());+ }+ None => {+ params.remove(*key);+ }+ }+ }+ out.push((cmd, redefine));+ }+ Ok(out)+}++/// The line the folder dialog shows over its fields.+pub(crate) fn note(app: &SolveApp, d: &Dialog, ui: &mut egui::Ui) {+ if let Some((count, name)) = summary(app, d) {+ let text = crate::i18n::format("hole_folder.applies_to", &[("count", &count.to_string()), ("folder", &name)]);+ ui.add(egui::Label::new(egui::RichText::new(text).color(crate::theme::Tokens::get().text_dim)).wrap());+ }+}diff --git a/crates/ui-egui/src/hole_place_ui_tests.rs b/crates/ui-egui/src/hole_place_ui_tests.rsindex 8825d7afce..2e20549855 100644--- a/crates/ui-egui/src/hole_place_ui_tests.rs+++ b/crates/ui-egui/src/hole_place_ui_tests.rs@@ -569,3 +569,56 @@ fn single_holes_on_two_faces_share_a_parameter_typed_in_the_dialog() {assert!(!solid_at(&h, Vec3::new(30.0, 20.0, 17.0)) && !solid_at(&h, Vec3::new(25.0, 3.0, 10.0)), "both holes are drilled");assert!(solid_at(&h, Vec3::new(30.0, 20.0, 8.0)), "5 mm deep (and its drill point), not through");}++/// Each hole's (diameter, depth, position) in History order.+fn hole_fields(h: &Harness) -> Vec<(String, Option<String>, Vec3)> {+ h.app+ .session+ .doc+ .features+ .iter()+ .filter_map(|f| match &f.kind {+ FeatureKind::Hole { diameter, depth, position, .. } => Some((diameter.to_string(), depth.as_ref().map(|d| d.to_string()), position.0)),+ _ => None,+ })+ .collect()+}++#[test]+fn edit_holes_on_a_folder_changes_what_was_edited_in_every_hole_and_keeps_the_rest() {+ let mut h = block_as_installed();+ // Bore is through; the others are 4 and 6 mm deep.+ h.app.run("solid.hole", json!({"position": [30, 8, 20], "diameter": 6, "depth": 4, "name": "A"})).unwrap();+ h.app.run("solid.hole", json!({"position": [30, 22, 20], "diameter": 6, "depth": 6, "name": "B"})).unwrap();+ let folder = h.app.run("timeline.group", json!({"name": "Holes", "features": ["Bore", "A", "B"]})).unwrap()["group"].as_u64().unwrap();+ let before = hole_fields(&h);+ h.step(&json!({"call": "ui.editFolder", "params": {"folder": "Holes"}})).unwrap();+ h.frames(3);+ let d = h.app.dialog.as_ref().expect("the Hole dialog opened");+ assert!(d.editing.is_none() && d.inputs.is_empty(), "nothing to pick: each hole keeps its place");+ assert_eq!(crate::hole_folder::summary(&h.app, d), Some((3, "Holes".to_string())));+ // One redefinition per hole.+ let cmds = crate::dialogs::apply_commands(&h.app, d).unwrap();+ assert_eq!(cmds.iter().map(|(cmd, _)| cmd.as_str()).collect::<Vec<_>>(), ["timeline.redefine"; 3]);+ match h.app.dialog.as_mut().map(|d| &mut d.kind) {+ Some(Kind::Hole { diameter, .. }) => *diameter = "4 mm".into(),+ _ => panic!("the Hole dialog is open"),+ }+ 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));+ let after = hole_fields(&h);+ assert_eq!(after.len(), 3);+ for ((_, depth, position), (diameter, depth_now, position_now)) in before.iter().zip(&after) {+ assert_eq!(diameter, "4 mm", "every hole takes the new diameter");+ assert_eq!(depth, depth_now, "and keeps its own depth");+ assert!(position.dist(*position_now) < 1e-9, "and its place");+ }+ assert!(!solid_at(&h, Vec3::new(31.5, 8.0, 18.0)) && solid_at(&h, Vec3::new(33.5, 8.0, 18.0)), "A is 4 mm wide now");+ assert_eq!(h.app.session.doc.timeline_groups[0].id, folder, "still in their folder");+ // A folder with anything but holes has no Edit Holes.+ h.app.run("timeline.group", json!({"name": "Mixed", "features": [h.app.session.doc.features[0].id], "groups": [folder]})).unwrap();+ let mixed = h.app.session.doc.timeline_groups.iter().find(|g| g.name == "Mixed").unwrap().id;+ assert!(crate::hole_folder::holes(&h.app, mixed).is_none());+ assert!(h.step(&json!({"call": "ui.editFolder", "params": {"folder": "Mixed"}})).is_err());+}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex cdc76b99d1..d4a95fd3bc 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -76,6 +76,7 @@ mod history_folds;pub(crate) mod history_rows;#[cfg(test)]mod hole_direction_ui_tests;+pub(crate) mod hole_folder;pub(crate) mod hole_place;#[cfg(test)]mod hole_place_ui_tests;diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex c696eafcdd..06a98fba2c 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -849,6 +849,19 @@ pub(crate) fn floating_rect(available: Rect) -> Rect {Container::floating_card(Surface::Panel).bottom_strip_rect(available, 40.0)}+/// A folder's Edit Holes item, when it holds holes only: one Hole dialog for all of them.+pub(crate) fn edit_holes_item(app: &mut SolveApp, ui: &mut egui::Ui, folder: u64) {+ if crate::hole_folder::holes(app, folder).is_none() {+ return;+ }+ if crate::context_menu::button(ui, "Edit Holes", "hole").clicked() {+ if let Err(why) = crate::hole_folder::open(app, folder) {+ app.set_status(why, true);+ }+ ui.close();+ }+}+fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {let t = Tokens::get();let accent = crate::theme::TabAccent::for_tab(&t, &app.ui.tab);diff --git a/crates/ui-egui/src/timeline_folders.rs b/crates/ui-egui/src/timeline_folders.rsindex 9df31abeb2..b4ff47636d 100644--- a/crates/ui-egui/src/timeline_folders.rs+++ b/crates/ui-egui/src/timeline_folders.rs@@ -295,6 +295,7 @@ fn folder_menu(app: &mut SolveApp, ui: &mut egui::Ui, folder: &Folder, view: &crcrate::context_menu::start_rename(app, crate::context_menu::RenameWhat::TimelineGroup(folder.id), at);ui.close();}+ crate::timeline::edit_holes_item(app, ui, folder.id);if crate::context_menu::button(ui, "Ungroup", "feature_group").backing_on_hover_text("Keep its features and folders in the history").clicked() {app.tree.picked_timeline_groups.retain(|g| *g != folder.id);let _ = app.run("timeline.ungroup", json!({ "group": folder.id }));diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex f58a6f876b..04001270db 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -1174,6 +1174,7 @@ fn vertical_group_row(crate::context_menu::start_rename(app, crate::context_menu::RenameWhat::TimelineGroup(group.id), rect.center());ui.close();}+ crate::timeline::edit_holes_item(app, ui, group.id);ui.separator();selection_actions(app, ui, &table.groups, false);});diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex 08b5bd1b46..b4f784d0cc 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -805,6 +805,7 @@ no box selection.| `ui.at` | `world: [x,y,z]` \| `sketch: [x,y]` \| `plane: "XY"` \| `axis: "Z"` \| `dimension: "d1"` (its value text) \| `handle: "arrow"` (a manipulator handle, see `scenario::publish_handle`) | the screen point (a scenario step's target; see `crates/ui-egui/src/scenario.rs`) || `ui.pick` | `pixels?: [[x,y]…]`, `rays?: [{origin, dir}…]`, `frame?: "window"\|"model"`, `width?`, `height?`, `edges?` (default true), `edge_px?` (default 6), `all?`, `include_ghosted?` | read-only geometry under each pixel or ray (#6304): one entry per input, `null` where nothing is hit — body, face index, exact world `point` and outward `normal`, `depth`, `occurrence`/`component` for placed parts, `edge`/`vertex` within `edge_px` of a pixel, `section_cap: true` on a cut face. `window` pixels are physical pixels of a window screenshot; `model` pixels are pixels of a `ui.render` of `width`×`height` (default 960×600), so it works headless. As `view.pick` through `engine.execute`/`engine.batch`. See `crates/ui-egui/src/view_pick.rs` || `ui.handles` | `prefix?` | the handles drawn last frame, `[{name, x, y}]`: toolbar buttons and drop-down items `toolbar:<command id>` (the button alone: `button:<command id>`; a drop-down row: `dropdown:<command id>`, highlighted `dropdown_hot:<command id>`, its pin `dropdown_pin:<command id>`; Customize Toolbar's check boxes `customize:<command id>`), ribbon tabs `tab:<name>` (MODEL, SURFACE, ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW, SHEET METAL, WELDMENTS; contextual SKETCH; workspace RENDER), the toolbar menu button `ribbon:add_tab`, the hint when every tab is hidden `ribbon:tabs_hidden`, Preferences tab check boxes `prefs:toolbar_tab:<NAME>`, panel labels `panel:<tab>:<panel>` (also `ribbon:section:<TAB>:<SECTION>`), document overflow list `tab:overflow`, workspace column `ribbon:workspace`, command-search launcher `ribbon:search`, browser rows `row:<label>`, where each row's depth puts it `indent:<label>`, and fold arrows `fold:<label>`, manipulator handles; signed-axis tips `axis_view:z`, `axis_view:-y`; optional cube facets `navigation_cube:top`, `navigation_cube:top_front_right`, controls `navigation_cube:control:home` (and other actions), plus signed-axis aliases for visible cube faces; Preferences navigator picker `prefs:navigator`, options `prefs:navigator:Signed axes` and `prefs:navigator:Cube`; in the Motion Study dialog, where the chart puts its first and last step `motion:chart_start` and `motion:chart_end`, the Check collisions button `motion:check` and each collision found `motion:collision:<n>` |+| `ui.editFolder` | `folder` (id or name) | Edit Holes on a History folder that holds holes only: one Hole dialog, filled in from its first hole, whose OK gives every hole in the folder the fields changed there. Replies as `ui.start` does || `ui.editFeature` | `feature` (id or name) | what double-clicking a timeline item does: rolls back to it and opens its dialog filled in (sketches open in sketch mode). Replies as `ui.start` does, with the history `marker` || `ui.scroll` | `x`, `y`, `delta?`, `ctrl?`, `unit?`: `point` \| `line` | wheel zoom at the cursor. `ctrl: true` replays a Ctrl+wheel pinch (Ctrl held and the wheel in points); `unit` selects the wheel unit and defaults to points with `ctrl` and lines without it. `delta` is in points either way. Invalid units or coordinates outside the finite screen-coordinate range are rejected before queuing input || `ui.key` | `key` (egui key name, `Enter`, `Escape`…), `cmd?`, `ctrl?`, `shift?`, `alt?`, `pressed?` | By default, press and release, then release modifiers. With `pressed: true` or `false`, send only that edge; modifiers remain as given. `cmd` retains the legacy primary-modifier alias unless `ctrl` is explicit: `cmd:true, ctrl:false` sends physical Command, and both true sends Control+Command. `ui.move` can change modifiers between edges. |