99d8d382b9
* Bill of materials: part properties on components and assembly.bom A component definition now carries part properties (part number, description, revision, other tools' keys) and free text properties, saved with the component and shared by its occurrences. component.metadata and component.metadata.set read and change them in one undo step; Paste New copies them; parts.insert numbers standard parts from their standard and size, and parts.resize renumbers them. assembly.bom counts the placed components (flat: parts at any depth through their subassemblies; top: direct children), grouped by part number or by definition, sorted by part number, and writes CSV (fixed, quoted columns) or JSON. The app gets a Bill of Materials window on the INSPECT panel that lists, edits and exports the rows. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Bill of materials: name a merged row's equal definitions once Two standard parts with the same size are separate definitions with the same name; their row now reads "SHCS M6x20" instead of repeating it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Window widths test: close the Bill of Materials window between commands The test closes the floating windows a command opens before starting the next one; the Bill of Materials window was left open and measured against the next dialogs' limits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Bill of materials: sub-parts in their part's row, and part properties without re-evaluating assembly.bom takes group_children: true. A part with a part number keeps what is placed inside it (a bolt's washer and nut) in its own row, listed under it as children (items 1.1, 1.2, with each and count) instead of rows of their own; bolts with different contents stay different rows, and total_occurrences is the same either way. The window has a switch for it and shows the children under their part; the CSV lists them after their row. Changing part properties re-evaluated the model, re-seated every joint and rebuilt the placed model: 361 ms per change with 30 jointed bolts. A change that only touches components' metadata and properties now takes the same path as a render-only change (proved on the whole Document), also for its undo and redo: 0.6 ms. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Bill of materials: look the structure up once, not per subassembly Deciding whether a subassembly is a part (it has bodies of its own) scanned every body of the model for each subassembly, and each body looked up its feature by a linear search of the timeline: subassemblies × bodies × features. assembly.bom now indexes the placements, the body owners (Document::body_owners: one pass over the bodies with the timeline in a map, the same rule as model_body_component) and the numbered components once per call. 600 bodies and features with 60 subassemblies: 8.1 ms → 1.3 ms; the old cost grows with the cube of the design's size. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
97 lines
3.6 KiB
Rust
97 lines
3.6 KiB
Rust
//! Every command dialog and every window stays within the width limits of `frame`: started
|
|
//! through the control channel (the toolbar's way) and measured as drawn.
|
|
|
|
use serde_json::json;
|
|
use solidcraft_ui_egui::frame::{DIALOG_MAX_W, DIALOG_MIN_W, DIALOG_WIDE_MAX_W, WINDOW_WIDE_MAX_W};
|
|
use solidcraft_ui_egui::scenario::Harness;
|
|
|
|
/// Widths of the windows on screen (their areas in the middle layer).
|
|
fn window_widths(h: &Harness) -> Vec<(String, f32)> {
|
|
h.ctx.memory(|m| {
|
|
m.areas()
|
|
.visible_layer_ids()
|
|
.into_iter()
|
|
.filter(|l| l.order == egui::Order::Middle)
|
|
.filter_map(|l| m.area_rect(l.id).map(|r| (format!("{:?}", l.id), r.width())))
|
|
.collect()
|
|
})
|
|
}
|
|
|
|
fn fresh() -> Harness {
|
|
let mut h = Harness::new();
|
|
h.call("engine.execute", json!({"command": "solid.box", "params": {"length": 40, "width": 30, "height": 20}}));
|
|
h.frames(3);
|
|
h
|
|
}
|
|
|
|
#[test]
|
|
fn command_dialogs_shrink_to_their_content_within_limits() {
|
|
let mut h = fresh();
|
|
let mut bad = Vec::new();
|
|
// The frame border and shadow add a little to the content limits.
|
|
let slack = 4.0;
|
|
for spec in solidcraft_engine::command_specs() {
|
|
h.call("ui.start", json!({"command": spec.id}));
|
|
h.frames(4);
|
|
let wide = h.app.dialog.as_ref().is_some_and(|d| d.is_wide());
|
|
let max = if wide { DIALOG_WIDE_MAX_W } else { DIALOG_MAX_W };
|
|
for (layer, w) in window_widths(&h) {
|
|
// Floating windows a command opened (Parameters…) have their own limit.
|
|
let limit = if h.app.dialog.is_some() { max } else { WINDOW_WIDE_MAX_W };
|
|
if w > limit + slack {
|
|
bad.push(format!("{} ({layer}): {w} px", spec.id));
|
|
}
|
|
}
|
|
// The docked dialog shrinks to its content: most dialogs stay well under the maximum.
|
|
if h.app.dialog.is_some() && !wide {
|
|
for (_, w) in window_widths(&h) {
|
|
if w < DIALOG_MIN_W - slack {
|
|
bad.push(format!("{}: {w} px is narrower than {DIALOG_MIN_W}", spec.id));
|
|
}
|
|
}
|
|
}
|
|
h.app.dialog = None;
|
|
h.app.params = None;
|
|
h.app.design_properties = None;
|
|
h.app.bom = None;
|
|
h.app.tool = None;
|
|
if h.app.session.active_sketch.is_some() {
|
|
h.app.finish_sketch();
|
|
}
|
|
h.frames(2);
|
|
}
|
|
assert!(bad.is_empty(), "windows too wide or too narrow:\n{}", bad.join("\n"));
|
|
}
|
|
|
|
#[test]
|
|
fn common_dialogs_are_not_stretched() {
|
|
// Simple dialogs have room to spare: they must not be pushed out to the maximum.
|
|
let mut h = fresh();
|
|
for id in ["solid.extrude", "solid.fillet", "solid.shell", "solid.move", "solid.hole"] {
|
|
h.call("ui.start", json!({"command": id}));
|
|
h.frames(6);
|
|
let w: f32 = window_widths(&h).iter().map(|x| x.1).fold(0.0, f32::max);
|
|
assert!(w < DIALOG_MAX_W - 20.0, "{id} is stretched to {w} px");
|
|
h.app.dialog = None;
|
|
h.frames(2);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn floating_windows_stay_within_limits() {
|
|
let mut h = fresh();
|
|
h.app.prefs_window.open = true;
|
|
h.app.keymap.open = true;
|
|
h.app.help.about = true;
|
|
h.app.ui.palette_open = true;
|
|
solidcraft_ui_egui::params_dialog::open(&mut h.app);
|
|
solidcraft_ui_egui::design_properties::open(&mut h.app);
|
|
h.frames(6);
|
|
let ws = window_widths(&h);
|
|
// Keyboard Shortcuts is a page of Preferences (one window, #36).
|
|
assert!(ws.len() >= 3, "windows on screen: {ws:?}");
|
|
for (layer, w) in ws {
|
|
assert!(w <= WINDOW_WIDE_MAX_W + 4.0, "{layer} is {w} px wide");
|
|
}
|
|
}
|