Files
Jackson Oursland 6275665100 STEP import: an option reads STEP files with cadmpeg instead of SolidCraft's own reader, to compare the two (#16906)
* STEP import: "Import with cadmpeg" also reads STEP files with cadmpeg instead of SolidCraft's own reader, to compare the two

A STEP file can now be read by cadmpeg's STEP decoder: its neutral model is read into B-rep
records exactly as a FreeCAD or Rhino file's is, and the Import feature keeps those records.
`reader: "cadmpeg"` on `doc.open` and `file.insert_step`, or the Preferences > General > Import
with cadmpeg switch (`cadmpeg_import`, off by default, added for FreeCAD and Rhino files in
#16811), chooses it; the default, `reader: "solidcraft"`, is SolidCraft's own reader as before.
IGES is always SolidCraft's. The switch's label now names STEP files too.

cadmpeg's neutral model bounds a STEP file's edges by their vertices alone, with no parameter
range: the assembly now finds such an edge's interval where its vertices lie on its curve
(`Assembly::add_edge_on`), with the STEP reader's own vertex projection for lines, conics,
splines and polylines.

On the step-conformance parts (cylinders, cones, domes, a NURBS torus ring, a grooved shaft, a
sheet, a plate with 100 holes) both readers give the same volumes. Known gap: a part placed more
than once in an assembly comes in once (CADIR's occurrences are not followed yet).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: closed spline edges start at their vertex, line edges measured by length

Review follow-up.
- An edge cadmpeg gives no interval on a closed spline whose vertex is not where the spline
  starts is now that whole spline from its vertex (restarted there exactly); before, its ends
  were the spline's start and the edge was refused for a vertex 14 mm off.
- A line edge's degeneracy is decided by its length, as `map_edge` decides it, not by the line's
  parameter scale.
- In the browser, a STEP file cadmpeg reads is not staged through SolidCraft's STEP reading first
  (it has no STEP text to stage).
- The docs say that cadmpeg's reader does not follow a file's assembly structure yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: the records and the STEP route are compared on every step-conformance part too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* STEP import with cadmpeg: the switch's label names STEP files in every complete catalog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: the extruded-ellipse and nearly-flat-cone kernel cases compared between the two routes

The two import kernel cases the records route used to refuse (#3208: a SURFACE_OF_LINEAR_EXTRUSION
of an ellipse, which cadmpeg reads as a procedural surface with no solved form; #4006: a cone 7e-12
short of a right angle, which is a plane) join the parts compared between the STEP route and the
records, and a test checks that the records build each case's expected body: one whole body, its
faces and volume as expected.json gives them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: a closed spline edge is restarted at its vertex once, by the reader's own open_or_closed

main's open_or_closed already restarts a closed spline or polyline at the edge's vertex, snapped to a knot, so the second restart in closed_at_vertex never changed the curve. The function and its call are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: the spline arm of record_edge on one line, as rustfmt writes it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: `reader` in the help of `doc.open` and `file.insert_step` names STEP files too

The schemas already took `reader` for STEP files; the commands' parameter help, which named it
for FreeCAD and Rhino files (#16811), now names STEP files and what cadmpeg's reader does with
them, beside main's `flatten`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* Web file loading: an open or insert that is not read in stages answers its request with the failure, not success

On the web, a file with no staged open (FreeCAD, Rhino, IGES, meshes, and now STEP read with
cadmpeg) runs `open_path_with` or `insert_path_with`, which dropped the command's error, so the
control request or design link was answered `ok: true` when the file did not open. Both now return
the command's result, and the request is answered with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: a spline edge between two vertices at one point is the whole closed curve, as a conic's is

`record_edge` passed only `closed` (one vertex at both ends) to the spline arm, so two distinct
vertices at one point of a closed spline were taken as a degenerate edge and refused the region.
It now passes `full` (the ends are one point), as the circle and ellipse arms do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* STEP import with cadmpeg: the setting's label in Korean

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

* Web file loading: main's test of an inserted STEP part's check takes insert_path_with's result, which it now returns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018WRx8erWfxRfxVtyfRiGSb

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 10:01:15 +00:00

250 lines
12 KiB
Rust

//! Actual app evidence for disclosure states, rendered from egui meshes without a GPU.
#[path = "support/raster.rs"]
mod raster;
use egui::{ColorImage, Rect, TextureId};
use serde_json::json;
use solidcraft_engine::panels::LogicalRect;
use solidcraft_ui_egui::{
panel_runtime::HostSection,
scenario::{self, Harness},
ui_kit::LayoutMode,
};
use std::collections::HashMap;
fn panel<'a>(h: &'a Harness, id: &str) -> &'a HostSection {
h.app.universal_panel_frame().unwrap().layout.sections.iter().find(|section| section.instance.0 == id).unwrap()
}
fn rect(value: LogicalRect) -> Rect {
Rect::from_min_size(egui::pos2(value.origin.x, value.origin.y), egui::vec2(value.size.width, value.size.height))
}
#[test]
fn appearance_and_browser_folds_keep_handles_and_render_both_states() {
let previous = solidcraft_theme::is_dark();
let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/disclosure-review");
std::fs::create_dir_all(&dir).unwrap();
for dark in [false, true] {
let mut h = Harness::new();
h.app.home.open = false;
h.call("ui.resize", json!({"width":1100,"height":1500}));
h.call("ui.set", json!({"dark":dark}));
h.app.ui.layout = LayoutMode::Floating;
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Body1".into() }];
h.app.start("appearance.assign");
h.frames(3);
for open in [true, false] {
if !open {
h.step(&json!({"click":{"handle":"dialog:collapse"}})).unwrap();
let at = rect(panel(&h, "browser").collapse.unwrap()).center();
h.step(&json!({"click":[at.x,at.y]})).unwrap();
}
assert_eq!(h.app.dialog.as_ref().unwrap().collapsed, !open);
assert_eq!(panel(&h, "browser").collapsed, !open);
assert_eq!(scenario::handle_at("fold:Bodies").is_some(), open);
assert_eq!(scenario::handle_at("appearance:search").is_some(), open);
// Fresh context transfers all textures to the software renderer, including fonts.
h.ctx = egui::Context::default();
solidcraft_ui_egui::fonts::setup_fonts(&h.ctx);
solidcraft_theme::apply(&h.ctx);
let mut textures: HashMap<TextureId, ColorImage> = HashMap::new();
for _ in 0..8 {
raster::paint(&mut h, &mut textures, vec![]);
}
let output = raster::paint(&mut h, &mut textures, vec![]);
let screenshot = raster::raster(&mut h, &textures, output);
let mode = if dark { "dark" } else { "light" };
let state = if open { "open" } else { "closed" };
screenshot.save(dir.join(format!("{mode}-{state}.png"))).unwrap();
for (name, rect) in [("appearance", scenario::rect_of("dialog:header").unwrap()), ("browser", rect(panel(&h, "browser").header))] {
let bounds = rect.intersect(Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(screenshot.width() as f32, screenshot.height() as f32)));
image::imageops::crop_imm(&screenshot, bounds.left() as u32, bounds.top() as u32, bounds.width() as u32, bounds.height() as u32)
.to_image()
.save(dir.join(format!("{mode}-{state}-{name}.png")))
.unwrap();
}
}
}
solidcraft_theme::set_dark(previous);
}
#[test]
fn render_browser_uses_shared_rows_in_both_lenses_and_themes() {
let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/render-browser-review");
std::fs::create_dir_all(&dir).unwrap();
for dark in [false, true] {
let mut h = Harness::new();
h.app.home.open = false;
h.app.session.run_script(&solidcraft_engine::sample::script()).unwrap();
h.app.run("solid.box", json!({"corner":[60,0,0],"length":10,"width":10,"height":10,"body_name":"Detail block"})).unwrap();
h.app.run("appearance.assign", json!({"bodies":["Plate"],"appearance":"ABS - Red"})).unwrap();
h.app.run("appearance.assign", json!({"bodies":["Detail block"],"appearance":"ABS - Blue"})).unwrap();
h.call("ui.resize", json!({"width":1440,"height":1100}));
h.call("ui.set", json!({"dark":dark}));
h.app
.run(
"render.settings.set",
json!({"name":"Studio","set":{"job":{"method":"gpu_path","options":{
"lighting":{"environment":[0.2,0.2,0.2],"sun":{"direction":[1,-1,-2],"angular_radius_rad":0.1,"radiance":[2,2,2]},
"area_lights":[{"center":[10,20,30],"u":[4,0,0],"v":[0,-2,0],"radiance":[1,1,1]}]}
}}}}),
)
.unwrap();
h.app.run("render.settings.set", json!({"name":"Detail","set":{"job":{"method":"raster"}}})).unwrap();
h.call("ui.workspace", json!({"workspace":"render"}));
h.ctx = egui::Context::default();
solidcraft_ui_egui::fonts::setup_fonts(&h.ctx);
solidcraft_theme::apply(&h.ctx);
let mut textures: HashMap<TextureId, ColorImage> = HashMap::new();
for _ in 0..8 {
raster::paint(&mut h, &mut textures, vec![]);
}
for lens in ["object", "look"] {
if lens == "look" {
let at = rect(panel(&h, "render-browser").actions.iter().find(|(id, _)| id.0 == "by-look").unwrap().1).center();
// Capture texture uploads from the input frames too: the look rows may
// introduce glyphs that were absent from the object lens.
for pressed in [true, false] {
raster::paint(
&mut h,
&mut textures,
vec![
egui::Event::PointerMoved(at),
egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE },
],
);
}
}
for _ in 0..4 {
raster::paint(&mut h, &mut textures, vec![]);
}
let output = raster::paint(&mut h, &mut textures, vec![]);
for section in ["environment", "lights", "shots", "objects", "output"] {
assert!(scenario::rect_of(&format!("render:tree:{section}")).is_some());
}
for action in ["render:tree:lights:add", "render:tree:light:0:solo", "render:tree:light:0:mute", "render:tree:shots:add"] {
assert!(scenario::rect_of(action).is_some(), "{action}");
}
assert_eq!(solidcraft_theme::is_dark(), dark);
assert_eq!(scenario::rect_of("render:tree:look:0").is_some(), lens == "look");
let browser = rect(panel(&h, "render-browser").outer);
let screenshot = raster::raster(&mut h, &textures, output);
let ppp = h.ctx.pixels_per_point();
image::imageops::crop_imm(
&screenshot,
(browser.left() * ppp) as u32,
(browser.top() * ppp) as u32,
(browser.width() * ppp) as u32,
(browser.height() * ppp) as u32,
)
.to_image()
.save(dir.join(format!("{}-{lens}.png", if dark { "dark" } else { "light" })))
.unwrap();
}
}
}
#[test]
fn stand_up_memory_controls_apply_and_forget_with_visible_evidence() {
use solidcraft_ui_egui::stand_up::Answer;
let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/stand-up-memory-review");
std::fs::create_dir_all(&dir).unwrap();
let mut h = Harness::new();
h.app.home.open = false;
h.call("ui.resize", json!({"width":1400,"height":1200}));
h.call("ui.prefs", json!({"open":"Design"}));
h.frames(3);
// Main's settings layout can put either row below the viewport. Reveal controls before
// clicking, just as the current preference tests do, instead of relying on page height.
let reveal = |h: &mut Harness, handles: &[&str]| {
for _ in 0..32 {
let page = scenario::rect_of("dialog:page_body").unwrap();
if handles
.iter()
.all(|name| scenario::handle_at(name).is_some_and(|at| page.shrink(solidcraft_theme::Tokens::get().space_16).contains(at)))
{
return;
}
h.call("ui.scroll", json!({"x":page.center().x,"y":page.center().y,"delta":-100}));
h.frames(20);
}
panic!("preference controls were not revealed: {handles:?}");
};
reveal(&mut h, &["prefs:remember_stand_up"]);
h.step(&json!({"click":{"handle":"prefs:remember_stand_up"}})).unwrap();
assert!(!h.app.preferences.remember_stand_up);
h.step(&json!({"click":{"handle":"prefs:remember_stand_up"}})).unwrap();
assert!(h.app.preferences.remember_stand_up);
reveal(&mut h, &["prefs:reuse_imports", "prefs:clear_imports"]);
assert!(h.app.preferences.reuse_imports);
h.step(&json!({"click":{"handle":"prefs:reuse_imports"}})).unwrap();
assert!(!h.app.preferences.reuse_imports);
h.step(&json!({"click":{"handle":"prefs:reuse_imports"}})).unwrap();
assert!(h.app.preferences.reuse_imports);
h.step(&json!({"click":{"handle":"prefs:clear_imports"}})).unwrap();
let status = h.app.status.as_ref().map(|(text, _, error)| (text.clone(), *error));
let (text, error) = status.expect("Clear sets a status");
assert!(!error && text.starts_with("Cleared ") && text.ends_with(" cached imports"), "Clear reports what it removed: {text}");
let digest = "a".repeat(64);
h.app.preferences.stand_up_answers.remember(digest.clone(), Answer::Leave);
h.step(&json!({"widget":"Forget remembered answers"})).unwrap();
assert_eq!(h.app.preferences.stand_up_answers.get(&digest), None);
let capture = |h: &mut Harness, name: &str| {
h.ctx = egui::Context::default();
solidcraft_ui_egui::fonts::setup_fonts(&h.ctx);
solidcraft_theme::apply(&h.ctx);
let mut textures: HashMap<TextureId, ColorImage> = HashMap::new();
for _ in 0..8 {
raster::paint(h, &mut textures, vec![]);
}
for _ in 0..16 {
let (Some(page), Some(at)) = (scenario::rect_of("dialog:page_body"), scenario::handle_at("prefs:clear_imports")) else { break };
if page.contains(at) {
break;
}
raster::paint(
h,
&mut textures,
vec![
egui::Event::PointerMoved(page.center()),
egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: egui::vec2(0.0, -100.0),
modifiers: egui::Modifiers::NONE,
phase: egui::TouchPhase::Move,
source: egui::MouseWheelSource::Unknown,
},
],
);
for _ in 0..20 {
raster::paint(h, &mut textures, vec![]);
}
}
let output = raster::paint(h, &mut textures, vec![]);
raster::raster(h, &textures, output).save(dir.join(name)).unwrap();
// The raster pass keeps its own clock; the harness goes on with a fresh context, so its
// later frames are not earlier than the ones the raster pass ran.
h.ctx = egui::Context::default();
solidcraft_ui_egui::fonts::setup_fonts(&h.ctx);
solidcraft_theme::apply(&h.ctx);
};
capture(&mut h, "preferences.png");
h.call("ui.prefs", json!({"button":"ok", "stand_up_unknown":"ask"}));
let path = dir.join("plate.step").to_string_lossy().to_string();
h.app.run("solid.box", json!({"length":10,"width":40,"height":5})).unwrap();
h.app.run("file.export", json!({"path":path})).unwrap();
let text = std::fs::read_to_string(&path).unwrap().replace("'SolidCraft','SolidCraft'", "'SolidCraft','Example CAD'");
std::fs::write(&path, text).unwrap();
h.app.open_path_with(&path, &Default::default()).unwrap();
assert!(h.app.stand_up.is_some());
capture(&mut h, "first-offer.png");
h.step(&json!({"click":{"handle":"stand_up:stand"}})).unwrap();
let stood = solidcraft_engine::view::bounds(&h.app.session).unwrap();
h.app.open_path_with(&path, &Default::default()).unwrap();
assert!(h.app.stand_up.is_none());
assert_eq!(solidcraft_engine::view::bounds(&h.app.session).unwrap(), stood);
capture(&mut h, "reopened.png");
}