Inspect Sketch: clicking it shows a Sketch report window (#6262) (#6263)

* claim: #6262

* Inspect Sketch: the ribbon button opens a Sketch report window (#6262)

sketch.inspect gets a place on the Sketch tab (Inspect panel). ui.start opens a
read-only Sketch report: solver status, degrees of freedom left, counts of
curves, points, constraints and profiles, the curves and points that are not
fully constrained, and Copy JSON. engine.execute still only returns the JSON.

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

* Inspect Sketch: a Sketch Report button on the Sketch tab while a sketch is open (#6262)

SKETCH/INSPECT placed it in the Inspect tab's Surface Quality drop-down, which
is hidden while a sketch is edited. It now has its own Inspect panel on the
Sketch tab, labelled Sketch Report; the test clicks the ribbon button.

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

* Sketch Report: strings in a pending locale file, help for sketch.inspect (#6262)

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

* Sketch Report: the Sketch tab fits at 1366 px; the width test closes the report (#6262)

The panels left of the Finish group keep the gap before it when they are fitted,
so they collapse before they reach it.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Frank <plexi32@gmail.com>
This commit is contained in:
Frank
2026-10-30 15:39:25 +00:00
committed by GitHub
parent f0a5fc5016
commit bf14bf3678
8 changed files with 245 additions and 2 deletions
+58
View File
@@ -0,0 +1,58 @@
{
"en": {
"help.sketch.inspect": "Opens a report on the open sketch: how many degrees of freedom are left and whether it is fully constrained. Use it to find out what still moves before you finish the sketch.",
"ui.sketch_report.all_constrained": "Everything is fully constrained.",
"ui.sketch_report.dof": "Degrees of freedom",
"ui.sketch_report.loose": "Not fully constrained",
"ui.sketch_report.status": "Status",
"ui.sketch_report.title": "Sketch Report"
},
"de": {
"help.sketch.inspect": "Öffnet einen Bericht zur offenen Skizze: wie viele Freiheitsgrade übrig sind und ob sie vollständig bestimmt ist. Damit sehen Sie, was sich noch bewegt, bevor Sie die Skizze abschließen.",
"ui.sketch_report.all_constrained": "Alles ist vollständig bestimmt.",
"ui.sketch_report.dof": "Freiheitsgrade",
"ui.sketch_report.loose": "Nicht vollständig bestimmt",
"ui.sketch_report.status": "Status",
"ui.sketch_report.title": "Skizzenbericht"
},
"ja": {
"help.sketch.inspect": "開いているスケッチのレポートを開きます。残りの自由度と、完全に拘束されているかどうかを表示します。スケッチを終える前に、まだ動く部分を確認するときに使います。",
"ui.sketch_report.all_constrained": "すべて完全に拘束されています。",
"ui.sketch_report.dof": "自由度",
"ui.sketch_report.loose": "完全には拘束されていません",
"ui.sketch_report.status": "状態",
"ui.sketch_report.title": "スケッチ レポート"
},
"zh": {
"help.sketch.inspect": "打开当前草图的报告:显示剩余的自由度以及是否已完全约束。在完成草图之前,用它找出仍然可以移动的部分。",
"ui.sketch_report.all_constrained": "全部已完全约束。",
"ui.sketch_report.dof": "自由度",
"ui.sketch_report.loose": "未完全约束",
"ui.sketch_report.status": "状态",
"ui.sketch_report.title": "草图报告"
},
"ar": {
"help.sketch.inspect": "يفتح تقريرًا عن الرسم المفتوح: عدد درجات الحرية المتبقية وهل هو مقيد بالكامل. استخدمه لمعرفة ما لا يزال يتحرك قبل إنهاء الرسم.",
"ui.sketch_report.all_constrained": "كل شيء مقيد بالكامل.",
"ui.sketch_report.dof": "درجات الحرية",
"ui.sketch_report.loose": "غير مقيد بالكامل",
"ui.sketch_report.status": "الحالة",
"ui.sketch_report.title": "تقرير الرسم"
},
"he": {
"help.sketch.inspect": "פותח דוח על הסקיצה הפתוחה: כמה דרגות חופש נותרו והאם היא מאולצת במלואה. השתמשו בו כדי לגלות מה עדיין זז לפני שמסיימים את הסקיצה.",
"ui.sketch_report.all_constrained": "הכול מאולץ במלואו.",
"ui.sketch_report.dof": "דרגות חופש",
"ui.sketch_report.loose": "לא מאולץ במלואו",
"ui.sketch_report.status": "מצב",
"ui.sketch_report.title": "דוח סקיצה"
},
"vi": {
"help.sketch.inspect": "Mở báo cáo về bản phác thảo đang mở: còn bao nhiêu bậc tự do và đã ràng buộc hoàn toàn chưa. Dùng nó để biết phần nào vẫn còn di chuyển được trước khi hoàn tất bản phác thảo.",
"ui.sketch_report.all_constrained": "Mọi thứ đã được ràng buộc hoàn toàn.",
"ui.sketch_report.dof": "Bậc tự do",
"ui.sketch_report.loose": "Chưa ràng buộc hoàn toàn",
"ui.sketch_report.status": "Trạng thái",
"ui.sketch_report.title": "Báo cáo phác thảo"
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ pub static COMMANDS: &[CommandSpec] = &[
revision (moves whenever the design, what is hidden or a component's uncaptured position changes, \
never on a selection or a view; from one counter for the whole run, so it never repeats). Read-only",
),
CommandSpec::new("sketch.inspect", "Inspect Sketch", sketch_inspect).icon("inspect").noundo().params("sketch?: id|name (default active)"),
CommandSpec::new("sketch.inspect", "Inspect Sketch", sketch_inspect).at("SKETCH", "INSPECT").icon("inspect").noundo().params("sketch?: id|name (default active)"),
CommandSpec::new("model.edges", "List Edges", model_edges).icon("inspect").noundo().params("body: name"),
CommandSpec::new("model.faces", "List Faces", model_faces).icon("inspect").noundo().params(
"body: name → per face: index, name (what face.delete, sheet.convert `face`, solid.shell … take in place of a point), exact, area, centroid (not always on the face), \
+1
View File
@@ -26,6 +26,7 @@ pub const DOCUMENTED: &[&str] = &[
"sketch.construction_line.tangent_two",
"sketch.construction_line.vertical",
"sketch.equation_curve",
"sketch.inspect",
"solid.align",
"solid.chamfer",
"solid.combine",
+9
View File
@@ -258,6 +258,7 @@ mod sketch_modify_ui_tests;
mod sketch_moving_click_tests;
pub mod sketch_palette;
mod sketch_pattern_tree;
pub mod sketch_report;
#[cfg(test)]
mod sketch_side_ui_tests;
mod sketch_state;
@@ -505,6 +506,8 @@ pub struct SolveApp {
pub params: Option<params_dialog::ParamsDialog>,
/// The Design Properties window, when open.
pub design_properties: Option<design_properties::DesignProperties>,
/// The Sketch report window (`sketch.inspect` from the ribbon), when open.
pub sketch_report: Option<sketch_report::SketchReport>,
/// The Bill of Materials window, when open.
pub bom: Option<bom_panel::BomPanel>,
material_card_review: Option<material_card_review::ReviewWindow>,
@@ -748,6 +751,7 @@ impl SolveApp {
dialog: None,
params: None,
design_properties: None,
sketch_report: None,
bom: None,
material_card_review: None,
menu: context_menu::MenuState::default(),
@@ -1730,6 +1734,10 @@ impl SolveApp {
design_properties::open(self);
return;
}
if id == "sketch.inspect" {
sketch_report::open(self);
return;
}
if id == "assembly.bom" {
bom_panel::open(self);
return;
@@ -2808,6 +2816,7 @@ impl SolveApp {
self.resolve_fit(ui.ctx());
params_dialog::show(self, ui.ctx());
design_properties::show(self, ui.ctx());
sketch_report::show(self, ui.ctx());
bom_panel::show(self, ui.ctx());
material_card_review::show(self, ui.ctx());
recovery_ui::show(self, ui.ctx());
+169
View File
@@ -0,0 +1,169 @@
//! The Sketch report window (#6262): what `sketch.inspect` says about the active sketch, for
//! people. The solver status and degrees of freedom left, how many curves, points and
//! constraints the sketch has, and which curves and points are not fully constrained yet.
//! Copy JSON puts the whole `sketch.inspect` result on the clipboard. `ui.start` of
//! `sketch.inspect` (its ribbon button) opens it; `engine.execute` still only returns the JSON.
//! The report follows edits while it is open.
use serde_json::Value;
use crate::SolveApp;
use crate::ui_kit;
/// Rows of unconstrained curves and points shown before the list scrolls.
const LIST_ROWS: f32 = 8.0;
/// The open report: the last `sketch.inspect` result, or why there is none.
pub struct SketchReport {
/// The session revision the report was read at.
pub revision: u64,
/// The sketch the report is about (the active one when the window opened).
pub sketch: Option<u64>,
pub result: Result<Value, String>,
}
fn read(app: &mut SolveApp, sketch: Option<u64>) -> Result<Value, String> {
let params = match sketch {
Some(id) => serde_json::json!({ "sketch": id }),
None => serde_json::json!({}),
};
app.session.execute("sketch.inspect", &params).map_err(|e| e.to_string())
}
/// Open the report on the active sketch.
pub fn open(app: &mut SolveApp) {
let sketch = app.session.active_sketch;
let result = read(app, sketch);
app.sketch_report = Some(SketchReport { revision: app.session.revision, sketch, result });
}
/// The ids of the entries in `list` that are not fully constrained.
pub fn loose(v: &Value, list: &str) -> Vec<String> {
v[list]
.as_array()
.map(|a| {
a.iter()
.filter(|e| !e["fully_constrained"].as_bool().unwrap_or(false))
.map(|e| match e["type"].as_str() {
Some(kind) => format!("{} ({kind})", e["id"].as_str().map(str::to_string).unwrap_or_else(|| e["id"].to_string())),
None => e["id"].as_str().map(str::to_string).unwrap_or_else(|| e["id"].to_string()),
})
.collect()
})
.unwrap_or_default()
}
fn count(v: &Value, list: &str) -> usize {
v[list].as_array().map_or(0, Vec::len)
}
/// The solver status as a word ("well", "under", …).
fn status(v: &Value) -> String {
match &v["status"] {
Value::String(s) => s.clone(),
Value::Null => String::new(),
other => other.to_string(),
}
}
/// Draw the window when it is open. Called once per frame.
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let Some(mut r) = app.sketch_report.take() else { return };
if r.revision != app.session.revision {
r.revision = app.session.revision;
r.result = read(app, r.sketch);
}
let title = crate::i18n::tr_label("Sketch Report");
let (closed, action) = ui_kit::Window::new(egui::Id::new("sc_sketch_report"), "inspect", title)
.fields()
.actions("", crate::i18n::tr("ui.close"), None)
.show(ctx, true, |ui| match &r.result {
Err(e) => {
ui_kit::text(ui, e, ui_kit::Text::Error("error"));
}
Ok(v) => {
let name = v["name"].as_str().unwrap_or_default();
ui_kit::row(ui, crate::i18n::tr_label("Sketch"), |ui| ui_kit::text(ui, name, ui_kit::Text::Cell));
ui_kit::row(ui, crate::i18n::tr_label("Status"), |ui| ui_kit::text(ui, &status(v), ui_kit::Text::Cell));
let dof = v["dof"].as_u64().map(|d| d.to_string()).unwrap_or_else(|| v["dof"].to_string());
ui_kit::row(ui, crate::i18n::tr_label("Degrees of freedom"), |ui| ui_kit::text(ui, &dof, ui_kit::Text::Cell));
let construction = v["curves"].as_array().map_or(0, |a| a.iter().filter(|c| c["construction"].as_bool() == Some(true)).count());
let curves =
if construction > 0 { format!("{} ({construction} construction)", count(v, "curves")) } else { count(v, "curves").to_string() };
ui_kit::row(ui, crate::i18n::tr_label("Curves"), |ui| ui_kit::text(ui, &curves, ui_kit::Text::Cell));
for (label, list) in [("Points", "points"), ("Constraints", "constraints"), ("Profiles", "profiles")] {
ui_kit::row(ui, crate::i18n::tr_label(label), |ui| ui_kit::text(ui, &count(v, list).to_string(), ui_kit::Text::Cell));
}
let (curves, points) = (loose(v, "curves"), loose(v, "points"));
if curves.is_empty() && points.is_empty() {
ui_kit::text(ui, crate::i18n::tr_label("Everything is fully constrained."), ui_kit::Text::Note("all_constrained"));
} else {
let heading = format!("{} ({})", crate::i18n::tr_label("Not fully constrained"), curves.len() + points.len());
ui_kit::section(ui, "sc_sketch_report_loose", &heading, true, |ui| {
egui::ScrollArea::vertical().max_height(ui_kit::row_height() * LIST_ROWS).show(ui, |ui| {
for (label, ids) in [("Curve", &curves), ("Point", &points)] {
for id in ids {
ui_kit::row(ui, crate::i18n::tr_label(label), |ui| ui_kit::text(ui, id, ui_kit::Text::Cell));
}
}
});
});
}
if ui_kit::icon_label_button(ui, crate::i18n::tr_label("Copy JSON"), "copy", true, false).clicked() {
ctx.copy_text(serde_json::to_string_pretty(v).unwrap_or_default());
}
}
});
if closed || action != ui_kit::Action::None {
return;
}
app.sketch_report = Some(r);
}
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::scenario::Harness;
#[test]
fn the_ribbon_button_opens_a_report_that_follows_the_sketch() {
let mut h = Harness::new();
h.app.home.open = false;
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
h.app.run("sketch.line", json!({"points": [[0, 0], [10, 0]]})).unwrap();
h.step(&json!({"start": "sketch.inspect"})).unwrap();
h.frames(2);
let r = h.app.sketch_report.as_ref().expect("the button opens the report");
let v = r.result.as_ref().expect("the active sketch is inspected");
assert_eq!(v["curves"].as_array().map(Vec::len), Some(1));
assert_eq!(super::loose(v, "curves").len(), 1, "a free line is not fully constrained");
h.app.run("sketch.line", json!({"points": [[10, 0], [10, 10]]})).unwrap();
h.frames(2);
let v = h.app.sketch_report.as_ref().unwrap().result.as_ref().unwrap();
assert_eq!(v["curves"].as_array().map(Vec::len), Some(2), "the report follows edits");
// Closing it changes nothing in the design.
let undo = h.app.session.undo.len();
h.frames(4);
assert!(crate::scenario::handle_at("dialog:cancel").is_some(), "the window is drawn");
h.step(&json!({"click": {"handle": "dialog:cancel"}})).unwrap();
h.frames(2);
assert!(h.app.sketch_report.is_none());
assert_eq!(h.app.session.undo.len(), undo);
}
#[test]
fn the_command_is_on_the_sketch_tab() {
let spec = solidcraft_engine::find_command("sketch.inspect").unwrap();
assert_eq!((spec.tab, spec.panel), ("SKETCH", "INSPECT"));
// While a sketch is open the Sketch tab shows it, not the Inspect tab's drop-down.
let mut h = Harness::new();
h.app.home.open = false;
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
h.frames(3);
let at = crate::scenario::handle_at("toolbar:sketch.inspect").expect("the button is on the ribbon");
h.step(&json!({"click": [at.x, at.y]})).unwrap();
h.frames(2);
assert!(h.app.sketch_report.is_some(), "clicking the ribbon button opens the report");
}
}
+4 -1
View File
@@ -1528,8 +1528,11 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) {
let finish_plan =
sizes.last().and_then(|size| if tab == "SKETCH" || (tab == "MODEL" && editing_in_place) { Some(Plan::full(size)) } else { None });
let finish_width = finish_plan.as_ref().map_or(0.0, |p| p.width().max(80.0));
// The Finish group keeps its own gap before it, so the panels on its left give up room
// (collapse) before they would touch it.
let finish_gap = if finish_plan.is_some() { 4.0 } else { 0.0 };
let normal_count = sizes.len().saturating_sub(usize::from(finish_plan.is_some()));
let mut plans = fit(sizes.get(..normal_count).unwrap_or_default(), right - 4.0 - px - finish_width);
let mut plans = fit(sizes.get(..normal_count).unwrap_or_default(), right - 4.0 - px - finish_width - finish_gap);
let finish_right = plans.iter().any(|p| p.fit == Fit::More);
plans.extend(finish_plan);
crate::scenario::publish_count("toolbar_collapsed", plans.iter().filter(|p| p.fit == Fit::Collapsed).count() as f64);
+2
View File
@@ -305,6 +305,7 @@ pub const SECTIONS: &[Section] = &[
],
},
// Sketch dimensions are driven by parameters, so they are one click away while sketching.
Section { tab: "SKETCH", panel: "INSPECT", promoted: 1, ids: &["sketch.inspect"] },
Section { tab: "SKETCH", panel: "CONFIGURE", promoted: 2, ids: CONFIGURE },
Section { tab: "SKETCH", panel: "FINISH SKETCH", promoted: 2, ids: &["sketch.finish", "sketch.cancel"] },
// New Sketch leads the tab, as on MODEL: a sheet part starts from a sketch (#3250).
@@ -449,6 +450,7 @@ pub const RIBBON_LABELS: &[(&str, &str)] = &[
("sketch.create", "New Sketch"),
("sketch.dimension", "Dimension"),
("sketch.finish", "Finish Sketch"),
("sketch.inspect", "Sketch Report"),
("sketch.pattern.circular", "Circular"),
("sketch.pattern.rectangular", "Rectangular"),
("sketch.rectangle.two_point", "Rectangle"),
+1
View File
@@ -104,6 +104,7 @@ fn command_dialogs_shrink_to_their_content_within_limits() {
h.app.dialog = None;
h.app.params = None;
h.app.design_properties = None;
h.app.sketch_report = None;
h.app.bom = None;
// Properties (Inspect → Measure) opens the Properties card.
h.app.menu.props = None;