From 201617ef888945779c822895b6ba707fb6a3922c Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:12:26 -0400 Subject: [PATCH] Wave 446/509: doc, ui: a feature that lost a reference asks for it to be picked again (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - e43fe1ab0 jyviko: Kernel rig: diagnostics.validation is a setting, exempt from cases - b24d90269 jyviko: doc, ui: a feature that lost a reference asks for it to be picked again - d62d248b7 jyviko: doc: Untrim's face points pick faces of the body it untrims - 1b08d4b8b jyviko: doc: a feature's face points are named on its own component's bodies first Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- .../locales/pending/reference-reselect.json | 23 ++++++++++++ crates/doc/src/eval.rs | 16 ++++++--- crates/doc/src/feature_geometry.rs | 3 +- crates/doc/src/lib.rs | 35 +++++++++++++++++++ crates/ui-egui/src/i18n.rs | 18 +++++++++- tests/kernel-cases/EXEMPT | 1 + 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 assets/locales/pending/reference-reselect.json diff --git a/assets/locales/pending/reference-reselect.json b/assets/locales/pending/reference-reselect.json new file mode 100644 index 000000000..2cea7dc5e --- /dev/null +++ b/assets/locales/pending/reference-reselect.json @@ -0,0 +1,23 @@ +{ + "ar": { + "diagnostic.reselect_reference": "{feature}: المرجع `{reference}` لم يعد موجودًا كما اختير؛ أعد اختياره" + }, + "de": { + "diagnostic.reselect_reference": "{feature}: Die Referenz `{reference}` existiert nicht mehr so, wie sie ausgewählt wurde; wählen Sie sie erneut aus" + }, + "en": { + "diagnostic.reselect_reference": "{feature}: the reference `{reference}` no longer exists as it was picked; reselect it" + }, + "he": { + "diagnostic.reselect_reference": "{feature}: ההפניה `{reference}` כבר אינה קיימת כפי שנבחרה; יש לבחור אותה מחדש" + }, + "ja": { + "diagnostic.reselect_reference": "{feature}: 参照 `{reference}` は選択したときのままでは存在しません。選択し直してください" + }, + "ko": { + "diagnostic.reselect_reference": "{feature}: 참조 `{reference}`이(가) 선택했을 때의 모습으로 더 이상 존재하지 않습니다. 다시 선택하세요" + }, + "zh": { + "diagnostic.reselect_reference": "{feature}:引用 `{reference}` 已不再是选择时的样子;请重新选择" + } +} diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index 93d2b3897..f764a4c6d 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -2063,7 +2063,7 @@ impl Model { } Ok(None) => f, Err(e) => { - frame_error = Some(e.to_string()); + frame_error = Some(e.in_feature(&f.name).to_string()); f } }; @@ -2074,7 +2074,7 @@ impl Model { None => kernel::guard(&f.name, || { let (r, deferred) = kernel::validating(validation, || eval_feature(doc, &vals, f, &mut next, &mut warning, &mut import_report, &mut repair)); - r.map_err(|e| kernel::KernelError::Failed(e.to_string()))?; + r.map_err(|e| kernel::KernelError::Failed(e.in_feature(&f.name).to_string()))?; // The checks the feature's steps left to its end: the bodies it keeps. if deferred { check_kept(&state, &next) } else { Ok(()) } }), @@ -7476,11 +7476,19 @@ pub fn face_point_state<'a>(doc: &Document, st: &'a ModelState, kind: &FeatureKi /// The names of the faces a feature's face points lie on (empty where none), found in /// [`face_point_state`]. A To / From point is named after the nearest face over every body, the /// one `object_height` resolves it to, not the first body with a face within tolerance: a part -/// resting a hair from the picked face would otherwise take its name. +/// resting a hair from the picked face would otherwise take its name. Another feature's point is +/// named on the bodies of the feature's own component first: each component's bodies lie in its +/// own coordinates there, where a part inserted twice has a face at the same point in each. pub fn face_point_names(doc: &Document, st: &ModelState, kind: &FeatureKind, comp: u64) -> Result> { let pts = kind.face_points(); if !matches!(kind, FeatureKind::Extrude { .. } | FeatureKind::Revolve { .. }) { - return Ok(crate::naming::face_names_at(st, &pts)); + let own = ModelState { bodies: st.bodies.iter().filter(|b| doc.model_body_component(b) == comp).cloned().collect(), ..ModelState::default() }; + let names = crate::naming::face_names_at(&own, &pts); + return Ok(names + .into_iter() + .zip(&pts) + .map(|(name, p)| if name.is_empty() { crate::naming::face_names_at(st, std::slice::from_ref(p)).pop().unwrap_or_default() } else { name }) + .collect()); } let fst = face_point_state(doc, st, kind, comp)?; let normal = match kind { diff --git a/crates/doc/src/feature_geometry.rs b/crates/doc/src/feature_geometry.rs index 09a0a4881..dcf371050 100644 --- a/crates/doc/src/feature_geometry.rs +++ b/crates/doc/src/feature_geometry.rs @@ -55,7 +55,7 @@ impl FeatureKind { /// The body a feature that works on one body's faces names (shell, draft, split, offset, /// delete and replace face, surface offset, the placed plastic features, sheet metal - /// conversion, ruled surface): its face points pick faces of that body. + /// conversion, ruled surface, untrim): its face points pick faces of that body. pub fn face_body(&self) -> Option<&str> { match self { FeatureKind::Shell { body, .. } @@ -69,6 +69,7 @@ impl FeatureKind { | FeatureKind::SnapFit { body, .. } | FeatureKind::Rest { body, .. } => body.as_deref(), FeatureKind::SheetConvert { body, .. } | FeatureKind::SurfaceRuled { body, .. } => Some(body.as_ref()), + FeatureKind::SurfaceUntrim { face, .. } => Some(face.body.as_ref()), _ => None, } } diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index f51058bf1..7e43f91ba 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -103,6 +103,41 @@ pub enum DocError { Sketch(#[from] solidcraft_sketch::SketchError), #[error(transparent)] Kernel(#[from] solidcraft_kernel::KernelError), + /// A stored reference (a face or edge name, a piece of a split face) no longer finds exactly + /// what it named: the feature using it fails, and the user picks it again. `feature` is + /// empty until the evaluation of the feature fills it in ([`DocError::in_feature`]). + #[error("{}", reselect_message(feature, reference))] + Reselect { feature: String, reference: String }, +} + +impl DocError { + /// A feature's `reference` that no longer finds what it named ([`DocError::Reselect`]), for + /// the feature being evaluated. + pub fn reselect(reference: impl Into) -> Self { + DocError::Reselect { feature: String::new(), reference: reference.into() } + } + + /// This error, raised while feature `feature` was evaluated: a [`DocError::Reselect`] names it. + pub fn in_feature(self, feature: &str) -> Self { + match self { + DocError::Reselect { feature: f, reference } if f.is_empty() => DocError::Reselect { feature: feature.into(), reference }, + other => other, + } + } +} + +/// What a feature that lost a reference says ([`DocError::Reselect`]). +fn reselect_message(feature: &str, reference: &str) -> String { + let feature = if feature.is_empty() { "this feature" } else { feature }; + format!("{feature}: the reference `{reference}` no longer exists as it was picked; reselect it") +} + +/// The feature and the reference of a [`DocError::Reselect`] message, read back from its text +/// (a feature's error is kept as text): `None` for any other message. +pub fn reselect_parts(text: &str) -> Option<(&str, &str)> { + let (feature, rest) = text.split_once(": the reference `")?; + let reference = rest.strip_suffix("` no longer exists as it was picked; reselect it")?; + Some((feature, reference)) } pub type Result = std::result::Result; diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs index 166c9ca62..a3ef0e637 100644 --- a/crates/ui-egui/src/i18n.rs +++ b/crates/ui-egui/src/i18n.rs @@ -202,8 +202,12 @@ impl Locale { } /// Evaluation errors stay English for scripts; the empty Cut/Intersect hint that names - /// another component is translated where it is shown. Other text is returned unchanged. + /// another component, and a feature's request to reselect a reference it lost, are translated + /// where they are shown. Other text is returned unchanged. pub fn diagnostic(self, text: &str) -> String { + if let Some((feature, reference)) = solidcraft_engine::doc::reselect_parts(text) { + return self.format("diagnostic.reselect_reference", &[("feature", &self.given_name(feature)), ("reference", reference)]); + } const PREFIX: &str = "there is no body to cut or intersect in component '"; if let Some((before, detail)) = text.split_once(PREFIX) && let Some((component, detail)) = detail.split_once("'; the tool may overlap '") @@ -379,6 +383,18 @@ mod tests { assert_eq!(Locale::for_language("ja").diagnostic(plain), plain); } + #[test] + fn reselect_reference_diagnostic_translates_with_the_feature_and_reference_as_given() { + let message = solidcraft_engine::doc::DocError::reselect("F4:side:c1#1|F4:top").in_feature("Fillet {2}").to_string(); + assert_eq!(Locale::for_language("en").diagnostic(&message), message); + for language in ["ar", "de", "he", "ja", "ko", "zh"] { + let translated = Locale::for_language(language).diagnostic(&message); + assert_ne!(translated, message, "{language}"); + // Right-to-left text comes back in display order, so only what it holds is checked. + assert!(translated.contains("Fillet {2}") && translated.contains("`F4:side:c1#1|F4:top`"), "{language}: {translated}"); + } + } + /// English first, then by id, so adding a locale edits only its own line. #[test] fn locales_are_listed_english_first_then_by_id() { diff --git a/tests/kernel-cases/EXEMPT b/tests/kernel-cases/EXEMPT index 9ad00ffe5..eade6e13b 100644 --- a/tests/kernel-cases/EXEMPT +++ b/tests/kernel-cases/EXEMPT @@ -44,6 +44,7 @@ diagnostics.crash_reports crash reports diagnostics.crash_reports.clear crash reports diagnostics.crash_test crash reports diagnostics.profile timing: where a command's time goes +diagnostics.validation a setting: when the body check runs doc.open opening and recovering documents doc.recover opening and recovering documents doc.recovery_discard opening and recovering documents