Imports become components; STEP assemblies as nested components (#1386) (#1426)

* Imports become components: a STEP assembly's tree as nested components (#1386)

Every imported file (STEP, IGES, 3MF, STL, OBJ: inserted, dropped, opened as a
design, or file.insert_step / file.insert_mesh / doc.open from scripts, the CLI
and MCP) now comes in as a new component named after the file, with its Import
feature inside it. A STEP assembly's products become nested components; a part
placed more than once is one component with an occurrence per placement, and
the Import feature skips the file's later copies (`skip`, format 21 note). The
contents are held as one rigid group (rigid joints, glyphs hidden); moving an
inner part is refused until component.unlock ("Unlock Contents") releases it.
Y up turns the import's component. Replies report component, component_name
and occurrence. Undo is one step; designs with loose imports are unchanged.

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

* Keep an import's rigid group hidden when the window loads the file in the background

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

* Import instances' skip list is format 22: format 21 ships in 0.12.0

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

* Catalog entries for Unlock Contents

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bherbruckandClaude Opus 5.5 authored and GitHub committed 2026-10-15 11:04:49 -04:00
1 parent d43c414b7b
commit 27529d9742
37 files changed
+968 -103

No files matched your search

+11 -2
View File
@@ -600,7 +600,7 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
}
"ui.moveOccurrence" => {
item.params = Some(json!({"occurrence": placement.occurrence, "path": path}));
item.enabled = !placement.grounded;
item.enabled = !placement.grounded && app.session.held_by_rigid_group(placement.occurrence).is_none();
}
"ui.properties" => item.params = Some(json!({"occurrence": placement.occurrence, "path": path})),
"occurrence.copy" => item.params = Some(json!({"occurrence": placement.occurrence, "translate": [10,10,0]})),
@@ -642,9 +642,18 @@ fn component_items(app: &SolveApp, id: u64) -> Vec<Item> {
let oid = occ.map(|o| o.id).unwrap_or(0);
v.push(act("ui.activate", "Activate", "component").with(json!({ "component": id })).on(!active));
v.push(cmd(app, "occurrence.ground", if grounded { "Unground" } else { "Ground" }).with(json!({ "occurrence": oid, "grounded": !grounded })));
v.push(act("ui.moveOccurrence", "Move/Copy", "move").key("M").with(json!({ "occurrence": oid })).on(!grounded && occ.is_some()));
v.push(
act("ui.moveOccurrence", "Move/Copy", "move")
.key("M")
.with(json!({ "occurrence": oid }))
.on(!grounded && occ.is_some() && app.session.held_by_rigid_group(oid).is_none()),
);
v.push(cmd(app, "component.capture_position", "Capture Position").on(!app.session.pending_moves.is_empty()));
v.push(cmd(app, "component.revert_position", "Revert Position").on(!app.session.pending_moves.is_empty()));
// An imported assembly moves as one until its rigid group is released.
if !app.session.contents_joints(id).is_empty() {
v.push(cmd(app, "component.unlock", "Unlock Contents").with(json!({ "component": id })));
}
v.push(Item::sep());
} else {
v.push(act("ui.activate", "Activate", "component").with(json!({ "component": id })).on(!active));
+1 -1
View File
@@ -740,7 +740,7 @@ pub fn tick(app: &mut SolveApp, ctx: &egui::Context) {
app.fit_view();
// A caller that said which way is up has been answered: no offer to stand the part up.
if (request.kind == Kind::Open || request.insert()) && !request.options.contains_key("up") {
crate::stand_up::offer(app, &request.path, &running.before);
crate::stand_up::offer(app, &request.path, &running.before, Some(&made.result));
}
let warnings = made.result.get("warnings").and_then(Value::as_array);
if let Kind::Recover { .. } = request.kind {
+6 -3
View File
@@ -312,6 +312,8 @@ pub struct SolveApp {
pub recoverable: Vec<solidcraft_engine::recovery::Entry>,
/// The bodies of a just-opened Y-up file, offered to be stood up (`stand_up`).
pub stand_up: Option<Vec<String>>,
/// The placement of the component that file came in as: the offer turns it.
pub stand_up_occurrence: Option<u64>,
/// The anti-aliasing sample counts the graphics device supports (empty without a GPU).
pub msaa_supported: Vec<u32>,
/// Settings put back at start because they kept SolidCraft from starting, one line each,
@@ -407,6 +409,7 @@ impl SolveApp {
autosave: None,
recoverable: Vec::new(),
stand_up: None,
stand_up_occurrence: None,
msaa_supported: Vec::new(),
settings_reset: Vec::new(),
big_operation: false,
@@ -910,9 +913,9 @@ impl SolveApp {
pub fn open_path(&mut self, path: &str) {
self.home.open = false;
documents::prepare_open(self);
if self.run("doc.open", json!({ "path": path })).is_ok() {
if let Ok(r) = self.run("doc.open", json!({ "path": path })) {
self.fit_view();
stand_up::offer(self, path, &[]);
stand_up::offer(self, path, &[], Some(&r));
}
}
@@ -930,7 +933,7 @@ impl SolveApp {
let before: Vec<String> = self.session.world_state().bodies.iter().map(|b| b.name.clone()).collect();
if let Ok(r) = self.run(cmd, json!({ "path": path })) {
self.fit_view();
stand_up::offer(self, path, &before);
stand_up::offer(self, path, &before, Some(&r));
if let Some(w) = r["warnings"].as_array().filter(|w| !w.is_empty()) {
self.set_status(format!("imported with {} warning(s): {}", w.len(), w.first().and_then(Value::as_str).unwrap_or("")), false);
}
+17 -6
View File
@@ -1,7 +1,7 @@
//! Standing up a Y-up file (#3). Many CAD programs save parts with Y up, so a STEP or IGES file
//! from them opens lying on its back in a Z-up design. After such a file opens, SolidCraft
//! offers to stand it up: a quarter turn about X (Y → Z) of the bodies it brought, as one
//! Move feature that can be undone or edited. Preferences › Design › "Offer to stand up Y-up
//! offers to stand it up: a quarter turn about X (Y → Z) of the component the file came in as
//! (#1386), so an assembly's parts and instances turn together, in one step that can be undone. Preferences › Design › "Offer to stand up Y-up
//! files" turns the offer off; with Y up as the default orientation it isn't needed.
use serde_json::json;
@@ -9,8 +9,9 @@ use serde_json::json;
use crate::SolveApp;
/// The bodies a just-opened file brought (`before`: body names before it opened, none for a
/// new design): offer to stand them up.
pub fn offer(app: &mut SolveApp, path: &str, before: &[String]) {
/// new design), and the import's component placement from the command's `result`: offer to
/// stand them up.
pub fn offer(app: &mut SolveApp, path: &str, before: &[String], result: Option<&serde_json::Value>) {
let io = &solidcraft_engine::io::is_step_path;
if !(io(path) || solidcraft_engine::io::is_iges_path(path)) || !app.preferences.offer_stand_up || app.preferences.up_axis != "z" {
return;
@@ -18,13 +19,19 @@ pub fn offer(app: &mut SolveApp, path: &str, before: &[String]) {
let bodies: Vec<String> = app.session.world_state().bodies.iter().map(|b| b.name.clone()).filter(|n| !before.contains(n)).collect();
if !bodies.is_empty() {
app.stand_up = Some(bodies);
app.stand_up_occurrence = result.and_then(|r| r.get("occurrence")).and_then(serde_json::Value::as_u64);
}
}
/// Turn the offered bodies a quarter turn about X (Y up becomes Z up).
pub fn stand_up(app: &mut SolveApp) -> Result<(), String> {
let Some(bodies) = app.stand_up.take() else { return Err("no file is waiting to be stood up".into()) };
app.run("solid.move", json!({ "bodies": bodies, "axis": [1, 0, 0], "angle": "90 deg" })).map_err(|e| e.to_string())?;
match app.stand_up_occurrence.take() {
// The import's component turns about its parent's origin, contents and all.
Some(occurrence) => app.run("occurrence.move", json!({ "occurrence": occurrence, "axis": [1, 0, 0], "angle": "90 deg" })),
None => app.run("solid.move", json!({ "bodies": bodies, "axis": [1, 0, 0], "angle": "90 deg" })),
}
.map_err(|e| e.to_string())?;
app.animate_view("home");
Ok(())
}
@@ -62,9 +69,13 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
app.set_status(e, true);
}
}
Some("leave") => app.stand_up = None,
Some("leave") => {
app.stand_up = None;
app.stand_up_occurrence = None;
}
Some("never") => {
app.stand_up = None;
app.stand_up_occurrence = None;
app.preferences.offer_stand_up = false;
}
_ => {}
@@ -14,8 +14,9 @@ fn placed_step_body_uses_imported_opacity_until_a_design_look_overrides_it() {
.unwrap();
let mut document = doc::Document::default();
let component = document.add_component(Some("Imported part"), 0).unwrap();
let feature =
document.add_feature(doc::FeatureKind::Import { file: "glass.step".into(), step: step.into(), components: Vec::new() }, None).unwrap();
let feature = document
.add_feature(doc::FeatureKind::Import { file: "glass.step".into(), step: step.into(), components: Vec::new(), skip: Vec::new() }, None)
.unwrap();
document.features.iter_mut().find(|f| f.id == feature).unwrap().component = component;
let mut session = Session::new(document);
let source = session.model.state().bodies[0].name.clone();