Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions assets/locales/pending/hole-several-per-face.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"en": {
"prefs.design_tools.hole_several": "Several holes on one face",
"prefs.design_tools.hole_several_help": "Picking elsewhere on a face adds another hole; picking a hole removes it."
},
"ar": {
"prefs.design_tools.hole_several": "عدة ثقوب على وجه واحد",
"prefs.design_tools.hole_several_help": "الاختيار في موضع آخر من الوجه يضيف ثقبًا آخر، واختيار ثقب يزيله."
},
"de": {
"prefs.design_tools.hole_several": "Mehrere Bohrungen auf einer Fläche",
"prefs.design_tools.hole_several_help": "Eine Auswahl an anderer Stelle der Fläche fügt eine weitere Bohrung hinzu; die Auswahl einer Bohrung entfernt sie."
},
"he": {
"prefs.design_tools.hole_several": "כמה חורים בפאה אחת",
"prefs.design_tools.hole_several_help": "בחירה במקום אחר בפאה מוסיפה חור נוסף; בחירה בחור מסירה אותו."
},
"ja": {
"prefs.design_tools.hole_several": "1つの面に複数の穴",
"prefs.design_tools.hole_several_help": "面の別の場所を選ぶと穴を追加し、穴を選ぶとその穴を削除します。"
},
"vi": {
"prefs.design_tools.hole_several": "Nhiều lỗ trên một mặt",
"prefs.design_tools.hole_several_help": "Chọn chỗ khác trên mặt sẽ thêm một lỗ; chọn một lỗ sẽ xóa lỗ đó."
},
"zh": {
"prefs.design_tools.hole_several": "一个面上多个孔",
"prefs.design_tools.hole_several_help": "在面的其他位置选择会再添加一个孔;选择孔会移除该孔。"
}
}
12 changes: 9 additions & 3 deletions crates/ui-egui/src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5804,10 +5804,16 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
);
} else {
// One hole per pick: a curved surface split at its seam is picked whole (both
// halves, the clicked one first), but the hole goes where it was clicked only.
// halves, the clicked one first), but the hole goes where it was clicked only. A
// face takes one hole, or several when Preferences says so.
let several = crate::hole_place::several(app, d).then(|| crate::hole_place::several_places(s, sels(d, 0)));
let mut taken: Vec<Sel> = Vec::new();
for x in sels(d, 0) {
if !matches!(x, Sel::Face { .. }) || taken.iter().any(|t| same_face(t, x)) {
for (i, x) in sels(d, 0).iter().enumerate() {
let skip = match &several {
Some(places) => !places.contains(&i),
None => !matches!(x, Sel::Face { .. }) || taken.iter().any(|t| same_face(t, x)),
};
if skip {
continue;
}
taken.extend(crate::viewport::grouped_selection(s, x));
Expand Down
112 changes: 109 additions & 3 deletions crates/ui-egui/src/hole_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
//! Create Hole › Move holes by clicking or dragging (`hole_moves`): every placed hole has a handle at its
//! centre that drags it across the model (snapping as a pick would) and takes it out when
//! clicked, and a pick elsewhere on a face that already has a hole moves the hole there.
//!
//! 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.

use crate::ui_kit::BackingTooltipExt as _;
use solidcraft_engine::geom::prelude::*;
Expand Down Expand Up @@ -261,6 +264,91 @@ pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool {
move_place(d, s, i, sel.clone())
}

/// Whether this dialog's faces take several Single holes (Preferences): a new Hole in Single
/// placement. Editing a Hole keeps its one place.
pub(crate) fn several(app: &SolveApp, d: &Dialog) -> bool {
app.preferences.hole_several && d.editing.is_none() && matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple)
}

/// The items of the face input that are holes when a face takes several: each pick, but not the
/// other pieces of a round face split at its seam that a pick brought in with it (nor the same
/// pick twice).
pub(crate) fn several_places(s: &Session, items: &[Sel]) -> Vec<usize> {
let mut pieces: Vec<Sel> = Vec::new();
let mut out = Vec::new();
for (i, x) in items.iter().enumerate() {
if !matches!(x, Sel::Face { .. }) || pieces.contains(x) {
continue;
}
pieces.extend(crate::viewport::grouped_selection(s, x));
out.push(i);
}
out
}

/// Set the face input to the holes `places`, in order, each with the other pieces of its surface
/// (once), and the input's other items after them.
fn set_places(s: &Session, d: &mut Dialog, places: Vec<Sel>) {
let Some(inp) = d.inputs.first_mut() else { return };
let others: Vec<Sel> = inp.items.iter().filter(|x| !matches!(x, Sel::Face { .. })).cloned().collect();
let mut items: Vec<Sel> = Vec::new();
for p in places {
for x in crate::viewport::grouped_selection(s, &p) {
if !items.contains(&x) {
items.push(x);
}
}
}
items.extend(others);
inp.items = items;
d.error = None;
}

/// The holes of the face input when a face takes several, in order.
fn several_list(s: &Session, d: &Dialog) -> Vec<Sel> {
let items = d.inputs.first().map(|i| i.items.as_slice()).unwrap_or_default();
several_places(s, items).into_iter().filter_map(|i| items.get(i).cloned()).collect()
}

/// Move hole `n` (of `several_list`) to `to`, or take it out.
fn several_change(s: &Session, d: &mut Dialog, n: usize, to: Option<Sel>) {
let mut places = several_list(s, d);
if n >= places.len() {
return;
}
match to {
Some(to) => places[n] = to,
None => {
places.remove(n);
}
}
set_places(s, d, places);
}

/// When a face takes several Single holes (Preferences), a face pick adds a hole there, or takes
/// out the hole it lands on (within its radius). True when the pick was taken so.
pub(crate) fn pick_several(app: &SolveApp, d: &mut Dialog, sel: &Sel) -> bool {
if !several(app, d) || d.active != 0 {
return false;
}
let Kind::Hole { diameter, .. } = &d.kind else { return false };
let Sel::Face { point, .. } = sel else { return false };
let s = &app.session;
let radius = s.doc.eval(diameter, ValueKind::Length).ok().filter(|v| v.is_finite() && *v > 0.0).map_or(0.0, |v| v / 2.0);
let group = crate::viewport::grouped_selection(s, sel);
let mut places = several_list(s, d);
let on =
places.iter().position(|p| matches!(p, Sel::Face { point: at, .. } if at.dist(*point) <= radius) && group.iter().any(|g| same_item(g, p)));
match on {
Some(n) => {
places.remove(n);
}
None => places.push(sel.clone()),
}
set_places(s, d, places);
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.
Expand All @@ -273,7 +361,16 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte
if !app.preferences.hole_moves {
return;
}
let places = places(&app.session, d);
let several = several(app, d);
let places = if several {
several_list(&app.session, d)
.into_iter()
.enumerate()
.filter_map(|(n, x)| if let Sel::Face { point, .. } = x { Some((n, point)) } else { None })
.collect()
} else {
places(&app.session, d)
};
let mut moved: Option<(usize, Sel)> = None;
let mut removed: Option<usize> = None;
for (n, (i, at)) in places.into_iter().enumerate() {
Expand Down Expand Up @@ -308,15 +405,24 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painte
r.backing_on_hover_text(crate::i18n::tr_label("Drag to move the hole; click to remove it"));
}
}
// With several holes on a face, `i` counts the holes rather than the input's items.
if let Some((i, to)) = moved
&& let Some(d) = app.dialog.as_mut()
{
move_place(d, &app.session, i, to);
if several {
several_change(&app.session, d, i, Some(to));
} else {
move_place(d, &app.session, i, to);
}
}
if let Some(i) = removed
&& let Some(d) = app.dialog.as_mut()
{
remove_place(d, &app.session, i);
if several {
several_change(&app.session, d, i, None);
} else {
remove_place(d, &app.session, i);
}
}
}

Expand Down
72 changes: 70 additions & 2 deletions crates/ui-egui/src/hole_place_ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//! default), a pick near the middle of a face or on a round edge snaps there, and Alt held places
//! it where it was clicked. With Move holes by clicking or dragging on (also off by default), the
//! handle drags a placed hole (also one being edited) and a second pick on its face moves it.
//! Both off, picks behave as before. Either way the dialog shows the hole's sizes beside a
//! With Several holes on one face on, a pick elsewhere on its face adds a hole instead. All off,
//! picks behave as before. Either way the dialog shows the hole's sizes beside a
//! section of it.

use serde_json::json;
Expand Down Expand Up @@ -286,7 +287,10 @@ fn editing_a_hole_drags_it_to_a_new_place() {
#[test]
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, "a new installation places holes as it always did");
assert!(
!h.app.preferences.hole_snaps && !h.app.preferences.hole_moves && !h.app.preferences.hole_several,
"a new installation places holes as it always did"
);
h.step(&json!({"start": "solid.hole"})).unwrap();
// Beside the middle: no snap.
let at = off(&mut h, MIDDLE, 5.0, -4.0);
Expand Down Expand Up @@ -336,6 +340,70 @@ fn moving_holes_is_its_own_setting() {
assert!(places(&h).is_empty(), "{:?}", places(&h));
}

#[test]
fn with_several_holes_on_a_face_a_pick_adds_one_and_a_pick_on_a_hole_takes_it_out() {
// Several holes on one face (Preferences, off by default): each pick elsewhere on the face
// adds a hole, even with moves on; a pick on a hole takes that one out; the handles drag them
// one by one; OK drills them all.
let mut h = block_as_installed();
crate::prefs::set(&mut h.app, &json!({"hole_several": true, "hole_moves": true})).unwrap();
h.step(&json!({"start": "solid.hole"})).unwrap();
let spots = [Vec3::new(30.0, 8.0, 20.0), Vec3::new(32.0, 24.0, 20.0), Vec3::new(20.0, 22.0, 20.0)];
for p in spots {
let at = screen(&mut h, p);
h.step(&json!({"click": at})).unwrap();
}
let near = |got: &[Vec3], want: &[Vec3]| got.len() == want.len() && got.iter().zip(want).all(|(g, w)| g.dist(*w) < 0.2);
assert!(near(&places(&h), &spots), "three holes on the one face: {:?}", places(&h));
// On the second hole itself (inside its radius): that one goes, the others stay.
let at = off(&mut h, spots[1], 2.0, 0.0);
h.step(&json!({"click": at})).unwrap();
assert!(near(&places(&h), &[spots[0], spots[2]]), "{:?}", places(&h));
// The second handle drags the second hole only.
h.frames(2);
assert!(handle_at("hole:1").is_some() && handle_at("hole:2").is_none(), "a handle per hole");
let moved = Vec3::new(22.0, 6.0, 20.0);
let to = screen(&mut h, moved);
h.step(&json!({"drag": [{"handle": "hole:1"}, to]})).unwrap();
assert!(near(&places(&h), &[spots[0], moved]), "{:?}", places(&h));
let before = h.app.session.doc.features.len();
h.step(&json!({"key": "Enter"})).unwrap();
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
let holes = &h.app.session.doc.features[before..];
assert_eq!(holes.len(), 2, "one Hole feature per hole");
let down = Vec3::new(0.0, 0.0, 3.0);
assert!(!solid_at(&h, spots[0] - down) && !solid_at(&h, moved - down), "both drilled");
assert!(solid_at(&h, spots[1] - down) && solid_at(&h, spots[2] - down), "not where they were taken out or moved from");
}

#[test]
fn several_holes_on_a_round_face_are_one_per_pick() {
// A round face split at its seam is picked whole (both halves), but each pick is one hole.
let mut h = Harness::new();
h.app.set_origin_shown(false);
h.app.run("solid.cylinder", json!({"radius": 10, "height": 40})).unwrap();
crate::prefs::set(&mut h.app, &json!({"hole_several": true})).unwrap();
h.step(&json!({"call": "ui.view", "params": {"view": "front"}})).unwrap();
h.settle();
h.step(&json!({"start": "solid.hole"})).unwrap();
for z in [12.0, 28.0] {
let at = screen(&mut h, Vec3::new(0.0, -10.0, z));
h.step(&json!({"click": at})).unwrap();
}
if let Some(Kind::Hole { depth, diameter, opts, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
*depth = "5 mm".into();
*diameter = "4 mm".into();
opts.all = false;
opts.angled = false;
}
h.step(&json!({"key": "Enter"})).unwrap();
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
let holes = h.app.session.doc.features.iter().filter(|f| matches!(f.kind, FeatureKind::Hole { .. })).count();
assert_eq!(holes, 2, "a hole per pick, none for the other half of the face");
assert!(!solid_at(&h, Vec3::new(0.0, -8.0, 12.0)) && !solid_at(&h, Vec3::new(0.0, -8.0, 28.0)), "both drilled");
assert!(solid_at(&h, Vec3::new(0.0, -8.0, 20.0)), "solid between them");
}

#[test]
fn the_dialog_shows_the_sizes_beside_a_section_of_the_hole() {
let mut h = block();
Expand Down
5 changes: 5 additions & 0 deletions crates/ui-egui/src/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,10 @@ preference_settings! {
/// hole moves the hole there (`hole_place`). Off by default: a second pick on its face takes
/// the hole out, and a hole is moved by taking it out and picking again.
hole_moves: bool = false, PAGE_TOOLS => check("Move holes by clicking or dragging");
/// 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_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 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
Expand Down Expand Up @@ -6281,6 +6285,7 @@ mod tests {
("direct_interaction", json!(true), PAGE_TOOLS),
("hole_snaps", json!(true), PAGE_TOOLS),
("hole_moves", json!(true), PAGE_TOOLS),
("hole_several", 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),
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/prefs/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
"Snap to face and edge centres",
),
(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"),
] {
ui.horizontal_wrapped(|ui| {
let response = setting(app, ui).backing_on_hover_text(app.tr(help));
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/prefs_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ mod tests {
("Hide origin by default", "ui.hide_origin_by_default", crate::prefs::PAGE_DESIGN, "prefs:hide_origin"),
("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"),
("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"),
Expand Down
6 changes: 4 additions & 2 deletions crates/ui-egui/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3734,8 +3734,10 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) {
}
let sel = crate::dialogs_move::from_shown(app, sel);
let Some(mut d) = app.dialog.take() else { return };
// With holes moving by clicking (Preferences), a Single hole picked again on its face moves there.
if app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel) {
// With several holes on a face (Preferences), a Single hole's pick adds a hole or takes one
// out; with holes moving by clicking, a Single hole picked again on its face moves there.
if crate::hole_place::pick_several(app, &mut d, &sel) || (app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel))
{
d.focus = true;
d.awaiting_pick = false;
d.pick_refused = None;
Expand Down
1 change: 1 addition & 0 deletions docs/control-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `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_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)
- `home_fit_size` (0.1…1, default 1: how much of the view the model fills when Home, Fit, an opened design or a navigator view change frames it, with `navigator_fit` on or off; 1 fills the room between the panels, the compass and the navigation bar, as before; #10091)
- `joint_rotation_coarse` (default 10°): coarse Assembly Move rotation step, in 0.001…180°.
Expand Down
Loading
Loading