Select hidden geometry with Select Other and fit the list to the window (#5574) (#5577)

* claim: #5574

* Pick hidden geometry near long clicks in a five-row list (#5574)

* fix: make Select Other configurable and fit its list to the window

---------

Co-authored-by: Kirill Frolov <k.a.frolov@vk.team>
This commit is contained in:
fkirill
2026-10-30 13:25:56 +00:00
committed by GitHub
parent 9f5ac92faa
commit 12636b67be
8 changed files with 345 additions and 32 deletions
@@ -0,0 +1,34 @@
{
"en": {
"prefs.select_other_hidden": "Select hidden geometry with Select Other",
"prefs.select_other_hidden_help": "On: include hidden bodies, sketches and occluded edges near the pointer. Off: use the original list of visible geometry under the pointer."
},
"ar": {
"prefs.select_other_hidden": "تحديد العناصر الهندسية المخفية باستخدام «تحديد عنصر آخر»",
"prefs.select_other_hidden_help": "عند التفعيل: تضمين الأجسام والمخططات المخفية والحواف المحجوبة قرب المؤشر. عند التعطيل: استخدام القائمة الأصلية للعناصر الهندسية المرئية أسفل المؤشر."
},
"he": {
"prefs.select_other_hidden": "בחירת גאומטריה מוסתרת באמצעות בחירה אחרת",
"prefs.select_other_hidden_help": "מופעל: כולל גופים, סקיצות וקצוות מוסתרים בקרבת הסמן. כבוי: שימוש ברשימה המקורית של גאומטריה גלויה מתחת לסמן."
},
"ja": {
"prefs.select_other_hidden": "「他を選択」で非表示のジオメトリを選択",
"prefs.select_other_hidden_help": "オン: ポインター付近の非表示のボディやスケッチ、遮られたエッジを含めます。オフ: ポインター直下の表示中のジオメトリだけを元のリストに表示します。"
},
"vi": {
"prefs.select_other_hidden": "Chọn hình học ẩn bằng Chọn đối tượng khác",
"prefs.select_other_hidden_help": "Bật: bao gồm các khối, bản phác thảo ẩn và cạnh bị che gần con trỏ. Tắt: dùng danh sách ban đầu chỉ gồm hình học đang hiển thị ngay dưới con trỏ."
},
"zh": {
"prefs.select_other_hidden": "使用“选择其他”选择隐藏几何体",
"prefs.select_other_hidden_help": "开启:包括指针附近的隐藏实体、草图和被遮挡的边。关闭:恢复原来的列表,仅包含指针正下方的可见几何体。"
},
"de": {
"prefs.select_other_hidden": "Verborgene Geometrie mit „Andere auswählen“ auswählen",
"prefs.select_other_hidden_help": "Ein: Verborgene Körper, Skizzen und verdeckte Kanten nahe dem Zeiger einbeziehen. Aus: Die ursprüngliche Liste sichtbarer Geometrie direkt unter dem Zeiger verwenden."
},
"ko": {
"prefs.select_other_hidden": "다른 항목 선택으로 숨겨진 형상 선택",
"prefs.select_other_hidden_help": "켜짐: 포인터 근처의 숨겨진 바디, 스케치 및 가려진 모서리를 포함합니다. 꺼짐: 포인터 바로 아래에 보이는 형상만 포함하는 기존 목록을 사용합니다."
}
}
+6
View File
@@ -1339,6 +1339,8 @@ preference_settings! {
/// release and end there (#7247); clicks still draw a chain. Off (the default): a drag is a
/// click that moved on the way, placing a point where it is let go (#2448).
line_drag_draws_one: bool = false, PAGE_SKETCH => check_id("prefs.line_drag_draws_one");
/// Include hidden geometry and a small pointer neighbourhood in Select Other.
select_other_hidden: bool = true, PAGE_SKETCH => check_id("prefs.select_other_hidden");
/// When true: Shift+click adds without removing; Primary toggles.
/// When false (default): Shift and Primary both toggle.
selection_shift_add_only: bool = false, PAGE_SKETCH;
@@ -3493,6 +3495,9 @@ pub fn set(app: &mut SolveApp, p: &serde_json::Value) -> Result<serde_json::Valu
if p.get("layout").is_some() {
app.ui.layout = new.layout;
}
if new.select_other_hidden != app.preferences.select_other_hidden {
crate::select_other::close(app);
}
app.preferences = new;
sync_surface_analysis(app);
apply_file_limits(&app.preferences);
@@ -5030,6 +5035,7 @@ mod tests {
("nav", json!("blender"), PAGE_NAVIGATION),
("look_at_anim", json!(false), PAGE_NAVIGATION),
("selection_shift_add_only", json!(true), PAGE_SKETCH),
("select_other_hidden", json!(false), PAGE_SKETCH),
("sketch_conflict_colour", json!(false), PAGE_SKETCH),
("suppress_sketch_snap", json!(ModifierCombo::NONE), PAGE_SKETCH),
("sketch_state_icons", json!(false), PAGE_SKETCH),
+2
View File
@@ -80,6 +80,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
ui_kit::settings_section(ui, "selection", app.tr("prefs.selecting"), |ui| {
ui_kit::checkbox(ui, crate::i18n::tr_label("Click selects whole bodies"), &mut app.ui.pick_bodies);
ui_kit::checkbox(ui, app.tr("prefs.prefer_free_sketch_points"), &mut app.preferences.prefer_free_sketch_points);
let hidden = setting::select_other_hidden(app, ui).on_hover_text(app.tr("prefs.select_other_hidden_help"));
crate::scenario::publish_target("prefs:select_other_hidden", hidden.rect);
let click = app.tr("prefs.click");
let shift = app.tr("prefs.shift");
let ctrl = app.tr("prefs.ctrl_cmd");
+48 -19
View File
@@ -4,6 +4,8 @@
//!
//! - Holding the left button still (or a finger, on touch screens) for [`HOLD_SECS`], or the
//! viewport menu's "Select Other…", opens a list at the cursor of every pickable thing there,
//! including hidden geometry in a six-point radius without changing its visibility by default.
//! The `select_other_hidden` preference restores the visible-only list. It is
//! in the selection filter's and the open dialog's terms, front to back like layers: sketch
//! points and curves first (drawn over the model), then what belongs to a body, one body at a
//! time and the nearest body first (its vertices, edges, face, then the body itself), then
@@ -35,6 +37,7 @@ use crate::viewport::{Hit, Proj};
pub const HOLD_SECS: f64 = 0.5;
/// How far (screen points) a repeat click may be from the last one and still cycle.
const CYCLE_SLOP: f32 = 4.0;
const ROW_HEIGHT: f32 = 24.0;
/// The most rows kept per kind of thing (vertices, edges, faces, …). The list exists to tell a
/// handful of overlapping things apart; nearest first, farther ones of the same kind are dropped
/// so it stays readable and bounded.
@@ -61,6 +64,7 @@ pub struct Popup {
/// The model and dialog it was made for: it closes when they change.
revision: u64,
dialog: bool,
include_hidden: bool,
/// The browser's body highlight is ours to clear.
lit_body: bool,
/// The keys held at the press or click that opened it.
@@ -94,12 +98,12 @@ pub struct State {
/// Every pickable thing under `pos`, front to back (the sketch being edited first): see
/// [`order`].
pub fn rows(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Row> {
rows_capped(app, proj, pos).0
rows_capped(app, proj, pos, app.preferences.select_other_hidden).0
}
/// [`rows`], with how many things were under the cursor in all.
fn rows_capped(app: &SolveApp, proj: &Proj, pos: Pos2) -> (Vec<Row>, usize) {
let hits = crate::viewport::pick_all(app, proj, pos);
fn rows_capped(app: &SolveApp, proj: &Proj, pos: Pos2, through: bool) -> (Vec<Row>, usize) {
let hits = if through { crate::viewport::pick_through(app, proj, pos) } else { crate::viewport::pick_all(app, proj, pos) };
let mut found = crate::viewport::candidates(app, &hits);
let dialog = app.dialog.as_ref().is_some_and(|d| d.wants_picks());
// A body behind each face (body picking already turns faces into bodies).
@@ -387,14 +391,23 @@ pub fn open(app: &mut SolveApp, at: Pos2, held: Held) -> bool {
}
fn open_with(app: &mut SolveApp, proj: &Proj, at: Pos2, held: Held) -> bool {
let (rows, total) = rows_capped(app, proj, at);
let (rows, total) = rows_capped(app, proj, at, app.preferences.select_other_hidden);
close(app);
if rows.is_empty() {
app.set_status("Nothing to select here", false);
return false;
}
close(app);
app.viewport.select_other.popup =
Some(Popup { at, rows, total, hovered: None, revision: app.session.revision, dialog: app.dialog.is_some(), lit_body: false, held });
app.viewport.select_other.popup = Some(Popup {
at,
rows,
total,
hovered: None,
revision: app.session.revision,
dialog: app.dialog.is_some(),
include_hidden: app.preferences.select_other_hidden,
lit_body: false,
held,
});
true
}
@@ -457,8 +470,8 @@ pub fn control(app: &mut SolveApp, p: &Value) -> Result<Value, String> {
return Ok(describe(app));
}
if let (Some(x), Some(y)) = (p.get("x").and_then(Value::as_f64), p.get("y").and_then(Value::as_f64)) {
if !(x.is_finite() && y.is_finite()) {
return Err("x and y must be numbers".into());
if !(x.is_finite() && y.is_finite()) || x.abs() > 1e6 || y.abs() > 1e6 {
return Err("x and y must be finite screen points within ±1000000".into());
}
if app.viewport.rect.is_none() {
return Err("no viewport".into());
@@ -583,7 +596,7 @@ pub fn cycle_click(app: &mut SolveApp, proj: &Proj, at: Pos2) -> bool {
if c.at.distance(at) > CYCLE_SLOP || c.key != cycle_key(app) || c.selection != app.session.selection {
return false;
}
let rows = rows(app, proj, at);
let rows = rows_capped(app, proj, at, false).0;
if rows.len() < 2 {
return false;
}
@@ -602,24 +615,38 @@ pub fn cycle_click(app: &mut SolveApp, proj: &Proj, at: Pos2) -> bool {
/// Draw the open list; handle its hover, clicks, and a press elsewhere (which closes it).
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let Some(p) = app.viewport.select_other.popup.clone() else { return };
if p.revision != app.session.revision || p.dialog != app.dialog.is_some() || app.tool.is_some() {
if p.revision != app.session.revision
|| p.dialog != app.dialog.is_some()
|| p.include_hidden != app.preferences.select_other_hidden
|| app.tool.is_some()
{
close(app);
return;
}
let t = Tokens::get();
let mut hovered = None;
let mut picked = None;
let w = crate::context_menu::LIST_W - 10.0;
// Title, rows up to the scroll height, margins and border.
let size = vec2(w + 10.0, 30.0 + (p.rows.len() as f32 * 24.0).min(360.0));
let screen = ctx.content_rect();
let margins = crate::ui_kit::Menu::frame().total_margin().sum();
let width = crate::context_menu::LIST_W.min(screen.width());
let w = (width - margins.x).max(0.0);
let header = 20.0;
let gap = vec2(12.0, 12.0);
let at = pos2(p.at.x.clamp(screen.left(), screen.right()), p.at.y.clamp(screen.top(), screen.bottom()));
let rows_height = p.rows.len() as f32 * ROW_HEIGHT;
let overhead = header + margins.y;
let scroll_height = (screen.height() - overhead).max(0.0);
let size = vec2(width, overhead + rows_height.min(scroll_height));
let resp = Container::new(ctx, Surface::Popup)
.area(egui::Id::new("sc_select_other"))
.fixed_pos(crate::context_menu::place(p.at, vec2(12.0, 12.0), size, ctx.content_rect()))
.fixed_pos(crate::context_menu::place(at, gap, size, screen))
.constrain(true)
.order(egui::Order::Foreground)
.show(ctx, |ui| {
crate::context_menu::menu_frame(ui, |ui| {
let (r, _) = ui.allocate_exact_size(vec2(w, 20.0), Sense::hover());
// Area remembers the preceding list's size, which must not limit a longer list.
ui.set_max_height(size.y);
crate::ui_kit::Menu::show(ui, width, |ui| {
let (r, _) = ui.allocate_exact_size(vec2(w, header), Sense::hover());
let title = crate::i18n::tr_label("Select Other").to_uppercase();
let title = if p.total > p.rows.len() { format!("{title} · {} / {}", p.rows.len(), p.total) } else { title };
ui.painter().text(
@@ -629,9 +656,10 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
FontId::proportional(crate::theme::Tokens::get().font_panel),
t.text_dim,
);
egui::ScrollArea::vertical().max_height(360.0).show(ui, |ui| {
egui::ScrollArea::vertical().min_scrolled_height(0.0).max_height(scroll_height).show(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
for (i, row) in p.rows.iter().enumerate() {
let (r, resp) = ui.allocate_exact_size(vec2(w, 24.0), Sense::click());
let (r, resp) = ui.allocate_exact_size(vec2(w, ROW_HEIGHT), Sense::click());
crate::scenario::publish_handle(&format!("select_other:{i}"), r.center());
if resp.hovered() {
hovered = Some(i);
@@ -663,6 +691,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
});
});
});
crate::scenario::publish_rect("select_other", resp.response.rect);
if let Some(pop) = app.viewport.select_other.popup.as_mut()
&& pop.hovered != hovered
{
+217
View File
@@ -659,3 +659,220 @@ fn a_curve_from_intersect_is_labelled_intersected_and_one_from_project_projected
h.app.run("sketch.project", json!({"refs":[{"body":"Block"}]})).unwrap();
assert!(label(&h, LinkKind::Project).ends_with("(projected)"));
}
#[test]
fn long_press_picks_hidden_profiles_behind_a_body_without_revealing_them() {
let mut h = Harness::new();
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY","name":"Buried profile"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[10,10]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
let sketch = h.app.session.doc.find_feature("Buried profile").unwrap().id;
h.app.run("solid.box", json!({"length":20,"width":20,"height":10,"corner":[-5,-5,1],"body_name":"Cover"})).unwrap();
h.call("ui.view", json!({"view":"top"}));
h.call("ui.view", json!({"view":"fit"}));
h.app.session.visibility.hidden_sketches.push(sketch);
h.app.start("solid.extrude");
h.app.dialog.as_mut().unwrap().inputs[0].items.clear();
h.settle();
assert_eq!(h.call("ui.prefs", json!({}))["result"]["select_other_hidden"], true);
assert_eq!(h.call("ui.prefs", json!({"select_other_hidden":false}))["ok"], true);
h.step(&json!({"hold":{"world":[5,5,0]}})).unwrap();
assert!(!h.app.viewport.select_other.popup.as_ref().unwrap().rows.iter().any(|r| matches!(r.sel, Sel::Profile { .. })));
h.call("ui.selectOther", json!({"close":true}));
assert_eq!(h.call("ui.prefs", json!({"select_other_hidden":true}))["ok"], true);
let before = h.app.session.visibility.hidden_sketches.clone();
h.step(&json!({"hold":{"world":[5,5,0]}})).unwrap();
let popup = h.app.viewport.select_other.popup.as_ref().unwrap();
let row = popup.rows.iter().position(|r| r.sel == Sel::Profile { sketch, index: 0 }).unwrap();
h.call("ui.selectOther", json!({"pick":row}));
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, [Sel::Profile { sketch, index: 0 }]);
assert_eq!(h.app.session.visibility.hidden_sketches, before);
assert!(!crate::viewport::visible_sketches(&h.app).contains(&sketch));
assert!(h.app.session.selection.is_empty());
}
#[test]
fn see_through_includes_hidden_bodies_and_occluded_edges_but_normal_picks_do_not() {
let mut h = Harness::new();
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Hidden"})).unwrap();
h.app.run("solid.box", json!({"length":30,"width":30,"height":10,"corner":[-10,-10,20],"body_name":"Cover"})).unwrap();
h.call("ui.view", json!({"view":"top"}));
h.call("ui.view", json!({"view":"fit"}));
let point = h.at(&json!({"world":[5,0,10]})).unwrap();
let pos = egui::pos2(point[0] as f32, point[1] as f32);
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
let edge = |hit: &crate::viewport::Hit| matches!(hit, crate::viewport::Hit::Edge { body, .. } if body == "Hidden");
assert!(crate::viewport::pick_through(&h.app, &proj, pos).iter().any(edge));
assert!(!crate::viewport::pick_all(&h.app, &proj, pos).iter().any(edge));
h.app.session.visibility.hidden_bodies.push("Hidden".into());
let hidden = h.app.session.visibility.hidden_bodies.clone();
h.call("ui.prefs", json!({"select_other_hidden":false}));
h.call("ui.selectOther", json!({"x":pos.x,"y":pos.y}));
assert!(!h.app.viewport.select_other.popup.as_ref().unwrap().rows.iter().any(|r| r.sel == Sel::Body { name: "Hidden".into() }));
h.call("ui.selectOther", json!({"close":true}));
h.call("ui.prefs", json!({"select_other_hidden":true}));
h.call("ui.selectOther", json!({"x":pos.x,"y":pos.y}));
let i = h.app.viewport.select_other.popup.as_ref().unwrap().rows.iter().position(|r| r.sel == Sel::Body { name: "Hidden".into() }).unwrap();
h.call("ui.selectOther", json!({"pick":i}));
assert_eq!(h.app.session.selection, [Sel::Body { name: "Hidden".into() }]);
assert_eq!(h.app.session.visibility.hidden_bodies, hidden);
assert!(
!crate::viewport::pick_all(&h.app, &proj, pos).iter().any(|hit| matches!(hit, crate::viewport::Hit::Face { body, .. } if body == "Hidden"))
);
}
#[test]
fn approximate_long_click_reaches_profiles_and_shows_all_eight_rows() {
let mut h = Harness::new();
h.app.set_origin_shown(false);
let mut sketches = Vec::new();
for i in 0..8 {
h.app.run("sketch.create", json!({"plane":"XY","name":format!("Layer{i}")})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[10,10]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
sketches.push(h.app.session.doc.find_feature(&format!("Layer{i}")).unwrap().id);
}
h.call("ui.view", json!({"view":"top"}));
h.call("ui.view", json!({"view":"fit"}));
h.app.session.visibility.hidden_sketches = sketches.clone();
h.app.start("solid.extrude");
h.app.dialog.as_mut().unwrap().inputs[0].items.clear();
h.settle();
let at = h.at(&json!({"world":[10,5,0]})).unwrap();
let pos = egui::pos2(at[0] as f32 + 3.0, at[1] as f32);
let proj = crate::viewport::projection(&h.app, h.app.viewport.rect.unwrap());
assert!(crate::viewport::pick_all(&h.app, &proj, pos).iter().all(|x| !matches!(x, crate::viewport::Hit::Profile { .. })));
h.step(&json!({"hold":[pos.x,pos.y]})).unwrap();
assert_eq!(h.app.viewport.select_other.popup.as_ref().unwrap().rows.len(), 8);
h.frames(3);
if let Ok(dir) = std::env::var("SOLIDCRAFT_SELECT_OTHER_EVIDENCE") {
let ctx = crate::fonts::test_context();
let mut textures = std::collections::HashMap::new();
let mut last = None;
for _ in 0..4 {
let output = ctx.run_ui(
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1000.0))), ..Default::default() },
|ui| super::show(&mut h.app, ui.ctx()),
);
crate::ui_kit::test_textures_update(&mut textures, &output.textures_delta);
last = Some(output);
}
let output = last.unwrap();
let rect = crate::scenario::rect_of("select_other").unwrap();
std::fs::create_dir_all(&dir).unwrap();
crate::ui_kit::test_raster(&ctx, output.shapes, output.pixels_per_point, rect.expand(4.0), &textures)
.save(std::path::Path::new(&dir).join("select-other.png"))
.unwrap();
h.frames(4);
}
let rect = crate::scenario::rect_of("select_other").unwrap();
assert!(rect.height() > 8.0 * super::ROW_HEIGHT, "all eight rows plus header: {rect:?}");
for i in 0..8 {
assert!(rect.contains(crate::scenario::handle_at(&format!("select_other:{i}")).unwrap()), "row {i}: {rect:?}");
}
h.step(&json!({"click":{"handle":"select_other:7"}})).unwrap();
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, [Sel::Profile { sketch: sketches[7], index: 0 }]);
h.app.session.visibility.hidden_sketches.clear();
h.call("ui.prefs", json!({"select_other_hidden":false}));
assert!(!super::rows(&h.app, &proj, pos).iter().any(|r| matches!(r.sel, Sel::Profile { .. })), "old list uses the exact pointer");
h.call("ui.prefs", json!({"select_other_hidden":true}));
assert_eq!(super::rows(&h.app, &proj, pos).iter().filter(|r| matches!(r.sel, Sel::Profile { .. })).count(), 8);
h.app.session.visibility.hidden_sketches = sketches.clone();
}
#[test]
fn see_through_control_rejects_out_of_range_coordinates() {
let mut h = Harness::new();
h.settle();
for x in [1e300, -1e300, 1e7] {
let reply = h.call("ui.selectOther", json!({"x":x,"y":10}));
assert_eq!(reply["ok"], false, "{reply}");
}
}
#[test]
fn popup_uses_window_height_and_flips_above_the_pointer() {
for (count, y, height) in [(20, 100.0, 1000), (20, 900.0, 1000), (20, 500.0, 1000), (60, 500.0, 1000), (20, 240.0, 480)] {
let (mut h, at) = two_lines();
h.step(&json!({"hold":at})).unwrap();
let popup = h.app.viewport.select_other.popup.as_mut().unwrap();
popup.rows = vec![popup.rows[0].clone(); count];
popup.total = count;
popup.at.y = y;
h.call("ui.resize", json!({"width":1600,"height":height}));
h.frames(4);
let rect = crate::scenario::rect_of("select_other").unwrap();
assert!(h.ctx.content_rect().contains_rect(rect), "{count} rows: {rect:?}");
if count == 20 && height == 1000 {
assert!(rect.height() > 360.0, "large window shows more than the old fixed cap: {rect:?}");
assert!(rect.contains(crate::scenario::handle_at("select_other:19").unwrap()), "last row fits: {rect:?}");
if y > 500.0 {
assert!(rect.bottom() <= y, "opens above the pointer: {rect:?}");
} else if y < 500.0 {
assert!(rect.top() > y, "opens below the pointer: {rect:?}");
}
} else {
assert!(!rect.contains(crate::scenario::handle_at(&format!("select_other:{}", count - 1)).unwrap()), "overflow needs scrolling");
h.app.synthetic.push(egui::Event::PointerMoved(rect.center()));
h.app.synthetic.push(egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: egui::vec2(0.0, -2000.0),
phase: egui::TouchPhase::Move,
modifiers: egui::Modifiers::NONE,
});
h.frames(40);
assert!(rect.contains(crate::scenario::handle_at(&format!("select_other:{}", count - 1)).unwrap()), "can scroll to the last row");
}
}
}
#[test]
fn hidden_selection_preference_is_saved_and_older_settings_get_the_new_default() {
let prefs: crate::prefs::Prefs = serde_json::from_value(json!({})).unwrap();
assert_eq!(serde_json::to_value(&prefs).unwrap()["select_other_hidden"], true);
let prefs: crate::prefs::Prefs = serde_json::from_value(json!({"select_other_hidden":false})).unwrap();
assert_eq!(serde_json::to_value(&prefs).unwrap()["select_other_hidden"], false);
}
#[test]
fn hidden_selection_preference_can_be_changed_and_cancelled_in_preferences() {
let mut h = Harness::new();
h.call("ui.prefs", json!({"open":"Sketch & selection"}));
crate::prefs::reveal_preference(&mut h, "prefs:select_other_hidden");
h.step(&json!({"click":{"handle":"prefs:select_other_hidden"}})).unwrap();
assert_eq!(h.call("ui.prefs", json!({}))["result"]["select_other_hidden"], false);
h.call("ui.prefs", json!({"button":"cancel"}));
assert_eq!(h.call("ui.prefs", json!({}))["result"]["select_other_hidden"], true);
}
#[test]
fn changing_hidden_selection_or_opening_an_empty_point_clears_the_old_list() {
let mut h = Harness::new();
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Hidden"})).unwrap();
h.call("ui.view", json!({"view":"top"}));
h.call("ui.view", json!({"view":"fit"}));
let at = h.at(&json!({"world":[5,5,10]})).unwrap();
let point = json!({"x":at[0],"y":at[1]});
h.app.session.selection.clear();
h.app.session.visibility.hidden_bodies.push("Hidden".into());
h.call("ui.selectOther", point.clone());
assert!(super::is_open(&h.app));
h.call("ui.prefs", json!({"select_other_hidden":false}));
assert!(!super::is_open(&h.app), "old hidden rows close when the preference changes");
assert_eq!(h.call("ui.selectOther", point.clone())["result"]["open"], false);
assert_eq!(h.call("ui.selectOther", json!({"pick":0}))["ok"], false);
assert!(h.app.session.selection.is_empty());
h.call("ui.prefs", json!({"select_other_hidden":true}));
h.call("ui.selectOther", point.clone());
h.app.preferences.select_other_hidden = false;
h.frames(2);
assert!(!super::is_open(&h.app), "direct preference changes also close stale rows");
h.app.session.visibility.hidden_bodies.clear();
h.call("ui.selectOther", point);
assert!(super::is_open(&h.app));
let rect = h.app.viewport.rect.unwrap();
assert_eq!(h.call("ui.selectOther", json!({"x":rect.left()+20.0,"y":rect.top()+20.0}))["result"]["open"], false);
assert!(!super::is_open(&h.app), "an empty point cannot keep the preceding list");
}
+28 -10
View File
@@ -2260,7 +2260,7 @@ pub fn pick(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
/// Operand picking excludes idle MID selection, including while a tool is temporarily taken
/// out of `app.tool` to handle its click.
pub(crate) fn pick_for_tool(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
pick_hits(app, proj, pos, false, false, false)
pick_hits(app, proj, pos, false, false, false, false)
}
/// Like [`pick`], but also returns points of every visible sketch: only for the 3D drawing snap,
@@ -2273,11 +2273,28 @@ pub fn pick_3d(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
/// vertex, edge, axis and profile near the cursor, and the nearest face of every body along the
/// ray, instead of the nearest of each kind. Each kind is nearest first.
pub fn pick_all(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
pick_hits(app, proj, pos, false, true, true)
pick_hits(app, proj, pos, false, true, true, false)
}
/// See-through candidates in a small screen-space disk. The nine rays are fixed and bounded;
/// ordinary picking and repeat-click cycling retain their visible-only path.
pub(crate) fn pick_through(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
if !pos.x.is_finite() || !pos.y.is_finite() || !proj.rect.contains(pos) {
return Vec::new();
}
let mut out = Vec::new();
for (x, y) in [(0.0, 0.0), (6.0, 0.0), (-6.0, 0.0), (0.0, 6.0), (0.0, -6.0), (4.0, 4.0), (-4.0, 4.0), (4.0, -4.0), (-4.0, -4.0)] {
for hit in pick_hits(app, proj, pos + vec2(x, y), false, true, true, true) {
if !out.iter().any(|previous| same_target(previous, &hit)) {
out.push(hit);
}
}
}
out
}
fn pick_with_sketch_points(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool) -> Vec<Hit> {
let mut hits = pick_hits(app, proj, pos, other_sketch_points, false, true);
let mut hits = pick_hits(app, proj, pos, other_sketch_points, false, true, false);
// A Single hole's face place snaps to the face's centre and its round edges' centres.
crate::hole_place::snap_hits(app, proj, pos, &mut hits);
hits
@@ -2336,7 +2353,7 @@ impl<T: PartialOrd + Copy> Near<T> {
}
}
fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool, all: bool, include_midpoints: bool) -> Vec<Hit> {
fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool, all: bool, include_midpoints: bool, through: bool) -> Vec<Hit> {
let s = &app.session;
let st = crate::open_meshing::shown_world(app);
let bounds = body_bounds(app, &st);
@@ -2362,6 +2379,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
}
Some(moved)
};
let sketches = if through { st.sketches.iter().map(|s| s.feature).collect() } else { visible_sketches(app) };
let mut hits = Vec::new();
let (o, d) = proj.ray(pos);
// MID is an idle sketch selection target. Tools and dialogs keep their existing picks.
@@ -2395,7 +2413,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
let point_sketches: Vec<u64> = if crate::render_workspace::active(app) {
Vec::new()
} else if external_points {
visible_sketches(app)
sketches.clone()
} else {
s.active_sketch.into_iter().collect()
};
@@ -2441,7 +2459,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
// Sketch curves: the active sketch's own before projected and other sketches' ones, then
// nearest (the active sketch wins ties).
let mut bestc = Near::new(all);
for sid in visible_sketches(app).into_iter().filter(|_| !crate::render_workspace::active(app)) {
for sid in sketches.clone().into_iter().filter(|_| !crate::render_workspace::active(app)) {
let Some(ss) = st.sketch(sid) else { continue };
let active = s.active_sketch == Some(sid);
let bonus = if active { 2.0 } else { 0.0 };
@@ -2504,7 +2522,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
// Bounds retain the state's body order. Looking each one up by name made both passes
// quadratic for assemblies with many small parts.
for (i, b) in st.bodies.iter().enumerate() {
if !app.session.body_visible(&b.name) {
if !through && !app.session.body_visible(&b.name) {
continue;
}
// Bodies whose box the ray misses (or enters behind the best hit so far) are skipped.
@@ -2566,13 +2584,13 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
// Wireframe draws no faces, so nothing hides an edge or a vertex. `slack` is the body's own:
// what counts as lying on the face in front depends on how coarsely that body is meshed.
let wireframe = app.ui.visual_style == 2;
let visible = |p: Vec3, slack: f64| kept(p) && (wireframe || hidden_from.is_none_or(|t| (p - o).dot(d) <= t + slack));
let visible = |p: Vec3, slack: f64| kept(p) && (through || wireframe || hidden_from.is_none_or(|t| (p - o).dot(d) <= t + slack));
// Vertices (edge end points) and edges, within 7 and 6 points of the cursor.
let reach = crate::pick_index::reach(proj, pos, 8.0);
let mut bestv = Near::new(all);
let mut beste = Near::new(all);
for (i, b) in st.bodies.iter().enumerate() {
if !app.session.body_visible(&b.name) {
if !through && !app.session.body_visible(&b.name) {
continue;
}
let mut body_slack = slack;
@@ -2656,7 +2674,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
let mut surf: Vec<(f64, Hit)> = Vec::new();
let mut bestp: Option<(f64, f64, Hit)> = None;
let mut profiles_all: Vec<(f64, f64, Hit)> = Vec::new();
for sid in visible_sketches(app) {
for sid in sketches.clone() {
let Some(ss) = st.sketch(sid) else { continue };
let n = ss.plane.normal();
let den = n.dot(d);
+8 -2
View File
@@ -35,10 +35,16 @@
reach something under something else (two lines drawn on top of each other, coincident points,
an edge in front of a face, overlapping bodies), hold the left button still for half a second
(long-press on a touch screen) or right-click › **Select Other…**: a list of everything under
the cursor opens there, the sketch being edited first. Hovering a row lights it up; clicking it
the cursor opens there, including hidden bodies and sketches near the pointer.
The popup grows to fit the available window space, opening above the pointer when it needs
the extra room, and scrolls only when the rows do not fit. Turn off **Select hidden geometry
with Select Other** in Preferences › Sketch & selection to restore the original visible-only
list under the pointer. Picking a hidden object leaves its
visibility unchanged, so an Extrude profile can be chosen through a covering body.
The sketch being edited comes first. Hovering a row lights it up; clicking it
selects it (Shift or Ctrl adds), and in a command's dialog it goes to the active selection box.
Esc or a click elsewhere closes the list. Clicking again on the same spot, with nothing changed
in between, selects the next thing in that list. The
in between, cycles through visible candidates at that point. The
wheel zooms at the cursor, the middle button pans and right-drag orbits freely (the mouse
preset in Preferences switches to SolidWorks, Inventor, Alias, Maya, Blender, Tinkercad, OpenSCAD, HFSS or Touchpad style). On a
trackpad, pinch zooms and two-finger scroll pans (Navigation › Two-finger scroll pans;
+2 -1
View File
@@ -354,7 +354,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
| `ui.menu` | `x?`, `y?`, `target?`, `close?` | with a point: open a context menu there as a right-click would (the viewport's marking menu, or a browser menu with `target: {"type": "body", "name"} \| {"type": "sketch", "id"} \| {"type": "component", "id"}`); without: the open menu (`radial` and `items`: id, label, shortcut, enabled, icon, placeholder; blank icons on headings/separators have `placeholder: false`) |
| `ui.icon_audit` | `reset?`, `stop?` | `reset: true` enables collection on the UI thread and clears previous requests; returns `{requested: [{name, master, placeholder}]}` sorted by requested id. Each read drains names collected since the previous read/reset. Collection stays enabled until `stop: true` (which returns pending names before disabling it). Includes aliases, variable/table ids and cached paints. |
| `ui.menuPick` | `item`: id or label | runs an item of the open menu, as clicking it does |
| `ui.selectOther` | `x?`, `y?`, `pick?`, `add?`, `hover?`, `close?` | Select Other: with a point, list everything pickable there (as holding the left button does); `pick`: select row `pick` (`add`: as Shift-click; with a dialog open, into its active input); `hover`: light a row up; without: the open list (`open`, `at`, `total`: everything under the cursor, `rows`: label, icon, sel, at most 20 per kind, nearest first) |
| `ui.selectOther` | `x?`, `y?`, `pick?`, `add?`, `hover?`, `close?` | Select Other: with a point, list compatible hidden and visible geometry near the pointer by default (as holding the left button does; disable `select_other_hidden` for the original visible-only list); the popup fits the available window space and scrolls only for overflow; `pick`: select row `pick` (`add`: as Shift-click; with a dialog open, into its active input); `hover`: light a row up; without: the open list (`open`, `at`, `total`: everything under the cursor, `rows`: label, icon, sel, at most 20 per kind, nearest first) |
| `ui.rename` | `text?`, `commit?` (default true) | finishes the rename box a Rename item opened |
| `ui.selection` | | the selection, the open dialog's inputs, the hovered item, and the active sketch's drawn dimensions (`dimensions`: id and text centre, `dimension_selected`, `dimension_editing`), and finished sketches' dimensions shown in the model view (`shown_dimensions`: sketch, id and text centre; a double-click there edits the value) |
| `ui.worldToScreen` | `points`: `[[x, y, z]…]` world points | their screen points |
@@ -438,6 +438,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
- `print_face_highlight` (0…1, default 0.2: how strongly a print face is tinted and outlined in the view, #8429; 0 draws no highlight)
- `ribbon_reveal` (default false: hovering a result in Search commands switches the ribbon to the command's tab and marks its button, or opens the panel drop-down that holds it on its row, handle `ribbon:reveal`; leaving the results goes back to the tab before; a command started from the search blinks there, and a running command from a drop-down marks its panel label, `ribbon:running_section:<TAB>:<SECTION>`, #7287)
- `right_drag_orbits` (default true; false: a right drag the mouse preset would orbit leaves the camera alone, #6492)
- `select_other_hidden` (default true: Select Other includes hidden geometry near the pointer; false restores the original visible-only list under the pointer)
- `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle)
- `sketch_auto_dimensions` (default false: each shape drawn in a sketch gets all its dimensions at the sizes drawn, as `sketch.draw.dimensioned` with `as_drawn`; typed values win)
- `sketch_auto_locate` (default false; with `sketch_auto_dimensions`, new shapes are also placed from the sketch origin until fully constrained, as `sketch.draw.dimensioned` with `locate`)