SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Pattern and Mirror dialogs: explain Object Type, and say why a sketch is not taken (#10057) (#10097)
phanoobe64202417f8e
diff --git a/assets/locales/pending/pattern-object-type-help.json b/assets/locales/pending/pattern-object-type-help.jsonnew file mode 100644index 0000000000..b0e477cb62--- /dev/null+++ b/assets/locales/pending/pattern-object-type-help.json@@ -0,0 +1,38 @@+{+ "en": {+ "dialog.pattern_sketch_not_object": "Pick bodies or features: a sketch is neither. Repeat its curves with the sketch's own Pattern or Mirror, or extrude it first.",+ "ui.pattern_object_type_tip": "Bodies: solid shapes, picked in the view or the Browser; each is copied whole.\nFeatures: steps of the History, such as an extrude or a hole, picked in the History or on a face they made; the step is repeated.\nA sketch is neither: repeat its curves with the sketch's own Pattern or Mirror, or extrude it first."+ },+ "ar": {+ "dialog.pattern_sketch_not_object": "اختر أجسامًا أو ميزات: الرسم ليس أيًّا منهما. كرّر منحنياته بأداة النمط أو المرآة داخل الرسم، أو ابثقه أولًا.",+ "ui.pattern_object_type_tip": "الأجسام: أشكال مصمتة تُختار في العرض أو في المستعرض؛ يُنسخ كل منها كاملًا.\nالميزات: خطوات في السجل، مثل بثق أو ثقب، تُختار في السجل أو على وجه صنعته؛ تتكرر الخطوة.\nالرسم ليس أيًّا منهما: كرّر منحنياته بأداة النمط أو المرآة داخل الرسم، أو ابثقه أولًا."+ },+ "de": {+ "dialog.pattern_sketch_not_object": "Körper oder Funktionen wählen: Eine Skizze ist keines von beiden. Ihre Kurven mit Muster oder Spiegeln in der Skizze wiederholen oder sie zuerst extrudieren.",+ "ui.pattern_object_type_tip": "Körper: feste Formen, in der Ansicht oder im Browser gewählt; jeder wird ganz kopiert.\nFunktionen: Schritte im Verlauf, etwa eine Extrusion oder eine Bohrung, im Verlauf oder auf einer von ihnen erzeugten Fläche gewählt; der Schritt wird wiederholt.\nEine Skizze ist keines von beiden: Ihre Kurven mit Muster oder Spiegeln in der Skizze wiederholen oder sie zuerst extrudieren."+ },+ "fr": {+ "dialog.pattern_sketch_not_object": "Choisissez des corps ou des fonctions : une esquisse n'est ni l'un ni l'autre. Répétez ses courbes avec la Répétition ou la Symétrie de l'esquisse, ou extrudez-la d'abord.",+ "ui.pattern_object_type_tip": "Corps : formes pleines, choisies dans la vue ou le Navigateur ; chacun est copié en entier.\nFonctions : étapes de l'Historique, comme une extrusion ou un perçage, choisies dans l'Historique ou sur une face qu'elles ont créée ; l'étape est répétée.\nUne esquisse n'est ni l'un ni l'autre : répétez ses courbes avec la Répétition ou la Symétrie de l'esquisse, ou extrudez-la d'abord."+ },+ "he": {+ "dialog.pattern_sketch_not_object": "בחרו גופים או פיצ'רים: סקיצה אינה אף אחד מהם. חזרו על העקומות שלה בעזרת המערך או השיקוף של הסקיצה עצמה, או בצעו לה שליפה קודם.",+ "ui.pattern_object_type_tip": "גופים: צורות מלאות, נבחרות בתצוגה או בעץ התכן; כל אחד מועתק בשלמותו.\nפיצ'רים: שלבים בציר הזמן, כמו שליפה או חור, נבחרים בציר הזמן או על פאה שהם יצרו; השלב חוזר על עצמו.\nסקיצה אינה אף אחד מהם: חזרו על העקומות שלה בעזרת המערך או השיקוף של הסקיצה עצמה, או בצעו לה שליפה קודם."+ },+ "ja": {+ "dialog.pattern_sketch_not_object": "ボディかフィーチャーを選んでください。スケッチはどちらでもありません。曲線はスケッチ内のパターンかミラーで繰り返すか、先に押し出してください。",+ "ui.pattern_object_type_tip": "ボディ: ビューまたはブラウザで選ぶ立体形状。それぞれがまるごとコピーされます。\nフィーチャー: 押し出しや穴など履歴のステップ。履歴で、またはそれが作った面で選びます。そのステップが繰り返されます。\nスケッチはどちらでもありません: 曲線はスケッチ内のパターンかミラーで繰り返すか、先に押し出してください。"+ },+ "ko": {+ "dialog.pattern_sketch_not_object": "바디나 피처를 선택하세요. 스케치는 둘 다 아닙니다. 곡선은 스케치 안의 패턴이나 대칭 복사로 반복하거나, 먼저 돌출하세요.",+ "ui.pattern_object_type_tip": "바디: 뷰나 브라우저에서 선택하는 솔리드 형상이며, 각각 통째로 복사됩니다.\n피처: 돌출이나 구멍 같은 기록의 단계이며, 기록에서 또는 그 단계가 만든 면에서 선택합니다. 그 단계가 반복됩니다.\n스케치는 둘 다 아닙니다. 곡선은 스케치 안의 패턴이나 대칭 복사로 반복하거나, 먼저 돌출하세요."+ },+ "vi": {+ "dialog.pattern_sketch_not_object": "Hãy chọn thân khối hoặc tính năng: bản phác thảo không phải là cả hai. Lặp lại các đường cong của nó bằng Mảng hoặc Lấy đối xứng trong chính bản phác thảo, hoặc đùn khối nó trước.",+ "ui.pattern_object_type_tip": "Thân khối: các hình đặc, chọn trong khung nhìn hoặc Trình duyệt; mỗi thân được sao chép nguyên vẹn.\nTính năng: các bước trong Lịch sử, như một lần đùn khối hay một lỗ, chọn trong Lịch sử hoặc trên một mặt do chúng tạo ra; bước đó được lặp lại.\nBản phác thảo không phải là cả hai: lặp lại các đường cong của nó bằng Mảng hoặc Lấy đối xứng trong chính bản phác thảo, hoặc đùn khối nó trước."+ },+ "zh": {+ "dialog.pattern_sketch_not_object": "请选择实体或特征:草图两者都不是。请用草图自身的阵列或镜像重复其曲线,或先将其拉伸。",+ "ui.pattern_object_type_tip": "实体:在视图或浏览器中选取的实心形状,每个都会被整体复制。\n特征:历史中的步骤,例如拉伸或孔,在历史中或在其生成的面上选取;该步骤会被重复。\n草图两者都不是:请用草图自身的阵列或镜像重复其曲线,或先将其拉伸。"+ }+}diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 4ee1173b9c..c5b5004545 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -1606,6 +1606,9 @@ impl Dialog {/// the command starts. The island inside another profile's hole is left out, or it would fill/// the hole. False when the click is not one of those (the caller selects it as usual).pub fn pick_sketch(&mut self, s: &Session, id: u64) -> bool {+ if self.refuse_sketch(s, id) {+ return true;+ }if self.active != 0|| !matches!(self.kind, Kind::Extrude { .. } | Kind::Revolve { .. } | Kind::Emboss { .. })|| !self.inputs.first().is_some_and(|i| i.accept & PROFILES != 0)@@ -1630,6 +1633,21 @@ impl Dialog {true}+ /// A sketch clicked (in the view, the Browser or the History) while a pattern or Mirror waits+ /// for its bodies or features: a sketch is neither, so the dialog says what to do instead of+ /// taking nothing in silence (#10057). False when the click is not one of those.+ pub fn refuse_sketch(&mut self, s: &Session, id: u64) -> bool {+ if self.active != 0+ || !is_pattern(&self.kind)+ || !self.inputs.first().is_some_and(|i| i.accept == BODIES || i.accept == selection::FEATURES)+ || !s.doc.feature(id).is_some_and(|f| matches!(f.kind, FeatureKind::Sketch { .. }))+ {+ return false;+ }+ self.error = Some(SKETCH_NOT_OBJECT.to_string());+ true+ }+/// A pick in the viewport (already accepted by the active input).pub fn pick(&mut self, s: &Session, sel: Sel) {if self.take_extrude_target(s, &sel) {@@ -2411,6 +2429,11 @@ fn objects_label(accept: Accept) -> &'static str {if accept == selection::FEATURES { "Features" } else { "Objects" }}+/// What a pattern or Mirror says when a sketch is clicked for its objects (#10057). It names what+/// to pick, so it shows as a hint rather than an error ([`missing_pick`]).+const SKETCH_NOT_OBJECT: &str =+ "Pick bodies or features: a sketch is neither. Repeat its curves with the sketch's own Pattern or Mirror, or extrude it first.";+fn is_pattern(k: &Kind) -> bool {matches!(k, Kind::PatternRect { .. } | Kind::PatternCirc { .. } | Kind::PathPattern { .. } | Kind::Mirror)}@@ -2421,7 +2444,8 @@ fn object_type_row(d: &mut Dialog, ui: &mut egui::Ui) {let Some(inp) = d.inputs.first_mut() else { return };let cur = usize::from(inp.accept == selection::FEATURES);let mut ty = cur;- choice_row(ui, "Object Type", "pat_obj", &mut ty, &["Bodies", "Features"]);+ // What the two kinds are, and that a sketch is neither (#10057).+ choice_row(ui, "Object Type", "pat_obj", &mut ty, &["Bodies", "Features"]).on_hover_text(crate::i18n::tr("ui.pattern_object_type_tip"));if ty != cur {inp.accept = if ty == 1 { selection::FEATURES } else { BODIES };inp.label = objects_label(inp.accept);diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rsindex 00c74c2684..42795a8e96 100644--- a/crates/ui-egui/src/dialogs_all_tests.rs+++ b/crates/ui-egui/src/dialogs_all_tests.rs@@ -1207,3 +1207,39 @@ fn circular_pattern_dialog_shows_one_active_field_at_a_time() {assert_eq!((active("Objects"), active("Axis")), (false, true), "only Axis looks active");assert_eq!(h.app.dialog.as_ref().unwrap().active, 1, "picks still go to Axis");}++/// #10057: a sketch clicked for a pattern's objects is not taken in silence. In the view, the+/// Browser and the History, with either Object Type, the dialog says a sketch is neither a body+/// nor a feature and what to do instead, as a hint rather than an error; nothing is picked and+/// the selection stays as it was.+#[test]+fn pattern_says_why_a_clicked_sketch_is_not_taken() {+ for (dock, ty) in [("bottom", "Bodies"), ("left", "Features"), ("under_browser", "Bodies")] {+ let mut h = Harness::new();+ h.app.home.open = false;+ h.app.run("view.history_layout", json!({"dock": dock})).unwrap();+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.app.run("sketch.circle.center", json!({"center": [20, 0], "radius": 5})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ h.app.run("select.clear", json!({})).unwrap();+ h.app.start("solid.pattern.circular");+ h.frames(4);+ mirror_object_type(&mut h, ty);+ for click in [json!({"browser": "Sketch1"}), json!({"handle": "timeline:Sketch1"}), json!({"world": [25, 0, 0]})] {+ h.app.dialog.as_mut().unwrap().error = None;+ // Out of double-click time: a double click opens the sketch to edit.+ h.frames(30);+ h.step(&json!({ "click": click })).unwrap();+ h.frames(2);+ let d = h.app.dialog.as_ref().expect("the pattern stays open");+ assert!(matches!(d.kind, Kind::PatternCirc { .. }), "{dock} {ty} {click}");+ assert_eq!(d.error.as_deref(), Some(crate::dialogs::SKETCH_NOT_OBJECT), "{dock} {ty} {click}");+ assert!(d.inputs[0].items.is_empty(), "{dock} {ty} {click}: the sketch is not picked");+ assert!(h.app.session.selection.is_empty(), "{dock} {ty} {click}: the selection stays as it was");+ }+ }+ assert!(crate::dialogs::missing_pick(crate::dialogs::SKETCH_NOT_OBJECT), "shown as what to pick, with no Create Issue");+ let _japanese = crate::i18n::scope("ja");+ assert!(!crate::i18n::tr_label(crate::dialogs::SKETCH_NOT_OBJECT).is_ascii(), "the hint reads in the user's language");+ assert!(!crate::i18n::tr("ui.pattern_object_type_tip").is_ascii(), "so does the Object Type tooltip");+}diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex a5f26a8214..29d1a7128b 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -500,6 +500,10 @@ fn select_range(app: &mut SolveApp, order: &[u64], id: u64, add: bool) {/// Give a History feature click to a compatible active dialog input in any layout./// Plain clicks keep an existing pick; Ctrl/Command clicks toggle it off.pub(crate) fn pick_feature_into_dialog(app: &mut SolveApp, id: u64, modifiers: egui::Modifiers) -> bool {+ // A pattern or Mirror says why it does not take a sketch (#10057).+ if app.dialog.as_mut().is_some_and(|d| d.refuse_sketch(&app.session, id)) {+ return true;+ }let Some(d) = app.dialog.as_mut().filter(|d| d.active_input().is_some_and(|i| i.accept & crate::selection::FEATURES != 0)) else {return false;};diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 4edef830f3..4516bdb699 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -4510,6 +4510,14 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {if let Some((hit, Some(sel))) = cand {dialog_pick(app, &hit, sel);} else if let Some(mut dialog) = app.dialog.take() {+ // A sketch clicked for a pattern's or Mirror's objects: say why it is not taken (#10057).+ let sketch = hits.iter().find_map(|h| match h {+ Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } | Hit::Profile { sketch, .. } => Some(*sketch),+ _ => None,+ });+ if let Some(sketch) = sketch {+ dialog.refuse_sketch(&app.session, sketch);+ }let state = crate::open_meshing::shown_world(app);if let Some(sketch) = app.session.active_sketch.and_then(|id| state.sketch(id)) {let (origin, direction) = proj.ray(p);