Save the browser's view with the design, and an option to hide the origin by default (#1849)

The Origin folder's eye, a finished sketch's Show Profile and Show Dimensions,
and body locks move from UiState into the design's saved visibility
(origin_hidden, hidden_profiles, shown_dimensions, locked_bodies), so each tab
keeps its own and they survive closing the design. The Sketches folder uses the
saved browser folder (c0/sketches in hidden_folders); ui.set/ui.inspect keep
showOrigin, showSketches, hiddenProfiles, shownDims and lockedBodies.

Preferences > Design > "Hide origin by default": a design that never toggled
its Origin eye follows the preference. New fields are a pending format change
(format/pending/browser-view-state.rs).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
froglemonade2
2026-10-24 17:15:47 +00:00
committed by GitHub
parent 1236863b17
commit 46f24f2394
43 changed files with 306 additions and 189 deletions
+2
View File
@@ -1843,6 +1843,8 @@
"ui.hideOrigin": "Skrýt počátek",
"ui.hidePlanes": "Skrýt roviny",
"ui.hideProfile": "Skrýt profil",
"ui.hide_origin_by_default": "Ve výchozím stavu skrýt počátek",
"ui.hide_origin_note": "Nové návrhy začínají se skrytou složkou Počátek. Návrh si ponechá vlastní nastavení počátku, jakmile ho zobrazíte nebo skryjete.",
"ui.history_back": "O krok zpět",
"ui.history_below_browser": "Pod prohlížečem",
"ui.history_first": "Přejít na začátek",
+2
View File
@@ -2696,6 +2696,8 @@
"ui.hideOrigin": "Hide Origin",
"ui.hidePlanes": "Hide Planes",
"ui.hideProfile": "Hide Profile",
"ui.hide_origin_by_default": "Hide origin by default",
"ui.hide_origin_note": "New designs start with the Origin folder hidden. A design keeps its own Origin setting once you show or hide it.",
"ui.history_back": "Go back one step",
"ui.history_below_browser": "Below browser",
"ui.history_edge_hint": "double-click the edge",
+2
View File
@@ -2696,6 +2696,8 @@
"ui.hideOrigin": "原点を非表示",
"ui.hidePlanes": "平面を非表示",
"ui.hideProfile": "プロファイルを非表示",
"ui.hide_origin_by_default": "原点を既定で非表示",
"ui.hide_origin_note": "新しいデザインは原点フォルダーを非表示にして始まります。原点の表示/非表示を切り替えたデザインは、その設定を保持します。",
"ui.history_back": "1ステップ戻る",
"ui.history_below_browser": "ブラウザーの下",
"ui.history_edge_hint": "端をダブルクリック",
+2
View File
@@ -2696,6 +2696,8 @@
"ui.hideOrigin": "隐藏原点",
"ui.hidePlanes": "隐藏平面",
"ui.hideProfile": "隐藏轮廓",
"ui.hide_origin_by_default": "默认隐藏原点",
"ui.hide_origin_note": "新设计开始时原点文件夹处于隐藏状态。显示或隐藏过原点的设计会保留自己的原点设置。",
"ui.history_back": "后退一步",
"ui.history_below_browser": "浏览器下方",
"ui.history_edge_hint": "双击边缘",
+18 -1
View File
@@ -2549,7 +2549,8 @@ pub struct Document {
pub visibility: Visibility,
}
/// Items hidden or shown one by one. Saved with the design, but not an undo step.
/// The browser's view of a design: items and folders hidden or shown, sketch profiles and
/// dimensions shown, bodies locked. Saved with the design, but not an undo step.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct Visibility {
@@ -2566,6 +2567,18 @@ pub struct Visibility {
/// Assembly joints by id: their glyphs are not drawn (they still constrain and move).
#[serde(skip_serializing_if = "Vec::is_empty")]
pub hidden_joints: Vec<u64>,
/// The browser's Origin folder is hidden (`None`: the app's preference decides).
#[serde(skip_serializing_if = "Option::is_none")]
pub origin_hidden: Option<bool>,
/// Finished sketches whose closed profiles are not shaded, by feature id.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub hidden_profiles: Vec<u64>,
/// Finished sketches whose dimensions are shown, by feature id.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub shown_dimensions: Vec<u64>,
/// Bodies locked in the browser (no move or delete), by name.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub locked_bodies: Vec<String>,
/// Browser folders and groups hidden themselves, by tree key: `<scope>/<folder>` or
/// `<scope>/g<group id>`, where the scope is `c0` (the design) or `o:<placement path>`
/// (`o:4/9/bodies`). Their items keep their own state: they are drawn again, as they were,
@@ -2583,6 +2596,10 @@ impl Visibility {
&& self.hidden_sketches.is_empty()
&& self.shown_sketches.is_empty()
&& self.hidden_joints.is_empty()
&& self.origin_hidden.is_none()
&& self.hidden_profiles.is_empty()
&& self.shown_dimensions.is_empty()
&& self.locked_bodies.is_empty()
&& self.hidden_folders.is_empty()
}
}
@@ -0,0 +1,7 @@
//! A design's `visibility` can also keep the rest of the browser's view of it: the Origin
//! folder's eye (`origin_hidden`), finished sketches whose profiles are not shaded or whose
//! dimensions are shown (`hidden_profiles`, `shown_dimensions`, sketch ids) and locked bodies
//! (`locked_bodies`, body names). Older designs need no transformation: without them profiles
//! are shaded, dimensions hidden and nothing is locked, as before, and the Origin follows the
//! Hide Origin by Default preference until the design records its own. The last release asks
//! for an update; it would ignore them and lose only that view.
+48 -5
View File
@@ -339,8 +339,11 @@ fn visibility(s: &mut Session, p: &Value) -> Result<Value> {
s.visibility.hidden_folders.retain(|k| !k.ends_with(&own) && !groups.iter().any(|g| k.ends_with(g.as_str())));
}
let v = &mut s.visibility;
if visible && str_(p, "folder") == Some("bodies") {
v.hidden_occurrences.clear();
match str_(p, "folder") {
Some("bodies") if visible => v.hidden_occurrences.clear(),
// Showing a whole folder shows the folder too.
Some("origin") if visible => v.origin_hidden = Some(false),
_ => {}
}
for it in &items {
match it {
@@ -675,7 +678,8 @@ fn rename_body(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad(cmd, e));
}
d.rename_body_keys(&old, name);
for b in s.visibility.hidden_bodies.iter_mut().filter(|b| **b == old) {
let v = &mut s.visibility;
for b in v.hidden_bodies.iter_mut().chain(v.locked_bodies.iter_mut()).filter(|b| **b == old) {
*b = name.to_string();
}
Ok(json!({"body": old, "name": name}))
@@ -1172,10 +1176,12 @@ mod tests {
// The browser's Sketches folder hidden: sketches shown one by one aren't drawn either,
// only the sketch being edited.
assert!(s.visibility.shown_sketches.contains(&floor));
assert!([floor, drain].iter().all(|id| !crate::view::sketch_drawn(&s, *id, false)));
run(&mut s, "browser.visibility", json!({"tree_folders": ["c0/sketches"], "visible": false}));
assert!([floor, drain].iter().all(|id| !crate::view::sketch_shown(&s, *id)));
s.active_sketch = Some(floor);
assert!(crate::view::sketch_drawn(&s, floor, false) && !crate::view::sketch_drawn(&s, drain, false));
assert!(crate::view::sketch_shown(&s, floor) && !crate::view::sketch_shown(&s, drain));
s.active_sketch = None;
run(&mut s, "browser.visibility", json!({"tree_folders": ["c0/sketches"], "visible": true}));
// Bodies (following a rename) and construction planes.
run(&mut s, "browser.visibility", json!({"items": [body.clone(), "Floor", "xy"], "visible": false}));
assert!(crate::view::scene(&s, &cam).meshes.is_empty());
@@ -1240,6 +1246,43 @@ mod tests {
assert!(s.execute("browser.rename_group", &json!({"group": first, "name": "Stale reference"})).is_err());
}
#[test]
fn the_browsers_view_is_saved_with_the_design() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10}));
let sketch = run(&mut s, "sketch.create", json!({"plane": "XY"}))["sketch"].as_u64().unwrap();
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [20, 0], "p1": [30, 10]}));
run(&mut s, "sketch.finish", json!({}));
let body = names(&s)[0].clone();
s.mark_saved();
let undo = s.undo.len();
assert!(crate::view::sketch_shown(&s, sketch));
// The folders' eyes, a sketch's profiles and dimensions and a lock: view state to save.
let v = &mut s.visibility;
v.origin_hidden = Some(true);
v.hidden_folders.push("c0/sketches".into());
v.hidden_profiles.push(sketch);
v.shown_dimensions.push(sketch);
v.locked_bodies.push(body.clone());
assert!(s.is_dirty() && s.undo.len() == undo, "a change to save, not an undo step");
assert!(!crate::view::sketch_shown(&s, sketch), "the hidden Sketches folder hides an unused sketch");
run(&mut s, "body.rename", json!({"body": body, "name": "Locked"}));
assert_eq!(s.visibility.locked_bodies, vec!["Locked".to_string()]);
// Saved and opened again, the design brings all of it back, with nothing to save.
let text = s.design().to_json();
let opened = Session::new(solidcraft_doc::Document::from_json(&text).unwrap());
assert_eq!(opened.visibility, s.visibility);
assert!(!opened.is_dirty());
assert!(!crate::view::sketch_shown(&opened, sketch));
// Showing a whole folder shows the folder itself.
run(&mut s, "browser.visibility", json!({"folder": "origin", "visible": true}));
run(&mut s, "browser.visibility", json!({"folder": "sketches", "visible": true}));
assert_eq!((s.visibility.origin_hidden, s.visibility.hidden_folders.is_empty()), (Some(false), true));
// A design that never touched the Origin's eye leaves it to the app.
let plain = solidcraft_doc::Document::from_json(&Session::default().design().to_json()).unwrap();
assert!(plain.visibility.is_empty() && plain.visibility.origin_hidden.is_none());
}
#[test]
fn groups_hold_items_and_follow_renames() {
let mut s = Session::default();
+10 -21
View File
@@ -105,28 +105,23 @@ impl Default for Palette {
/// joints and moves place them, and the sketches the view draws (not ones used by a feature,
/// hidden ones, or ones in hidden components). What Home, Fit and the orbit pivot frame.
pub fn bounds(s: &Session) -> Aabb3 {
visible_bounds(s, true)
bounds_by(s, |body| body.mesh_bounds())
}
/// [`bounds`], with the browser's Sketches folder shown (`sketches`) or hidden.
pub fn visible_bounds(s: &Session, sketches: bool) -> Aabb3 {
bounds_by(s, sketches, |body| body.mesh_bounds())
}
/// [`visible_bounds`] without meshing anything: a body not meshed yet counts with its outline
/// [`bounds`] without meshing anything: a body not meshed yet counts with its outline
/// ([`solidcraft_kernel::Body::outline_bounds`]), which a face curving out past all of its edges
/// can exceed. Frames a design whose bodies are still being meshed.
pub fn unmeshed_bounds(s: &Session, sketches: bool) -> Aabb3 {
bounds_by(s, sketches, |body| body.cached_mesh().map(|m| m.bounds()).unwrap_or_else(|| body.outline_bounds()))
pub fn unmeshed_bounds(s: &Session) -> Aabb3 {
bounds_by(s, |body| body.cached_mesh().map(|m| m.bounds()).unwrap_or_else(|| body.outline_bounds()))
}
fn bounds_by(s: &Session, sketches: bool, of: impl Fn(&solidcraft_doc::ModelBody) -> Aabb3) -> Aabb3 {
fn bounds_by(s: &Session, of: impl Fn(&solidcraft_doc::ModelBody) -> Aabb3) -> Aabb3 {
let st = s.world_state();
let mut b = Aabb3::EMPTY;
for body in st.bodies.iter().filter(|x| s.body_visible(&x.name)) {
b = b.union(&of(body));
}
for ss in st.sketches.iter().filter(|x| sketch_drawn(s, x.feature, sketches)) {
for ss in st.sketches.iter().filter(|x| sketch_shown(s, x.feature)) {
// All four corners: on a tilted plane two opposite ones don't span the rectangle.
if let Some((lo, hi)) = ss.sketch.bounds() {
for p in [lo, hi, solidcraft_geom::Vec2::new(lo.x, hi.y), solidcraft_geom::Vec2::new(hi.x, lo.y)] {
@@ -643,21 +638,15 @@ impl SectionIndex {
}
}
/// Is a sketch drawn? The active one is; others unless hidden. Finished sketches are hidden
/// once a feature uses them, by default, unless shown one by one.
/// Is a sketch drawn? The sketch being edited always is; otherwise not when hidden, nor in a
/// hidden component, Sketches folder or group (even one shown on its own), and one used by a
/// feature only when shown on its own.
pub fn sketch_shown(s: &Session, id: u64) -> bool {
sketch_drawn(s, id, true)
}
/// Is a sketch drawn, with sketches shown (`folder`) or hidden? The sketch being edited always
/// is; otherwise not when hidden, nor in a hidden component, Sketches folder or group (even one
/// shown on its own), and one used by a feature only when shown on its own.
pub fn sketch_drawn(s: &Session, id: u64, folder: bool) -> bool {
let v = &s.visibility;
if s.active_sketch == Some(id) {
return true;
}
if !folder || v.hidden_sketches.contains(&id) || !sketch_component_visible(s, id) || s.feature_folder_hidden(id, "sketches") {
if v.hidden_sketches.contains(&id) || !sketch_component_visible(s, id) || s.feature_folder_hidden(id, "sketches") {
return false;
}
v.shown_sketches.contains(&id) || !sketch_consumed(s, id)
+11 -10
View File
@@ -140,7 +140,7 @@ impl OccMove {
// ---------------------------------------------------------------------------------------------
/// Is a sketch shown itself (its eye)? A hidden Sketches folder or component still keeps it out
/// of the viewport (`solidcraft_engine::view::sketch_drawn`).
/// of the viewport (`solidcraft_engine::view::sketch_shown`).
pub fn sketch_visible(app: &SolveApp, id: u64) -> bool {
if app.session.visibility.hidden_sketches.contains(&id) {
return false;
@@ -1303,10 +1303,10 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &Actio
&Row {
depth,
fold: Some(open),
eye: Some(app.ui.show_origin),
eye: Some(app.origin_shown()),
icon: "origin",
label: "Origin",
dim: !app.ui.show_origin,
dim: !app.origin_shown(),
mark: if items.iter().any(|(_, _, thing)| lit(thing) != (false, false)) { Mark::Branch } else { Mark::None },
..Default::default()
},
@@ -1315,7 +1315,7 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &Actio
toggle(app, key, false);
}
if r.eye {
app.ui.show_origin = !app.ui.show_origin;
app.set_origin_shown(!app.origin_shown());
}
if let Some(p) = r.secondary {
crate::context_menu::open_for(app, p, Target::Origin);
@@ -1336,7 +1336,7 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &Actio
ui,
ui.id().with(("o", k)),
// Faded when hidden itself or with the whole Origin.
&Row { depth: depth + 1, eye: Some(visible), icon, label, selected, dim: !visible || !app.ui.show_origin, mark, ..Default::default() },
&Row { depth: depth + 1, eye: Some(visible), icon, label, selected, dim: !visible || !app.origin_shown(), mark, ..Default::default() },
);
if r.eye {
if visible {
@@ -1723,7 +1723,7 @@ fn entries(app: &SolveApp, comp: u64, folder: &str) -> Vec<Entry> {
visible: !app.session.visibility.hidden_bodies.contains(&b.name),
selected: sel.iter().any(|x| matches!(x, Sel::Body { name } if *name == b.name)),
color: None,
locked: app.ui.locked_bodies.contains(&b.name),
locked: app.session.visibility.locked_bodies.contains(&b.name),
sel: Some(Sel::Body { name: b.name.clone() }),
target: Some(Target::Body { name: b.name.clone() }),
bodies: vec![b.name.clone()],
@@ -2232,7 +2232,7 @@ pub fn dims_overlay(app: &SolveApp, ctx: &egui::Context) {
use solidcraft_engine::geom::Vec2;
use solidcraft_engine::sketch::{DimFrame, chain_centres, default_text, dim_frame, dim_layout_reaching, dim_reach};
let Some(rect) = app.viewport.rect else { return };
if app.ui.shown_dims.is_empty() {
if app.session.visibility.shown_dimensions.is_empty() {
return;
}
let tk = Tokens::get();
@@ -2240,10 +2240,11 @@ pub fn dims_overlay(app: &SolveApp, ctx: &egui::Context) {
let painter = ctx.layer_painter(egui::LayerId::background()).with_clip_rect(rect);
let st = app.session.world_state();
for id in app
.ui
.shown_dims
.session
.visibility
.shown_dimensions
.iter()
.filter(|id| app.session.active_sketch != Some(**id) && solidcraft_engine::view::sketch_drawn(&app.session, **id, app.ui.show_sketches))
.filter(|id| app.session.active_sketch != Some(**id) && solidcraft_engine::view::sketch_shown(&app.session, **id))
{
let Some(ss) = st.sketch(*id) else { continue };
let sk = &ss.sketch;
+1 -1
View File
@@ -12,7 +12,7 @@ fn navigating_and_selecting_reuse_placements_but_rows_read_live_view_state() {
h.app.cam.yaw += 0.25;
h.app.run("select.set", json!({"items":[Sel::Body{name:"Body1".into()}]})).unwrap();
h.app.session.visibility.hidden_bodies.push("Body1".into());
h.app.ui.locked_bodies.push("Body1".into());
h.app.session.visibility.locked_bodies.push("Body1".into());
let after = super::model_placement(&mut h.app, &[occurrence]).unwrap();
assert!(Arc::ptr_eq(&first, &after), "view-only changes resolved the same placement again");
let rows = super::entries(&h.app, component, "bodies");
+23 -18
View File
@@ -577,7 +577,7 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {
if app.session.section.is_some() {
v.push(act("ui.unsection", "Remove Section", "section"));
}
v.push(act("ui.origin", if app.ui.show_origin { "Hide Origin" } else { "Show Origin" }, "origin"));
v.push(act("ui.origin", if app.origin_shown() { "Hide Origin" } else { "Show Origin" }, "origin"));
return v;
}
if !sel.is_empty() {
@@ -596,7 +596,7 @@ fn body_items(app: &SolveApp, bodies: &[String], browser: bool) -> Vec<Item> {
let names = json!(bodies);
let all_hidden = bodies.iter().all(|b| app.session.visibility.hidden_bodies.contains(b));
let one = bodies.len() == 1;
let locked = bodies.iter().all(|b| app.ui.locked_bodies.contains(b));
let locked = bodies.iter().all(|b| app.session.visibility.locked_bodies.contains(b));
let items = json!(bodies.iter().map(|b| json!({"type": "body", "name": b})).collect::<Vec<_>>());
let mut v = vec![
act("ui.moveBodies", "Move/Copy", "move").key("M").with(json!({ "bodies": names })).on(!locked),
@@ -633,8 +633,8 @@ fn body_items(app: &SolveApp, bodies: &[String], browser: bool) -> Vec<Item> {
fn sketch_items(app: &SolveApp, id: u64) -> Vec<Item> {
let visible = crate::browser::sketch_visible(app, id);
let profiles = !app.ui.hidden_profiles.contains(&id);
let dims = app.ui.shown_dims.contains(&id);
let profiles = !app.session.visibility.hidden_profiles.contains(&id);
let dims = app.session.visibility.shown_dimensions.contains(&id);
let editing = app.session.active_sketch == Some(id);
let has_profiles = app.session.world_state().sketch(id).is_some_and(|s| !s.profiles.is_empty());
vec![
@@ -1074,18 +1074,20 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
app.session.visibility.hidden_sketches.clear();
// Hidden folders and groups too, so everything really shows.
app.session.visibility.hidden_folders.clear();
app.ui.show_sketches = true;
}
"ui.isolate" => {
app.session.visibility.hidden_bodies =
app.session.world_state().bodies.iter().map(|b| b.name.clone()).filter(|b| !bodies.contains(b)).collect();
}
"ui.lock" => {
let locked = bodies.iter().all(|b| app.ui.locked_bodies.contains(b));
let locked = bodies.iter().all(|b| app.session.visibility.locked_bodies.contains(b));
if locked {
app.ui.locked_bodies.retain(|b| !bodies.contains(b));
app.session.visibility.locked_bodies.retain(|b| !bodies.contains(b));
} else {
app.ui.locked_bodies.extend(bodies.into_iter().filter(|b| !app.ui.locked_bodies.contains(b)).collect::<Vec<_>>());
app.session
.visibility
.locked_bodies
.extend(bodies.into_iter().filter(|b| !app.session.visibility.locked_bodies.contains(b)).collect::<Vec<_>>());
}
}
"ui.moveBodies" => {
@@ -1161,7 +1163,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
}
}
"ui.tangentChain" => tangent_chain(app),
"ui.origin" => app.ui.show_origin = !app.ui.show_origin,
"ui.origin" => app.set_origin_shown(!app.origin_shown()),
"ui.clear" => drop(app.run("select.clear", json!({}))),
"ui.unsection" => {
app.tree.hidden_section = None;
@@ -1190,19 +1192,19 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
}
"ui.sketchDims" => {
if let Some(id) = id_of(&p, "sketch") {
if app.ui.shown_dims.contains(&id) {
app.ui.shown_dims.retain(|x| *x != id);
if app.session.visibility.shown_dimensions.contains(&id) {
app.session.visibility.shown_dimensions.retain(|x| *x != id);
} else {
app.ui.shown_dims.push(id);
app.session.visibility.shown_dimensions.push(id);
}
}
}
"ui.sketchProfile" => {
if let Some(id) = id_of(&p, "sketch") {
if app.ui.hidden_profiles.contains(&id) {
app.ui.hidden_profiles.retain(|x| *x != id);
if app.session.visibility.hidden_profiles.contains(&id) {
app.session.visibility.hidden_profiles.retain(|x| *x != id);
} else {
app.ui.hidden_profiles.push(id);
app.session.visibility.hidden_profiles.push(id);
}
}
}
@@ -1274,7 +1276,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
}
}
"ui.originAll" => {
app.ui.show_origin = true;
app.set_origin_shown(true);
app.session.visibility.hidden_origin.retain(|h| !["O", "X", "Y", "Z", "XY", "XZ", "YZ"].contains(&h.as_str()));
}
"ui.originPart" => {
@@ -1498,7 +1500,10 @@ pub(crate) fn commit_rename(app: &mut SolveApp, r: &Rename) {
return;
}
match &r.what {
RenameWhat::Body(old) => drop(app.run_heavy("body.rename", json!({ "body": old, "name": name }))),
RenameWhat::Body(old) => {
// The command renames the body where it is hidden or locked too.
drop(app.run_heavy("body.rename", json!({ "body": old, "name": name })));
}
RenameWhat::Feature(f) => drop(app.run("timeline.rename", json!({ "feature": f, "name": name }))),
RenameWhat::Component(c) => drop(app.run("component.rename", json!({ "component": c, "name": name }))),
RenameWhat::Group(g) => crate::browser::group_action(app, "ui.renameGroup", &json!({ "group": g, "name": name })),
@@ -2083,7 +2088,7 @@ mod tests {
assert!(list["radial"].as_array().unwrap().is_empty());
assert!(list["items"].as_array().unwrap().iter().any(|item| item["id"] == "ui.origin" && item["enabled"] == true));
h.step(&json!({"click":{"handle":"menu:ui.origin"}})).unwrap();
assert!(!h.app.ui.show_origin && h.app.viewport.context_menu.is_none(), "the ordinary menu must execute Hide Origin and close");
assert!(!h.app.origin_shown() && h.app.viewport.context_menu.is_none(), "the ordinary menu must execute Hide Origin and close");
h.call("ui.prefs", json!({"radial_context_menu":true}));
h.step(&json!({"click":point,"button":"right"})).unwrap();
assert_eq!(describe(&h.app)["radial"].as_array().unwrap().len(), DIRS);
+47 -9
View File
@@ -85,6 +85,24 @@ fn wrap(r: Result<Value, String>) -> Outcome {
}
}
/// The design's own Sketches folder (`Visibility::hidden_folders`), which `showSketches` sets.
const SKETCHES_FOLDER: &str = "c0/sketches";
/// `UiState` as `ui.inspect` and `ui.set` report it, with the browser's view of the design
/// (kept in the session) under the names the UI state used to give it.
fn ui_state(app: &SolveApp) -> Value {
let mut u = serde_json::to_value(&app.ui).unwrap_or_default();
let v = &app.session.visibility;
if let Some(o) = u.as_object_mut() {
o.insert("showOrigin".into(), json!(app.origin_shown()));
o.insert("showSketches".into(), json!(!app.session.folder_hidden(SKETCHES_FOLDER)));
o.insert("hiddenProfiles".into(), json!(v.hidden_profiles));
o.insert("shownDims".into(), json!(v.shown_dimensions));
o.insert("lockedBodies".into(), json!(v.locked_bodies));
}
u
}
fn key_from(name: &str) -> Option<egui::Key> {
egui::Key::from_name(name).or(match name.to_ascii_lowercase().as_str() {
"enter" | "return" => Some(egui::Key::Enter),
@@ -305,7 +323,7 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
"ui.messages" => ok(crate::messages::control(app, p)),
"ui.inspect" => ok(json!({
"render": crate::render_workspace::inspect_state(app),
"ui": serde_json::to_value(&app.ui).unwrap_or_default(),
"ui": ui_state(app),
"visibility": app.session.visibility,
"viewport": app.viewport.rect.map(|r| json!([r.left(), r.top(), r.width(), r.height()])),
"camera": app.cam,
@@ -354,26 +372,46 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
}
"ui.set" => {
// What is hidden lives in the session (`browser.visibility`); `ui.set` still sets it.
const VIS: [(&str, &str); 6] = [
const VIS: [(&str, &str); 9] = [
("hiddenBodies", "hidden_bodies"),
("hiddenOrigin", "hidden_origin"),
("hiddenSketches", "hidden_sketches"),
("shownSketches", "shown_sketches"),
("hiddenJoints", "hidden_joints"),
("hiddenProfiles", "hidden_profiles"),
("shownDims", "shown_dimensions"),
("lockedBodies", "locked_bodies"),
("hiddenFolders", "hidden_folders"),
];
let mut cur = serde_json::to_value(&app.ui).unwrap_or(json!({}));
let mut vis = serde_json::to_value(&app.session.visibility).unwrap_or(json!({}));
let mut sketches = None;
if let (Some(o), Some(vo), Some(src)) = (cur.as_object_mut(), vis.as_object_mut(), p.as_object()) {
for (k, v) in src {
match VIS.iter().find(|(camel, _)| camel == k) {
Some((_, snake)) => vo.insert(snake.to_string(), v.clone()),
None => o.insert(k.clone(), v.clone()),
let shown = |v: &Value| v.as_bool().map(|b| json!(!b)).unwrap_or_else(|| v.clone());
match (VIS.iter().find(|(camel, _)| camel == k), k.as_str()) {
(Some((_, snake)), _) => vo.insert(snake.to_string(), v.clone()),
(None, "showOrigin") => vo.insert("origin_hidden".into(), shown(v)),
(None, "showSketches") => {
sketches = Some(v.as_bool().ok_or_else(|| "`showSketches` must be true or false".to_string()));
None
}
_ => o.insert(k.clone(), v.clone()),
};
}
}
let sketches = match sketches.transpose() {
Ok(s) => s,
Err(e) => return err(e),
};
match (serde_json::from_value::<crate::UiState>(cur), serde_json::from_value::<solidcraft_engine::Visibility>(vis)) {
(Ok(mut u), Ok(v)) => {
(Ok(mut u), Ok(mut v)) => {
if let Some(shown) = sketches {
v.hidden_folders.retain(|k| k != SKETCHES_FOLDER);
if !shown {
v.hidden_folders.push(SKETCHES_FOLDER.to_string());
}
}
if (u.tab == "RENDER") != crate::render_workspace::active(app)
&& let Err(e) = crate::render_workspace::enter(app, u.tab == "RENDER")
{
@@ -382,7 +420,7 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->
u.ribbon_context = app.ui.ribbon_context.clone();
app.ui = u;
app.session.visibility = v;
ok(serde_json::to_value(&app.ui).unwrap_or_default())
ok(ui_state(app))
}
(Err(e), _) | (_, Err(e)) => err(e),
}
@@ -1154,12 +1192,12 @@ mod tests {
assert!(shot(&mut app, json!({})) == no_grid);
assert!(shot(&mut app, json!({"grid": true})) == all);
// With the Origin off too it has neither; `axes: true` puts the axes back.
app.ui.show_origin = false;
app.set_origin_shown(false);
assert!(shot(&mut app, json!({})) == bare);
assert!(shot(&mut app, json!({"axes": true})) == no_grid);
// The Origin and the Grid back on: the first picture again.
app.ui.show_grid = true;
app.ui.show_origin = true;
app.set_origin_shown(true);
assert!(shot(&mut app, json!({})) == all);
let _ = std::fs::remove_dir_all(&dir);
}
+1 -1
View File
@@ -22,7 +22,7 @@ pub struct Pending {
pub fn selection_params(app: &SolveApp) -> Value {
use solidcraft_engine::Sel;
let mut items: Vec<Sel> = Vec::new();
for s in app.session.selection.iter().filter(|s| !matches!(s, Sel::Body { name } if app.ui.locked_bodies.contains(name))) {
for s in app.session.selection.iter().filter(|s| !matches!(s, Sel::Body { name } if app.session.visibility.locked_bodies.contains(name))) {
// A MidPoint glyph shared by lines whose midpoints meet removes every constraint it
// shows, and the point they shared when nothing else holds it.
let group = match s {
+2 -2
View File
@@ -75,7 +75,7 @@ fn every_move_type_has_somewhere_to_put_its_value_box() {
#[test]
fn point_to_point_takes_the_origin_point() {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.app.run("solid.box", json!({"length": 20, "width": 20, "height": 20})).unwrap();
h.app.run("solid.move", json!({"bodies": ["Body1"], "translate": ["30 mm", "20 mm", "0 mm"]})).unwrap();
h.app.cam.distance = 200.0;
@@ -166,7 +166,7 @@ fn component_selection_fixture() -> crate::scenario::Harness {
}
h.app.ui.show_browser = false;
h.app.ui.show_timeline = false;
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap();
// Keep the selection rectangle to the right of the Move dialog.
h.step(&json!({"call": "ui.camera", "params": {"target": [0, 0, 0], "distance": 250}})).unwrap();
+31 -15
View File
@@ -28,13 +28,11 @@ pub struct DocSlot {
occurrence_move: Option<crate::browser::OccMove>,
}
/// The per-design part of the UI state (what is hidden, shown or locked).
/// The per-design part of the UI state the session doesn't keep (what is hidden, shown or locked
/// is in the session's `visibility`, saved with the design).
#[derive(Clone, Debug, Default)]
struct DocView {
render: crate::render_workspace::ViewState,
hidden_profiles: Vec<u64>,
shown_dims: Vec<u64>,
locked_bodies: Vec<String>,
}
impl DocSlot {
@@ -82,13 +80,7 @@ impl Documents {
}
fn take_view(app: &mut SolveApp) -> DocView {
let u = &mut app.ui;
DocView {
render: std::mem::take(&mut app.render_workspace.view),
hidden_profiles: std::mem::take(&mut u.hidden_profiles),
shown_dims: std::mem::take(&mut u.shown_dims),
locked_bodies: std::mem::take(&mut u.locked_bodies),
}
DocView { render: std::mem::take(&mut app.render_workspace.view) }
}
fn put_view(app: &mut SolveApp, v: DocView) {
@@ -96,10 +88,6 @@ fn put_view(app: &mut SolveApp, v: DocView) {
crate::render_workspace::invalidate_images(app);
crate::render_workspace::invalidate_scene(app);
crate::render_workspace::sync_backend(app);
let u = &mut app.ui;
u.hidden_profiles = v.hidden_profiles;
u.shown_dims = v.shown_dims;
u.locked_bodies = v.locked_bodies;
}
/// Put `slot` into the app and return what was there.
@@ -1233,6 +1221,34 @@ mod tests {
assert!(!a.session.auto_project, "a design adopted over a blank one");
}
/// Hide Origin by Default hides the Origin of designs that don't keep its eye; a design that
/// does keeps it, along with the rest of the browser's view, in its tab and in its file.
#[test]
fn the_browsers_view_follows_each_design_and_the_origin_preference() {
let mut a = app();
assert!(a.origin_shown());
a.preferences.hide_origin = true;
assert!(!a.origin_shown() && !a.session.is_dirty(), "the preference is not a change to the design");
let mut b = app();
b.load_prefs(&a.prefs());
assert!(b.preferences.hide_origin && !b.origin_shown(), "the preference is kept between runs");
// This design shows its Origin and locks its body and hides its Sketches folder.
a.run("solid.box", json!({"length": 10, "width": 10, "height": 10})).unwrap();
a.set_origin_shown(true);
a.session.visibility.locked_bodies.push("Body1".into());
a.session.visibility.hidden_folders.push("c0/sketches".into());
new_design(&mut a);
assert!(!a.origin_shown() && a.session.visibility.is_empty(), "a new design follows the preference");
switch(&mut a, 0);
assert!(a.origin_shown() && a.session.visibility.locked_bodies == ["Body1"] && a.session.folder_hidden("c0/sketches"));
// Opened again, the design's own Origin setting wins over the preference.
let text = a.session.design().to_json();
let mut c = app();
c.preferences.hide_origin = true;
c.session = Session::new(solidcraft_engine::doc::Document::from_json(&text).unwrap());
assert!(c.origin_shown() && c.session.visibility == a.session.visibility);
}
/// #1205: Units of new designs apply to the empty design a launch shows, to New while that
/// design is still empty, to `file.new`, and to the blank design left when the last tab closes.
/// A design that already has features keeps its units.
@@ -526,7 +526,7 @@ fn a_body_renamed_in_the_browser_keeps_the_pattern_after_it() {
] {
h.app.run(id, p).unwrap();
}
h.app.ui.locked_bodies.push("Body1".into());
h.app.session.visibility.locked_bodies.push("Body1".into());
h.app.apply_off_thread = Some(Duration::ZERO);
crate::context_menu::start_rename(&mut h.app, crate::context_menu::RenameWhat::Body("Body1".into()), egui::pos2(0.0, 0.0));
h.frames(2);
@@ -543,5 +543,5 @@ fn a_body_renamed_in_the_browser_keeps_the_pattern_after_it() {
assert_eq!(names(&h), ["Plate"]);
let kept = before.zip(mesh(&h)).is_some_and(|(a, b)| std::sync::Arc::ptr_eq(&a, &b));
assert!(kept, "no feature computed again");
assert_eq!(h.app.ui.locked_bodies, ["Plate"]);
assert_eq!(h.app.session.visibility.locked_bodies, ["Plate"]);
}
@@ -33,7 +33,7 @@ fn last_hole_direction(h: &Harness) -> Vec3 {
#[test]
fn a_hole_picked_under_a_thin_plate_on_xy_drills_up_into_it_as_its_arrow_shows() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane": "XY", "name": "S"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [150, 100]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
@@ -63,7 +63,7 @@ fn a_hole_picked_under_a_thin_plate_on_xy_drills_up_into_it_as_its_arrow_shows()
#[test]
fn a_hole_picked_on_a_round_bar_drills_to_its_axis_as_its_arrow_shows() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.cylinder", json!({"radius": 10, "height": 40})).unwrap();
h.step(&json!({"call": "ui.view", "params": {"view": "front"}})).unwrap();
h.settle();
@@ -94,7 +94,7 @@ fn a_hole_picked_on_a_round_bar_drills_to_its_axis_as_its_arrow_shows() {
#[test]
fn flip_drills_holes_at_sketch_points_the_other_way() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
// A point on a plane through the middle of the block: by itself the hole goes down from the top.
h.app.run("sketch.create", json!({"plane": {"origin": [0, 0, 10], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}, "name": "P"})).unwrap();
+1 -1
View File
@@ -26,7 +26,7 @@ fn block() -> Harness {
/// The block with the preferences a new installation has.
fn block_as_installed() -> Harness {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("solid.hole", json!({"position": [10, 10, 20], "diameter": 10, "name": "Bore"})).unwrap();
h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap();
@@ -27,7 +27,7 @@ fn block_with_circle() -> (Harness, Vec3) {
/// sketch `sketch` (`sketch.create`'s parameters) makes. Returns the circle centre in the world.
fn block_and_circle_on(sketch: Value, at: [f64; 2]) -> (Harness, Vec3) {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("sketch.create", sketch).unwrap();
h.app.run("sketch.circle.center", json!({"center": at, "radius": 4})).unwrap();
@@ -279,7 +279,7 @@ fn select_other_keeps_the_face_as_picked_beside_many_snapped_points() {
// More points under the cursor than Select Other lists of one kind: the snapped places are
// capped as points, and the face as picked keeps its row.
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("sketch.create", json!({"plane": {"face": [20, 15, 20]}})).unwrap();
let many = crate::select_other::MAX_PER_KIND + 4;
@@ -304,7 +304,7 @@ fn select_other_keeps_the_face_as_picked_beside_many_snapped_points() {
/// when given. Returns the corner, then the circle centre, in the world.
fn block_with_lettering(circle: Option<f64>) -> (Harness, Vec3, Option<Vec3>) {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("sketch.create", json!({"plane": {"face": [20, 15, 20]}})).unwrap();
h.app.run("sketch.text", json!({"text": "L", "at": [5, 5], "height": 10})).unwrap();
@@ -381,7 +381,7 @@ fn a_single_hole_snaps_only_to_points_its_sketch_shows() {
// where it was clicked while the sketch hides it (Show Projected off).
for shown in [true, false] {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("sketch.create", json!({"plane": {"face": [20, 15, 20]}})).unwrap();
h.app.run("sketch.options", json!({"show_projected": shown})).unwrap();
@@ -412,7 +412,7 @@ fn a_single_hole_snaps_only_to_points_its_sketch_shows() {
// Show Points off only hides the markers of the sketch being edited (a finished sketch draws
// none): its circle's centre is still snapped to.
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
h.app.run("sketch.create", json!({"plane": {"face": [20, 15, 20]}})).unwrap();
h.app.run("sketch.options", json!({"show_points": false})).unwrap();
@@ -461,7 +461,7 @@ fn rows_named(list: &Value, prefix: &str) -> usize {
/// points within 0.1 mm of `at` in the sketch `sketch.create` makes with `sketch`.
fn cylinder_with_cluster(sketch: Value, at: [f64; 2], view: &str) -> Cluster {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.cylinder", json!({"radius": 15, "height": 20})).unwrap();
h.app.run("sketch.create", sketch).unwrap();
let many = 3 * crate::select_other::MAX_PER_KIND;
+1 -1
View File
@@ -19,7 +19,7 @@ fn screen(h: &mut Harness, p: Vec3) -> [f64; 2] {
/// A 50 × 40 × 10 plate from the origin, seen from the top.
fn plate() -> Harness {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 50, "width": 40, "height": 10, "corner": [0, 0, 0]})).unwrap();
h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap();
h.settle();
+3 -3
View File
@@ -81,14 +81,14 @@ fn every_menu_label_is_in_the_english_catalog() {
// The labels that depend on state, so their other branch is seen too.
let names: Vec<String> = app.session.model.state().bodies.iter().map(|b| b.name.clone()).collect();
app.ui.show_origin = false;
app.set_origin_shown(false);
take(&app, &mut seen);
for name in &names {
app.ui.locked_bodies.push(name.clone());
app.session.visibility.locked_bodies.push(name.clone());
app.session.visibility.hidden_bodies.push(name.clone());
}
take(&app, &mut seen);
app.ui.locked_bodies.clear();
app.session.visibility.locked_bodies.clear();
app.session.visibility.hidden_bodies.clear();
take(&app, &mut seen);
+12 -22
View File
@@ -287,9 +287,7 @@ pub struct UiState {
pub show_browser: bool,
pub show_timeline: bool,
pub show_grid: bool,
pub show_origin: bool,
pub perspective: bool,
pub show_sketches: bool,
pub palette_open: bool,
/// Dark theme (the default); a preference kept between runs.
pub dark: bool,
@@ -303,12 +301,6 @@ pub struct UiState {
pub ground_shadow: bool,
/// The world's up axis (Z or Y; #3): the camera, axis view, home view and ground follow it.
pub up_axis: solidcraft_engine::render::UpAxis,
/// Sketches whose closed profiles are not shaded.
pub hidden_profiles: Vec<u64>,
/// Finished sketches whose dimensions are shown.
pub shown_dims: Vec<u64>,
/// Bodies locked in the browser (no move or delete).
pub locked_bodies: Vec<String>,
/// The agent cursor: shown, speed, follow camera (#35).
pub agent_cursor: agent_cursor::Settings,
}
@@ -323,9 +315,7 @@ impl Default for UiState {
show_browser: true,
show_timeline: true,
show_grid: true,
show_origin: true,
perspective: false,
show_sketches: true,
palette_open: false,
dark: true,
pick_off: Vec::new(),
@@ -333,9 +323,6 @@ impl Default for UiState {
visual_style: 0,
ground_shadow: true,
up_axis: Default::default(),
hidden_profiles: Vec::new(),
shown_dims: Vec::new(),
locked_bodies: Vec::new(),
agent_cursor: Default::default(),
}
}
@@ -862,14 +849,6 @@ impl SolveApp {
}
// Curves drawn in construction (or centerline) mode take that line type.
sketch_palette::apply_mode(self, id, v);
// Locks follow a body's rename, from the rename box or anywhere else.
if id == "body.rename"
&& let (Some(old), Some(new)) = (v.get("body").and_then(Value::as_str), v.get("name").and_then(Value::as_str))
{
for b in self.ui.locked_bodies.iter_mut().filter(|b| *b == old) {
*b = new.to_string();
}
}
}
self.finish_command(id, &r);
r
@@ -1263,11 +1242,22 @@ impl SolveApp {
v
}
/// Is the browser's Origin folder shown? The design keeps it once it is toggled; until then
/// the Hide Origin by Default preference decides.
pub fn origin_shown(&self) -> bool {
!self.session.visibility.origin_hidden.unwrap_or(self.preferences.hide_origin)
}
/// Show or hide the browser's Origin folder (saved with the design).
pub fn set_origin_shown(&mut self, on: bool) {
self.session.visibility.origin_hidden = Some(!on);
}
/// Is the origin widget shown? Origin planes and axes are drawn and pickable. While a dialog
/// picks a plane ([`SolveApp::picking_plane`]) the Origin is always shown, drawn through the
/// model (a plane inside a body stays visible), even when the browser hides it.
pub fn origin_visible(&self) -> bool {
self.ui.show_origin || self.picking_plane()
self.origin_shown() || self.picking_plane()
}
/// Is Create Sketch open, waiting for its plane?
+2 -2
View File
@@ -14,7 +14,7 @@ fn result(h: &Harness) -> &Value {
fn vertex_measurement(a: [f64; 3], b: [f64; 3]) -> Harness {
let mut h = Harness::new();
h.app.home.open = false;
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.ui.show_browser = false;
h.app.run("solid.box", json!({"length":3,"width":4,"height":12,"corner":[-3,0,-12],"body_name":"Box"})).unwrap();
h.app.session.selection = [a, b].into_iter().map(|p| Sel::Vertex { body: "Box".into(), point: p.into() }).collect();
@@ -61,7 +61,7 @@ fn measure_dialog_shows_the_obtuse_corner_of_selected_lines() {
fn measurement_axis_distances_follow_the_upstream_centre_min_and_max_choices() {
let mut h = Harness::new();
h.app.home.open = false;
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.ui.show_browser = false;
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
let mut items = Vec::new();
+3 -3
View File
@@ -59,7 +59,7 @@ fn empty_space_offers_view_items_and_greys_out_undo() {
assert!(!context_menu::radial_items(&app)[0].enabled, "no command to repeat yet");
// Hide Origin toggles.
context_menu::run_item(&mut app, &find(&items, "Hide Origin"), pos2(0.0, 0.0));
assert!(!app.ui.show_origin);
assert!(!app.origin_shown());
}
#[test]
@@ -240,7 +240,7 @@ fn sketch_menu_hides_and_moves_to_another_plane() {
context_menu::run_item(&mut app, &find(&items, "Show/Hide"), pos2(0.0, 0.0));
assert_eq!(crate::browser::sketch_visible(&app, id), !vis);
context_menu::run_item(&mut app, &find(&items, "Show Dimension"), pos2(0.0, 0.0));
assert_eq!(app.ui.shown_dims, vec![id]);
assert_eq!(app.session.visibility.shown_dimensions, vec![id]);
assert!(find(&context_menu::items(&app, &t), "Hide Dimension").enabled);
context_menu::run_item(&mut app, &find(&items, "Edit Sketch"), pos2(0.0, 0.0));
assert_eq!(app.session.active_sketch, Some(id));
@@ -348,7 +348,7 @@ fn pick_runs_an_item_of_the_open_menu() {
assert!(context_menu::pick(&mut app, "Undo").is_err(), "disabled");
assert!(context_menu::pick(&mut app, "ui.origin").is_ok());
assert!(app.viewport.context_menu.is_none(), "a pick closes the menu");
assert!(!app.ui.show_origin);
assert!(!app.origin_shown());
}
#[test]
+1 -1
View File
@@ -1111,7 +1111,7 @@ mod tests {
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.app.session = solidcraft_engine::Session::new(doc);
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h
}
+2 -2
View File
@@ -12,7 +12,7 @@ fn assembly() -> SolveApp {
s.execute("solid.cylinder", &json!({"radius": 8, "height": 35, "base": [10, 10, 0], "operation": "new_body"})).unwrap();
s.execute("solid.sphere", &json!({"radius": 9, "center": [30, 25, 22]})).unwrap();
let mut app = SolveApp::new(s, crate::Services::default());
app.ui.show_origin = false;
app.set_origin_shown(false);
app
}
@@ -118,7 +118,7 @@ fn pick_timing_on_curved_models() {
scenes.push(("25 placed meshes", app, 0.6));
}
for (name, mut app, pitch) in scenes {
app.ui.show_origin = false;
app.set_origin_shown(false);
(app.cam.yaw, app.cam.pitch) = (0.6, pitch);
let st = app.session.world_state();
app.cam.fit(&st.bodies.iter().fold(solidcraft_engine::geom::Aabb3::EMPTY, |a, b| a.union(&b.mesh_bounds())));
+2
View File
@@ -591,6 +591,8 @@ 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_DESIGN => check("Move holes by clicking or dragging");
/// 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");
/// What a middle-button double-click in the view does: `home`, `fit` or `off`.
middle_double_click: String = "home".into(), PAGE_NAVIGATION;
/// Colour vision mode (#778): `off`, `protan`, `deutan` or `tritan`.
+2
View File
@@ -52,6 +52,8 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
setting::offer_stand_up(app, ui);
ui_kit::text(ui, app.tr("prefs.stand_up_note"), ui_kit::Text::Hint("stand_up"));
setting::extrude_auto_to_object(app, ui);
setting::hide_origin(app, ui);
ui_kit::text(ui, app.tr("ui.hide_origin_note"), ui_kit::Text::Hint("hide_origin"));
});
// The Hole command's own settings, under its name.
ui_kit::settings_section(ui, "create_hole", crate::i18n::tr_label("Create Hole"), |ui| {
+1 -1
View File
@@ -270,7 +270,7 @@ fn path_plane_click_retains_source_and_previews_then_edits_in_place() {
let duplicate = h.app.run("sketch.line3d", json!({"points":[[-30,0,0],[-20,0,0]]})).unwrap()["curves"][0].as_str().unwrap().to_string();
assert_eq!(wire, duplicate, "exercise duplicate curve ids in different sketches");
h.app.run("sketch.finish", json!({})).unwrap();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.settle();
h.call("ui.view", json!({"view":"home"}));
h.call("ui.view", json!({"view":"fit"}));
+2 -2
View File
@@ -581,7 +581,7 @@ fn clicked_render_workspace_saves_one_setup_and_restores_design_view() {
h.app.session.mark_saved();
h.frames(3);
let camera = h.app.cam;
let flags = (h.app.ui.show_grid, h.app.ui.show_origin, h.app.ui.visual_style, h.app.ui.perspective);
let flags = (h.app.ui.show_grid, h.app.origin_shown(), h.app.ui.visual_style, h.app.ui.perspective);
let undo = h.app.session.undo.len();
let at = crate::scenario::rect_of("workspace_switcher").unwrap().center();
h.step(&json!({"click":[at.x,at.y]})).unwrap();
@@ -601,7 +601,7 @@ fn clicked_render_workspace_saves_one_setup_and_restores_design_view() {
h.step(&json!({"widget":back})).unwrap();
assert!(!active(&h.app));
assert_eq!(h.app.cam, camera);
assert_eq!(flags, (h.app.ui.show_grid, h.app.ui.show_origin, h.app.ui.visual_style, h.app.ui.perspective));
assert_eq!(flags, (h.app.ui.show_grid, h.app.origin_shown(), h.app.ui.visual_style, h.app.ui.perspective));
h.app.run("edit.undo", json!({})).unwrap();
assert!(!h.app.session.is_dirty());
}
+6 -6
View File
@@ -8,7 +8,7 @@ use crate::scenario::Harness;
/// A sketch with two lines drawn on top of each other (l1, then l2), off the origin axes.
fn two_lines() -> (Harness, Value) {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
for _ in 0..2 {
h.app.run("sketch.line", json!({"points":[[0,10],[20,10]],"infer":false,"connect":false})).unwrap();
@@ -121,7 +121,7 @@ fn the_viewport_menu_offers_select_other() {
#[test]
fn overlapping_bodies_list_both_and_the_hidden_one_can_be_picked() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Inner"})).unwrap();
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[5,5,5],"body_name":"Outer"})).unwrap();
h.call("ui.view", json!({"view":"top"}));
@@ -139,7 +139,7 @@ fn overlapping_bodies_list_both_and_the_hidden_one_can_be_picked() {
#[test]
fn long_names_stay_inside_the_popup_and_remain_available_on_hover() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.call("ui.resize", json!({"width":1000,"height":700}));
let name = "Long assembly component ".repeat(12);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":name})).unwrap();
@@ -177,7 +177,7 @@ fn long_names_stay_inside_the_popup_and_remain_available_on_hover() {
#[test]
fn a_dialog_selection_input_takes_its_pick_from_the_list() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Block"})).unwrap();
h.call("ui.view", json!({"view":"home"}));
h.call("ui.view", json!({"view":"fit"}));
@@ -199,7 +199,7 @@ fn a_dialog_selection_input_takes_its_pick_from_the_list() {
#[test]
fn rows_name_points_by_their_curves() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.circle.center", json!({"center":[10,10],"radius":3})).unwrap();
h.app.cam.distance = 60.0;
@@ -213,7 +213,7 @@ fn rows_name_points_by_their_curves() {
#[test]
fn a_dense_spot_is_capped_per_kind_and_reports_the_total() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
// Thirty overlapping lines and their MID targets each exceed the per-kind cap.
for _ in 0..30 {
@@ -7,7 +7,7 @@ use solidcraft_engine::{
fn shell() -> Harness {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Case"})).unwrap();
h.app.run("solid.shell", json!({"faces":[[20,15,20]],"thickness":2})).unwrap();
h.call("ui.view", json!({"view":"front"}));
@@ -79,7 +79,7 @@ fn pending_create_sketch_accepts_an_actual_shell_wall_patch_click() {
#[test]
fn rounded_shell_corner_is_one_physical_face_above_and_below_the_floor() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":80,"width":60,"height":30,"corner":[-40,-30,0],"body_name":"Case"})).unwrap();
h.app.run("solid.fillet", json!({"edges":[[40,30,15],[-40,30,15],[-40,-30,15],[40,-30,15]],"radius":6})).unwrap();
h.app.run("solid.shell", json!({"faces":[[0,0,30]],"thickness":2})).unwrap();
@@ -13,7 +13,7 @@ fn bridge_line_snaps_to_points_on_two_visible_sketch_planes() {
}
let bridge = h.app.run("sketch.create", json!({"plane":"XY","name":"Bridge"})).unwrap()["sketch"].as_u64().unwrap();
h.app.run("sketch.options", json!({"sketch_3d":true})).unwrap();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.call("ui.view", json!({"view":"home"}));
h.call("ui.view", json!({"view":"fit"}));
h.frames(3);
@@ -55,7 +55,7 @@ fn coplanar_foreign_point() -> (crate::scenario::Harness, u64, u64) {
h.app.run("sketch.point", json!({"point":[10,20]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
let active = h.app.run("sketch.create", json!({"plane":"XY","name":"Active"})).unwrap()["sketch"].as_u64().unwrap();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.call("ui.view", json!({"view":"home"}));
h.call("ui.view", json!({"view":"fit"}));
h.frames(3);
@@ -136,7 +136,7 @@ fn second_occurrence_drawn_wire_fit_picks_and_world_triad_drag_stay_aligned() {
h.app.run("solid.box", json!({"corner":[17,32,45],"length":2,"width":2,"height":10,"body_name":"SnapVertices"})).unwrap();
h.app.run("browser.visibility", json!({"paths":[[first]],"visible":false})).unwrap();
let sketch = h.app.run("sketch.create", json!({"plane":"XY","name":"Wire"})).unwrap()["sketch"].as_u64().unwrap();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.settle();
h.step(&json!({"click":{"handle":"sketch_palette:options_fold"}})).unwrap();
h.step(&json!({"widget":"3D Sketch"})).unwrap();
@@ -4,7 +4,7 @@ use solidcraft_engine::doc::{FaceAttachmentStatus, FeatureKind, PlaneRef};
fn picked_sketch() -> (Harness, u64) {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.session.auto_project = false;
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"BaseBox","name":"Original"})).unwrap();
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[0,0,20],"body_name":"ControlBox","name":"Control"})).unwrap();
@@ -146,7 +146,7 @@ fn attachment_drafts_leave_on_document_replacement_but_survive_failed_open() {
#[test]
fn unsupported_modified_face_offers_explicit_fixed_plane_without_live_links() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Modified"})).unwrap();
// An intentional split gives the +z source two distinct planar pieces. A
// strict attachment cannot claim the original whole-face certificate.
@@ -181,7 +181,7 @@ fn occurrence_click(h: &mut Harness, path: &[u64], control: &str) {
#[test]
fn actual_nested_second_placement_face_pick_keeps_target_and_author_paths() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.session.auto_project = false;
let parent = h.app.run("component.create", json!({"name":"Parent"})).unwrap();
let parent_component = parent["component"].as_u64().unwrap();
@@ -336,7 +336,7 @@ fn nested_anchor_saved_fixed_conversion_preserves_rotated_second_author_plane()
#[test]
fn picked_top_face_of_a_stacked_join_extrude_takes_a_sketch() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY","name":"Base"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[40,40]})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
+3 -3
View File
@@ -128,7 +128,7 @@ fn offset_window_without_a_curve_reports_it_and_keeps_the_window_open() {
#[test]
fn clicked_extend_endpoint_reaches_exact_ellipse_and_preserves_support() {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.ellipse", json!({"center":[20,0],"major":[30,0],"minor_radius":5})).unwrap();
h.app.run("sketch.constraint.fix", json!({"entity":"e1"})).unwrap();
@@ -200,7 +200,7 @@ fn has_point(h: &crate::scenario::Harness, at: Vec2) -> bool {
fn corner_window_takes_the_corner_then_applies_the_typed_size() {
for command in ["sketch.fillet", "sketch.chamfer.equal_distance", "sketch.chamfer.distance_angle", "sketch.chamfer.two_distance"] {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,30]})).unwrap();
h.frames(2);
@@ -518,7 +518,7 @@ fn fully_constrained_center_rectangle_corners_can_be_picked_and_filleted() {
#[test]
fn ordinary_drawing_keeps_origin_snap_and_real_origin_corners_work() {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.step(&json!({"start":"sketch.line"})).unwrap();
h.step(&json!({"move":{"world":[0,0,0]}})).unwrap();
@@ -8,7 +8,7 @@ use solidcraft_engine::render::{SampledPath, SamplingQuality};
use std::sync::Arc;
fn circle(h: &mut Harness) -> u64 {
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("parameters.add", json!({"name":"foreground_diameter","expression":"2 mm"})).unwrap();
h.app.run("sketch.create", json!({"plane":"XY","name":"PixelCircle"})).unwrap();
h.app.run("sketch.circle.center", json!({"center":[0,0],"radius":1})).unwrap();
@@ -295,7 +295,7 @@ fn pixel_frame_budget_does_not_cache_unbounded_empty_curve_results() {
#[test]
fn zoomed_in_ring_fill_fits_the_hover_highlight_budget() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.ui.perspective = true;
h.app.run("sketch.create", json!({"plane":"XY","name":"Ring"})).unwrap();
h.app.run("sketch.circle.center", json!({"center":[0,0],"radius":40})).unwrap();
+1 -1
View File
@@ -36,7 +36,7 @@ fn sketch_keys_outside_a_sketch_sketch_on_the_selected_plane_and_start_their_too
#[test]
fn a_sketch_key_sketches_on_the_selected_planar_face() {
let mut h = Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.ui.pick_bodies = false;
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"BaseBox"})).unwrap();
h.call("ui.view", json!({"view":"top"}));
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::scenario::Harness;
/// An XY sketch with points p (10, 5) and q (-12, -3), the Symmetry tool started and both picked.
fn two_points_picked() -> Harness {
let mut h = Harness::new();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
h.app.run("sketch.point", json!({"point":[10,5],"id":"p"})).unwrap();
h.app.run("sketch.point", json!({"point":[-12,-3],"id":"q"})).unwrap();
+1 -1
View File
@@ -60,7 +60,7 @@ fn home_and_fit_frame_the_moved_body_not_its_old_place() {
h.app.run("sketch.circle.center", json!({"center": [-300, 0], "radius": 5})).unwrap();
h.app.run("sketch.finish", json!({})).unwrap();
near_box(crate::viewport::view_bounds(&h.app), [-305., -5., 0.], [510., 10., 5.]);
h.app.ui.show_sketches = false;
h.app.session.visibility.hidden_folders.push("c0/sketches".into());
near_box(crate::viewport::view_bounds(&h.app), [500., 0., 0.], [510., 10., 5.]);
}
+29 -30
View File
@@ -310,17 +310,17 @@ pub fn projection(app: &SolveApp, rect: Rect) -> Proj {
/// Sketches drawn in the viewport: the active one, and finished ones not yet used by a feature.
pub(crate) fn visible_sketches(app: &SolveApp) -> Vec<u64> {
let st = crate::open_meshing::shown_world(app);
st.sketches.iter().filter(|s| solidcraft_engine::view::sketch_drawn(&app.session, s.feature, app.ui.show_sketches)).map(|s| s.feature).collect()
st.sketches.iter().filter(|s| solidcraft_engine::view::sketch_shown(&app.session, s.feature)).map(|s| s.feature).collect()
}
/// What Home, Fit and the orbit pivot frame: the bodies and sketches shown now, where they are
/// now (see [`solidcraft_engine::view::visible_bounds`]).
/// now (see [`solidcraft_engine::view::bounds`]).
pub fn view_bounds(app: &SolveApp) -> solidcraft_engine::geom::Aabb3 {
// Bodies still being meshed after an open frame the view by their outlines.
if crate::open_meshing::framing(app) {
return solidcraft_engine::view::unmeshed_bounds(&app.session, app.ui.show_sketches);
return solidcraft_engine::view::unmeshed_bounds(&app.session);
}
solidcraft_engine::view::visible_bounds(&app.session, app.ui.show_sketches)
solidcraft_engine::view::bounds(&app.session)
}
fn scene_key(app: &SolveApp) -> u64 {
@@ -337,13 +337,12 @@ fn scene_key(app: &SolveApp) -> u64 {
section_plane(app).map(|(o, n)| [o.x, o.y, o.z, n.x, n.y, n.z].map(f64::to_bits)).hash(&mut h);
app.cam.up.hash(&mut h);
(app.cam.pitch > 0.0).hash(&mut h);
app.ui.show_sketches.hash(&mut h);
app.session.visibility.hidden_bodies.hash(&mut h);
app.session.visibility.hidden_occurrences.hash(&mut h);
app.session.visibility.hidden_sketches.hash(&mut h);
app.session.visibility.shown_sketches.hash(&mut h);
app.session.visibility.hidden_folders.hash(&mut h);
app.ui.hidden_profiles.hash(&mut h);
app.session.visibility.hidden_profiles.hash(&mut h);
app.session.active_component.hash(&mut h);
app.session.active_occurrence_path.hash(&mut h);
app.preview.effective_replaced().hash(&mut h);
@@ -1041,7 +1040,7 @@ fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene {
let active = s.active_sketch == Some(sid);
// Closed profiles are shaded (lifted off a face they may lie on).
let lift = ss.plane.normal() * 0.01;
let profiles = if app.ui.hidden_profiles.contains(&sid) || ss.sketch.view.hide_profile { &[][..] } else { &ss.profiles[..] };
let profiles = if app.session.visibility.hidden_profiles.contains(&sid) || ss.sketch.view.hide_profile { &[][..] } else { &ss.profiles[..] };
for (index, _) in profiles.iter().enumerate() {
let display = crate::sketch_display::profile_region(app, sid, index, &ss.plane, proj);
for tri in display.as_ref().as_ref().map_or_else(Vec::new, |region| crate::sketch_display::fill_triangles(region, &mut fill_budget)) {
@@ -1188,7 +1187,7 @@ pub fn origin_planes(app: &SolveApp) -> Vec<(&'static str, Vec3, [Vec3; 4])> {
}
// While the Origin is hidden, a dialog picking a plane brings the planes back: then every
// plane; otherwise only those not hidden one by one.
let creating = !app.ui.show_origin && app.picking_plane();
let creating = !app.origin_shown() && app.picking_plane();
origin_quads(origin_size(app.cam.half_height()))
.into_iter()
.filter(|(n, _, _)| creating || !app.session.visibility.hidden_origin.iter().any(|h| h == n))
@@ -5088,7 +5087,7 @@ mod tests {
const SIZE: u32 = 256;
let rect = Rect::from_min_size(Pos2::ZERO, vec2(SIZE as f32, SIZE as f32));
let mut render = |origin: bool| {
app.ui.show_origin = origin;
app.set_origin_shown(origin);
app.viewport.gpu = Some(GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess: false });
let (scene, highlight) = (build_scene(&app), build_highlight(&app).merged());
let proj = projection(&app, rect);
@@ -5111,7 +5110,7 @@ mod tests {
return;
};
let (Some(without), _) = render(false) else { return };
app.ui.show_origin = true;
app.set_origin_shown(true);
let xy = origin_planes(&app).into_iter().find(|(n, _, _)| *n == "XY").map(|(_, _, q)| q).unwrap();
let (w, h, r) = (f64::from(SIZE), f64::from(SIZE), scene_radius(&app));
let (mut samples, mut plain) = (0, Vec::new());
@@ -5299,7 +5298,7 @@ mod tests {
fn timeline_modifiers_highlight_on_hover_and_click() {
for command in ["solid.fillet", "solid.chamfer"] {
let mut h = crate::scenario::Harness::new();
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
let base = h.app.run("solid.box", json!({"length":20,"width":20,"height":20})).unwrap()["feature"].as_u64().unwrap();
let id = h.app.run(command, json!({"edges":[[0,0,10]],"radius":2,"distance":2,"name":"Blend"})).unwrap()["feature"].as_u64().unwrap();
h.app.run("solid.box", json!({"length":5,"width":5,"height":5,"corner":[40,0,0]})).unwrap();
@@ -5379,7 +5378,7 @@ mod tests {
fn three_placed_parts((command, params): (&str, &str)) -> SolveApp {
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.ui.ground_shadow = false;
app.ui.show_origin = false;
app.set_origin_shown(false);
app.viewport.gpu = Some(GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess: false });
app.run("component.create", json!({"name":"Part"})).unwrap();
app.run(command, serde_json::from_str(params).unwrap()).unwrap();
@@ -5460,7 +5459,7 @@ mod tests {
let Some(path) = std::env::var_os("SOLIDCRAFT_BENCH_MESH") else { return };
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.ui.ground_shadow = false;
app.ui.show_origin = false;
app.set_origin_shown(false);
let component = app.run("file.insert_mesh", json!({"path": path.to_string_lossy()})).unwrap()["component"].clone();
app.run("component.activate", json!({"component":"root"})).unwrap();
let size = app.session.world_state().bodies[0].mesh_bounds().size();
@@ -5695,7 +5694,7 @@ mod tests {
doc.add_feature(FeatureKind::MeshImport { file: "scan.stl".into(), meshes }, Some("Scan")).unwrap();
let mut app = SolveApp::new(solidcraft_engine::Session::new(doc), crate::Services::default());
app.ui.ground_shadow = false;
app.ui.show_origin = false;
app.set_origin_shown(false);
app.viewport.gpu = Some(GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess: false });
app
}
@@ -5777,7 +5776,7 @@ mod tests {
let mut context = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
context.viewport.gpu = app.viewport.gpu;
context.ui.ground_shadow = false;
context.ui.show_origin = false;
context.set_origin_shown(false);
context.run("component.create", json!({"name":"Part"})).unwrap();
context.run(PARTS[0].0, serde_json::from_str(PARTS[0].1).unwrap()).unwrap();
context.run("occurrence.copy", json!({"component":"Part","translate":[40,0,0]})).unwrap();
@@ -5957,7 +5956,7 @@ mod tests {
let ctx = crate::fonts::test_context();
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.run("solid.box", json!({"length":200,"width":120,"height":160})).unwrap();
app.ui.show_origin = false;
app.set_origin_shown(false);
app.ui.visual_style = style;
app.cam.yaw = 0.7;
app.cam.pitch = 0.5;
@@ -6030,7 +6029,7 @@ mod tests {
let ctx = crate::fonts::test_context();
let mut app = hover_app(false);
app.preferences.nav = preset.into();
app.ui.show_origin = false;
app.set_origin_shown(false);
hover_frame(&mut app, &ctx, vec![]);
let point = projection(&app, app.viewport.rect.unwrap()).to_screen(Vec3::ZERO).unwrap();
let before = app.cam;
@@ -6058,7 +6057,7 @@ mod tests {
let ctx = crate::fonts::test_context();
let mut app = hover_app(false);
app.preferences.nav = preset.into();
app.ui.show_origin = false;
app.set_origin_shown(false);
hover_frame(&mut app, &ctx, vec![]);
let point = projection(&app, app.viewport.rect.unwrap()).to_screen(Vec3::ZERO).unwrap();
let (start, end) = match action {
@@ -6114,7 +6113,7 @@ mod tests {
let ctx = crate::fonts::test_context();
let mut app = hover_app(false);
app.preferences.nav = crate::prefs::OPENSCAD_NAV.into();
app.ui.show_origin = false;
app.set_origin_shown(false);
hover_frame(&mut app, &ctx, vec![]);
let point = projection(&app, app.viewport.rect.unwrap()).to_screen(Vec3::ZERO).unwrap();
let (start, end) =
@@ -6459,7 +6458,7 @@ mod tests {
let mut app = hover_app(gpu);
app.session = solidcraft_engine::Session::default();
app.session.execute("solid.box", &json!({"length":40,"width":40,"height":40,"corner":[-20,-20,-20]})).unwrap();
app.ui.show_origin = false;
app.set_origin_shown(false);
app.cam.target = Vec3::ZERO;
app.cam.distance = 110.0;
app.cam.yaw = 0.5;
@@ -6568,7 +6567,7 @@ mod tests {
let mut s = solidcraft_engine::Session::default();
s.execute("solid.box", &json!({"length": 40, "width": 30, "height": 20})).unwrap();
let mut app = SolveApp::new(s, crate::Services::default());
app.ui.show_origin = false;
app.set_origin_shown(false);
if gpu {
app.viewport.gpu = Some(GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess: false });
}
@@ -6689,7 +6688,7 @@ mod tests {
let mut s = solidcraft_engine::Session::default();
s.execute("solid.cylinder", &json!({"radius": 10, "height": 20})).unwrap();
let mut app = SolveApp::new(s, crate::Services::default());
app.ui.show_origin = false;
app.set_origin_shown(false);
app
}
@@ -6721,7 +6720,7 @@ mod tests {
#[test]
fn body_highlight_buffers_are_reused_when_the_camera_orbits_or_pans() {
let mut app = cylinder_app();
app.ui.show_origin = true;
app.set_origin_shown(true);
app.viewport.hover_bodies = vec!["Body1".into()];
let key = highlight_key(&app);
let before = build_highlight(&app).merged();
@@ -6751,7 +6750,7 @@ mod tests {
#[test]
fn world_highlight_block_survives_zoom_and_refreshes_when_bodies_are_hidden() {
let mut app = cylinder_app();
app.ui.show_origin = true;
app.set_origin_shown(true);
app.viewport.hover_bodies = vec!["Body1".into()];
let before = build_highlight(&app);
let bytes = before.blocks[0].bytes.clone();
@@ -6825,7 +6824,7 @@ mod tests {
let part = made["components"][0]["component"].as_u64().unwrap();
s.execute("occurrence.copy", &json!({"component": part, "translate": [40, 0, 0]})).unwrap();
let mut assembly = SolveApp::new(s, crate::Services::default());
assembly.ui.show_origin = false;
assembly.set_origin_shown(false);
let names: Vec<String> = assembly.session.world_state().bodies.iter().map(|b| b.name.clone()).collect();
assert_eq!(names.len(), 2, "two placements of the part");
build_scene(&assembly);
@@ -7028,7 +7027,7 @@ mod tests {
let mut h = crate::scenario::Harness::new();
h.app.run("solid.box", json!({"length":20,"width":20,"height":20,"corner":[-10,-10,-10]})).unwrap();
h.app.run("inspect.section", json!({"plane": "XZ", "offset": 0})).unwrap();
h.app.ui.show_origin = true;
h.app.set_origin_shown(true);
h.frames(2);
assert!(section_plane(&h.app).is_some());
let sc = build_highlight(&h.app).merged();
@@ -8450,7 +8449,7 @@ mod grid_plane_tests {
fn create_sketch_shows_the_origin_planes_through_the_model() {
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.run("solid.box", json!({"length":40,"width":40,"height":40})).unwrap();
app.ui.show_origin = false;
app.set_origin_shown(false);
assert!(origin_planes(&app).is_empty());
assert!(build_highlight(&app).xray.is_empty());
app.start("sketch.create");
@@ -8461,7 +8460,7 @@ mod grid_plane_tests {
assert!(sc.guide_trans.is_empty());
app.dialog = None;
assert!(origin_planes(&app).is_empty());
app.ui.show_origin = true;
app.set_origin_shown(true);
let sc = build_highlight(&app);
assert!(sc.xray.is_empty(), "through-body reference geometry is off by default");
assert_eq!(sc.guide_trans.len(), 3 * 6 * crate::gpu::TRI_SIZE, "planes use the ordinary depth-tested path by default");
@@ -8497,7 +8496,7 @@ mod grid_plane_tests {
fn a_dialog_picking_a_plane_shows_the_origin_planes() {
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.run("solid.box", json!({"length":40,"width":40,"height":40})).unwrap();
app.ui.show_origin = false;
app.set_origin_shown(false);
app.start("solid.mirror");
let d = app.dialog.as_ref().expect("the Mirror dialog");
assert_eq!(d.active, 0, "it starts on its objects");
@@ -8546,7 +8545,7 @@ mod standalone_point_tests {
let points = standalone_points(&app);
assert_eq!(points.len(), 1, "only the placed point, not the rectangle's corners: {points:?}");
assert!(points[0].dist(Vec3::new(5.0, 4.0, 0.0)) < 1e-9, "{points:?}");
app.ui.show_sketches = false;
app.session.visibility.hidden_folders.push("c0/sketches".into());
assert!(standalone_points(&app).is_empty(), "sketches hidden");
}
}
@@ -24,7 +24,7 @@ fn placed_step_body_uses_imported_opacity_until_a_design_look_overrides_it() {
session.execute("occurrence.copy", &json!({"component":component,"translate":[30,0,0]})).unwrap();
let mut app = SolveApp::new(session, Services::default());
app.ui.ground_shadow = false;
app.ui.show_origin = false;
app.set_origin_shown(false);
let placed = app.session.world_state().bodies.iter().find(|b| b.name != source).unwrap().name.clone();
app.session.selection = vec![solidcraft_engine::Sel::Body { name: placed }];
app.start("appearance.assign");
@@ -62,7 +62,7 @@ fn theme_switches_refresh_cached_viewport_colours_without_remeshing() {
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.app.ui.ground_shadow = false;
h.app.ui.show_origin = false;
h.app.set_origin_shown(false);
h.app.run("solid.box", json!({"length": 20, "width": 15, "height": 10})).unwrap();
h.app.viewport.gpu = Some(super::GpuTarget { format: egui_wgpu::wgpu::TextureFormat::Rgba8Unorm, depth: None, samples: 1, tess: false });
let body = h.app.session.world_state().bodies[0].name.clone();
@@ -21,7 +21,7 @@ fn app() -> SolveApp {
s.execute("solid.remove", &json!({"bodies": ["Gone"]})).unwrap();
let mut app = SolveApp::new(s, Services::default());
app.ui.ground_shadow = false;
app.ui.show_origin = false;
app.set_origin_shown(false);
app
}
+1 -1
View File
@@ -204,7 +204,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
| Method | Params | Notes |
|---|---|---|
| `ui.inspect` | — | UI state, pending file picker (`file_picker_busy`; compatibility alias `file_dialog_open`, no path), what is hidden (`visibility`: bodies, origin and construction items, sketches, joints (`hidden_joints`, joint ids); set it with the `browser.visibility` command), viewport rect, camera, active tool/dialog, the status line (`status`: text and whether it is an error), hover, renderer, timings, live preview (`active`, `busy`, `error`, `ms`, bodies it stands in for) |
| `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, `layout`, …), and `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints`, `hiddenFolders` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme; `layout: "floating"` (default) or `"compact"` (`"docked"` is also accepted) selects the transient shell layout without saving a preference. Scenarios use `{"call":"ui.set","params":{"layout":"docked"}}` |
| `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, `layout`, …), and the browser's view of the design, saved with it: `showOrigin` (the Origin folder's eye), `showSketches` (the design's Sketches folder, `c0/sketches` in `hiddenFolders`), `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints`, `hiddenFolders`, `hiddenProfiles`, `shownDims`, `lockedBodies` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme; `layout: "floating"` (default) or `"compact"` (`"docked"` is also accepted) selects the transient shell layout without saving a preference. Scenarios use `{"call":"ui.set","params":{"layout":"docked"}}` |
| `ui.view` | `view`: `front`, `back`, `top`, `bottom`, `left`, `right`, `iso`, `home`, `fit`; `animate` (bool, default false: snap) | |
| `ui.camera` | `target?`: `[x, y, z]` (mm), `yaw?`, `pitch?`, `roll?` (radians), `distance?` (mm), `fov?`, `up?`; `fit?`: `true`, `false` or `[occurrence id or name…]` (`root`: the bodies outside every component) | the viewport's orbit camera: it looks at `target` from `distance` away; `yaw` 0 looks along +Y (from the front), `pitch` is the elevation (±π/2: straight down or up), `roll` turns the image. Fields given are set first (the others keep their values), then `fit` frames the listed occurrences (or everything), keeping the direction. The reply, passed back, sets the same view again, so a framing can be stored and replayed. `fov` and `up` follow the perspective setting (`ui.set`) and the up axis preference (`ui.prefs`) and can't change here; a refused field changes nothing |
| `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes |