Exploded View: grey it out until the design has two components (#9142) (#9659)

* claim: #9142

* Exploded View: grey it out until the design has two components (#9142)

On a part made of plain bodies (the sample plate) Exploded View opened its
dialog and failed on OK with "an exploded view needs two or more
occurrences". The command is now disabled until the design has two or more
occurrences, and its tooltip says why and which commands make components.

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:
PaddleStroke
2026-10-31 01:18:34 +00:00
committed by GitHub
parent 8311ae5c5d
commit 2f09c90542
3 changed files with 67 additions and 1 deletions
@@ -0,0 +1,29 @@
{
"en": {
"ui.explode_needs_two_components": "Exploded View pulls components apart, so the design needs two or more of them (New Component, Insert Design or Create Components from Bodies)"
},
"ar": {
"ui.explode_needs_two_components": "يُبعد العرض المفكك المكوّنات بعضها عن بعض، لذا يحتاج التصميم إلى مكوّنين أو أكثر (مكوّن جديد، أو إدراج تصميم، أو إنشاء مكوّنات من الأجسام)"
},
"de": {
"ui.explode_needs_two_components": "Die Explosionsdarstellung zieht Komponenten auseinander, daher braucht die Konstruktion mindestens zwei davon (Neue Komponente, Konstruktion einfügen oder Komponenten aus Körpern erstellen)"
},
"fr": {
"ui.explode_needs_two_components": "La vue éclatée écarte les composants les uns des autres : la conception doit en contenir au moins deux (Nouveau composant, Insérer une conception ou Créer des composants à partir des corps)"
},
"he": {
"ui.explode_needs_two_components": "תצוגה מפוצצת מרחיקה רכיבים זה מזה, ולכן התכן צריך שניים או יותר מהם (רכיב חדש, הוספת תכן או יצירת רכיבים מגופים)"
},
"ja": {
"ui.explode_needs_two_components": "分解図はコンポーネント同士を引き離すため、デザインに 2 つ以上のコンポーネントが必要です(新規コンポーネント、デザインを挿入、またはボディからコンポーネントを作成)"
},
"ko": {
"ui.explode_needs_two_components": "분해 보기는 구성 요소를 서로 떼어 놓으므로 설계에 구성 요소가 두 개 이상 있어야 합니다(새 구성 요소, 설계 삽입 또는 바디로 구성 요소 만들기)"
},
"vi": {
"ui.explode_needs_two_components": "Chế độ xem phân rã tách các cụm chi tiết ra xa nhau, nên thiết kế cần có từ hai cụm chi tiết trở lên (Tạo mới Cụm chi tiết, Chèn thiết kế vào cụm hoặc Tạo cụm chi tiết từ các thân khối)"
},
"zh": {
"ui.explode_needs_two_components": "爆炸图会将组件彼此分开,因此设计中需要两个或更多组件(新建组件、插入设计或由实体创建组件)"
}
}
+11 -1
View File
@@ -103,7 +103,7 @@ pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("joint.sweep", "Sweep Joint", sweep::sweep).icon("interference").params(sweep::SWEEP_DOC),
CommandSpec::new("motion.list", "List Motion Studies", list_studies).icon("list").noundo(),
CommandSpec::new("motion.delete", "Delete Motion Study", delete_study).icon("delete").params("study"),
CommandSpec::new("explode.create", "Exploded View", explode_create).at("SOLID", "ASSEMBLE").icon("explode").params(
CommandSpec::new("explode.create", "Exploded View", explode_create).at("SOLID", "ASSEMBLE").icon("explode").enabled(has_parts_to_explode).params(
"name?; scale? (automatic: each occurrence pushed away from the assembly's centre by scale × its offset, default 1); \
moves?: [{occurrence, translate: [x,y,z]}] (instead of automatic)",
),
@@ -1013,6 +1013,16 @@ fn delete_study(s: &mut Session, p: &Value) -> Result<Value> {
// ---- Exploded views ----
/// Why Exploded View is greyed out: it pulls components apart, so a design of plain bodies, or
/// with a single component, has nothing to separate (#9142).
const EXPLODE_NEEDS_COMPONENTS: &str =
"Exploded View pulls components apart, so the design needs two or more of them (New Component, Insert Design or Create Components from Bodies)";
/// Exploded View is offered once the design has two or more occurrences to move apart (#9142).
fn has_parts_to_explode(s: &Session) -> std::result::Result<(), String> {
if s.doc.occurrences.len() >= 2 { Ok(()) } else { Err(EXPLODE_NEEDS_COMPONENTS.into()) }
}
fn view_index(s: &Session, p: &Value, cmd: &str) -> Result<usize> {
let key = match p.get("view") {
Some(Value::Number(n)) => n.to_string(),
+27
View File
@@ -691,6 +691,33 @@ fn exploded_views_show_without_changing_the_design() {
assert_eq!(run(&mut s, "explode.list", json!({}))["views"].as_array().map(Vec::len), Some(2));
}
/// #9142: on a part of plain bodies (the sample plate) Exploded View opened its dialog and failed
/// on OK ("an exploded view needs two or more occurrences"). It is greyed out instead, saying why,
/// until the design has two components to pull apart.
#[test]
fn exploded_view_is_greyed_out_until_there_are_two_components() {
let spec = crate::cmd::find_command("explode.create").unwrap();
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Plate"}));
let info = spec.info(&s);
assert!(!info.enabled, "a part of plain bodies has nothing to explode");
assert_eq!(info.disabled_reason.as_deref(), Some(super::EXPLODE_NEEDS_COMPONENTS));
let e = s.execute("explode.create", &json!({"scale": 1.62})).unwrap_err();
assert!(e.to_string().contains("two or more of them"), "{e}");
assert!(s.doc.assembly.exploded.is_empty(), "nothing was added: {e}");
// One component is still nothing to pull apart.
run(&mut s, "component.from_bodies", json!({"bodies": ["Plate"]}));
assert_eq!(s.doc.occurrences.len(), 1);
assert!(!spec.info(&s).enabled);
// A second one brings it back, and the automatic view separates the two.
run(&mut s, "component.activate", json!({"component": "root"}));
run(&mut s, "component.create", json!({"name": "Lid"}));
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [30, 0, 0]}));
assert!(spec.info(&s).enabled, "{:?}", spec.info(&s).disabled_reason);
let r = run(&mut s, "explode.create", json!({"scale": 1.62}));
assert_eq!(r["moves"].as_array().map(Vec::len), Some(2), "{r}");
}
/// Pictures drawn by the CPU rasterizer (the engine has no GPU): real views of the scene.
fn cpu(scene: &crate::render::Scene, cam: &crate::render::Camera, w: u32, h: u32) -> Result<crate::capture::Picture, String> {
Ok(crate::capture::Picture { rgba: crate::render::render(scene, cam, w as usize, h as usize).rgba, renderer: "cpu" })