diff --git a/assets/locales/pending/sketch-conflict-colour.json b/assets/locales/pending/sketch-conflict-colour.json new file mode 100644 index 000000000..0c8581f34 --- /dev/null +++ b/assets/locales/pending/sketch-conflict-colour.json @@ -0,0 +1,42 @@ +{ + "en": { + "prefs.sketch_conflict_colour": "Conflicting geometry in the conflict color", + "prefs.sketch_conflict_colour_note": "While a sketch's constraints conflict, the curves and points a failing constraint holds are drawn in the conflict color too, not only its glyph or dimension. Off: they keep their usual colors." + }, + "en-GB": { + "prefs.sketch_conflict_colour": "Conflicting geometry in the conflict colour", + "prefs.sketch_conflict_colour_note": "While a sketch's constraints conflict, the curves and points a failing constraint holds are drawn in the conflict colour too, not only its glyph or dimension. Off: they keep their usual colours." + }, + "de": { + "prefs.sketch_conflict_colour": "Widersprüchliche Geometrie in der Konfliktfarbe", + "prefs.sketch_conflict_colour_note": "Solange die Bedingungen einer Skizze im Konflikt stehen, werden auch die Kurven und Punkte, die eine nicht erfüllte Bedingung hält, in der Konfliktfarbe gezeichnet, nicht nur ihr Symbol oder ihre Bemaßung. Aus: Sie behalten ihre üblichen Farben." + }, + "ja": { + "prefs.sketch_conflict_colour": "競合するジオメトリを競合色で表示", + "prefs.sketch_conflict_colour_note": "スケッチの拘束が競合している間、満たされない拘束のグリフや寸法だけでなく、その拘束が保持する曲線と点も競合色で描画します。オフ: 通常の色のままです。" + }, + "ko": { + "prefs.sketch_conflict_colour": "충돌하는 기하를 충돌 색상으로 표시", + "prefs.sketch_conflict_colour_note": "스케치의 구속 조건이 충돌하는 동안 실패한 구속 조건의 글리프나 치수뿐 아니라 그 구속 조건이 잡고 있는 곡선과 점도 충돌 색상으로 그립니다. 끄기: 평소 색상을 유지합니다." + }, + "nl": { + "prefs.sketch_conflict_colour": "Conflicterende geometrie in de conflictkleur", + "prefs.sketch_conflict_colour_note": "Zolang de beperkingen van een schets conflicteren, worden ook de curven en punten die een niet-vervulde beperking vasthoudt in de conflictkleur getekend, niet alleen het symbool of de maat ervan. Uit: ze houden hun gewone kleuren." + }, + "zh": { + "prefs.sketch_conflict_colour": "以冲突颜色显示冲突的几何图形", + "prefs.sketch_conflict_colour_note": "草图约束冲突时,不仅失败约束的符号或尺寸,该约束所约束的曲线和点也以冲突颜色绘制。关闭:它们保持平常的颜色。" + }, + "ar": { + "prefs.sketch_conflict_colour": "الهندسة المتعارضة بلون التعارض", + "prefs.sketch_conflict_colour_note": "عندما تتعارض قيود الرسم، تُرسم المنحنيات والنقاط التي يمسكها قيد فاشل بلون التعارض أيضًا، لا رمزه أو بُعده فقط. عند الإيقاف: تحتفظ بألوانها المعتادة." + }, + "he": { + "prefs.sketch_conflict_colour": "גאומטריה סותרת בצבע הסתירה", + "prefs.sketch_conflict_colour_note": "כשאילוצי סקיצה סותרים, העקומות והנקודות שאילוץ כושל מחזיק מצוירות גם הן בצבע הסתירה, לא רק הסמל או המידה שלו. כבוי: הן שומרות על צבעיהן הרגילים." + }, + "vi": { + "prefs.sketch_conflict_colour": "Hình học xung đột theo màu xung đột", + "prefs.sketch_conflict_colour_note": "Khi các ràng buộc của bản phác xung đột, các đường cong và điểm mà một ràng buộc lỗi giữ cũng được vẽ bằng màu xung đột, không chỉ ký hiệu hay kích thước của nó. Tắt: chúng giữ màu thường." + } +} diff --git a/assets/styles/ui/palettes.rs b/assets/styles/ui/palettes.rs index 59da0e3ce..719324a5f 100644 --- a/assets/styles/ui/palettes.rs +++ b/assets/styles/ui/palettes.rs @@ -193,6 +193,8 @@ impl Tokens { sketch_halo: Color32::from_rgb(240, 243, 247), sketch_point: Color32::BLACK, sketch_locked: Color32::from_rgb(0, 140, 60), + // The error red (`error`). + sketch_conflict: Color32::from_rgb(214, 54, 54), // Sketch dimensions in a plum of their own, apart from the blue and black curves for // every colour vision mode (#7861). dimension: Color32::from_rgb(130, 42, 110), @@ -343,6 +345,7 @@ impl Tokens { t.selected_bg = Color32::from_rgb(42, 70, 110); t.construction_geom = icon_primary(crate::icon_svg::CONSTRUCTION_PRIMARY[1]); t.error = Color32::from_rgb(240, 100, 96); + t.sketch_conflict = t.error; t.warning = Color32::from_rgb(236, 170, 70); t.icon = Color32::from_rgb(208, 214, 226); t.timeline = Color32::from_rgb(33, 37, 45); @@ -413,6 +416,9 @@ impl Tokens { } t.construction_geom = icon_primary(crate::icon_svg::CONSTRUCTION_RED_GREEN[dark as usize]); t.glyph_text = icon_primary(crate::icon_svg::CONSTRAINT_RED_GREEN[dark as usize]); + // A deeper red keeps conflicting sketch geometry (#7244) apart from the orange + // construction and centerline lines and the crimson lost links for a red-green loss. + t.sketch_conflict = Color32::from_rgb(195, 35, 30); t.surface_accent = if dark { Color32::from_rgb(200, 135, 55) } else { Color32::from_rgb(164, 80, 0) }; t.mesh_accent = if dark { Color32::from_rgb(190, 175, 70) } else { Color32::from_rgb(130, 103, 0) }; t.form_accent = if dark { Color32::from_rgb(165, 135, 220) } else { Color32::from_rgb(115, 73, 205) }; @@ -443,6 +449,9 @@ impl Tokens { t.preview_sketch = Color32::from_rgb(125, 180, 105); t.glyph_text = icon_primary(crate::icon_svg::CONSTRAINT_BLUE_YELLOW[dark as usize]); t.construction_geom = icon_primary(crate::icon_svg::CONSTRUCTION_BLUE_YELLOW[dark as usize]); + // Conflicting sketch geometry (#7244) apart from the lost links and the construction and + // centerline lines for a blue-yellow loss: darker on the light view, lighter on the dark. + t.sketch_conflict = if dark { Color32::from_rgb(255, 170, 160) } else { Color32::from_rgb(165, 15, 30) }; if dark { t.sketch_locked = Color32::from_rgb(140, 225, 110); t.box_crossing = Color32::from_rgb(240, 110, 170); diff --git a/assets/styles/ui/themes/1-bit-dark.json b/assets/styles/ui/themes/1-bit-dark.json index e3da0763d..0da2cff2f 100644 --- a/assets/styles/ui/themes/1-bit-dark.json +++ b/assets/styles/ui/themes/1-bit-dark.json @@ -144,6 +144,7 @@ "sketch": "#ffffff", "sketch_accent": "#ffffff", "sketch_centerline": "#ffffff", + "sketch_conflict": "#ffffff", "sketch_construction": "#ffffff", "sketch_fixed": "#ffffff", "sketch_halo": "#000000", diff --git a/assets/styles/ui/themes/1-bit.json b/assets/styles/ui/themes/1-bit.json index 2781f3c57..a8236c52c 100644 --- a/assets/styles/ui/themes/1-bit.json +++ b/assets/styles/ui/themes/1-bit.json @@ -144,6 +144,7 @@ "sketch": "#000000", "sketch_accent": "#000000", "sketch_centerline": "#000000", + "sketch_conflict": "#000000", "sketch_construction": "#000000", "sketch_fixed": "#000000", "sketch_halo": "#ffffff", diff --git a/assets/styles/ui/themes/cga.json b/assets/styles/ui/themes/cga.json index 90e5623d2..c53e8559e 100644 --- a/assets/styles/ui/themes/cga.json +++ b/assets/styles/ui/themes/cga.json @@ -144,6 +144,7 @@ "sketch": "#55ffff", "sketch_accent": "#ff55ff", "sketch_centerline": "#ffff55", + "sketch_conflict": "#ff5555", "sketch_construction": "#aaaaaa", "sketch_fixed": "#ffffff", "sketch_halo": "#000000", diff --git a/crates/ui-egui/src/colour_vision_tests.rs b/crates/ui-egui/src/colour_vision_tests.rs index 975176572..0c1d030de 100644 --- a/crates/ui-egui/src/colour_vision_tests.rs +++ b/crates/ui-egui/src/colour_vision_tests.rs @@ -259,6 +259,7 @@ fn groups(t: &Tokens) -> Vec { ("sketch", t.sketch), ("sketch_fixed", t.sketch_fixed), ("sketch_locked", t.sketch_locked), + ("sketch_conflict", t.sketch_conflict), ("sketch_projected", t.sketch_projected), ("sketch_lost", t.sketch_lost), ("sketch_construction", t.sketch_construction), @@ -269,7 +270,12 @@ fn groups(t: &Tokens) -> Vec { ), group( "sketch points", - &[("sketch_point", t.sketch_point), ("sketch_point_free", t.sketch_point_free), ("sketch_locked", t.sketch_locked)], + &[ + ("sketch_point", t.sketch_point), + ("sketch_point_free", t.sketch_point_free), + ("sketch_locked", t.sketch_locked), + ("sketch_conflict", t.sketch_conflict), + ], &[("viewport_top", t.viewport_top)], ), group( @@ -766,6 +772,7 @@ fn each_mode_changes_only_its_table() { "sketch_accent", "preview_sketch", "form_success_fill", + "sketch_conflict", ]; let mut red_green_light = red_green_both.into_iter().filter(|name| !["surface_accent", "mesh_accent", "form_accent"].contains(name)).collect::>(); @@ -788,6 +795,7 @@ fn each_mode_changes_only_its_table() { "construction_geom", "glyph_text", "preview_sketch", + "sketch_conflict", "analysis.hatch", ]), ), @@ -804,6 +812,7 @@ fn each_mode_changes_only_its_table() { "construction_geom", "glyph_text", "preview_sketch", + "sketch_conflict", "analysis.hatch", ]), ), diff --git a/crates/ui-egui/src/dim_view.rs b/crates/ui-egui/src/dim_view.rs index 78873c772..bc5db1c7d 100644 --- a/crates/ui-egui/src/dim_view.rs +++ b/crates/ui-egui/src/dim_view.rs @@ -656,7 +656,7 @@ pub fn show(app: &mut SolveApp, ui: &egui::Ui, painter: &egui::Painter, proj: &P let expr = c.param.as_ref().and_then(|p| display_doc.param(p)).map(|p| p.expr.as_str()); let failing = source.report.failing.contains(&c.id); let col = if failing { - tk.error + crate::viewport::Conflict::glyph_colour(app, &tk) } else if is_sel(&c.id) || hover.as_deref() == Some(c.id.as_str()) { tk.accent } else if c.driven { diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 6b4fd67c7..746b4877e 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1150,6 +1150,10 @@ preference_settings! { selection_shift_add_only: bool = false, PAGE_SKETCH; /// Prefer movable sketch points on exact selection ties; off keeps point insertion order. prefer_free_sketch_points: bool = true, PAGE_SKETCH; + /// While the open sketch's constraints conflict, the curves and points a failing constraint + /// holds, and its glyph or dimension, are drawn in `sketch_conflict` (#7244). Off: only the + /// glyphs and dimensions are red, in `error`, as before. + sketch_conflict_colour: bool = true, PAGE_SKETCH => check_id("prefs.sketch_conflict_colour"); /// Drive Joints shows the moved parts' old place as a ghost (its Show ghost box, #5905). drive_joints_ghost: bool = true, PAGE_DESIGN; /// Plugin ids turned off (Preferences › Plugins). An installed plugin whose id is absent is on. @@ -4523,6 +4527,7 @@ mod tests { ("nav", json!("blender"), PAGE_NAVIGATION), ("look_at_anim", json!(false), PAGE_NAVIGATION), ("selection_shift_add_only", json!(true), PAGE_SKETCH), + ("sketch_conflict_colour", json!(false), PAGE_SKETCH), ("suppress_sketch_snap", json!(ModifierCombo::NONE), PAGE_SKETCH), ("sketch_state_icons", json!(false), PAGE_SKETCH), ("sketch_tracking_guides", json!(false), PAGE_SKETCH), diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs index d9fa0da15..3ace7d3f1 100644 --- a/crates/ui-egui/src/prefs/sketch.rs +++ b/crates/ui-egui/src/prefs/sketch.rs @@ -61,6 +61,9 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) { ui_kit::checkbox(ui, app.tr("prefs.alt_frees_manipulators"), &mut app.preferences.manipulator_free_alt).on_hover_text(crate::i18n::tr_label( "On: Alt/Option or Ctrl/Cmd on extrude / gizmo arrows disables value snapping. Off: Ctrl/Cmd only.", )); + // Conflicting curves and points in the conflict colour (#7244). + let check = setting::sketch_conflict_colour(app, ui).on_hover_text(app.tr("prefs.sketch_conflict_colour_note")); + crate::scenario::publish_target("prefs:sketch_conflict_colour", check.rect); }); ui_kit::settings_section(ui, "selection", app.tr("prefs.selecting"), |ui| { ui_kit::checkbox(ui, crate::i18n::tr_label("Click selects whole bodies"), &mut app.ui.pick_bodies); diff --git a/crates/ui-egui/src/sketch_tools.rs b/crates/ui-egui/src/sketch_tools.rs index 468946eeb..48531ad3a 100644 --- a/crates/ui-egui/src/sketch_tools.rs +++ b/crates/ui-egui/src/sketch_tools.rs @@ -1294,7 +1294,7 @@ pub fn preview(app: &SolveApp, t: &Tool, painter: &egui::Painter, proj: &Proj) { } /// Constraint glyphs of the active sketch: a small badge per constraint at its anchor -/// (conflicting ones red). +/// (failing ones in `sketch_conflict`). /// Glyph size and spacing (screen pixels). const GLYPH: f32 = 15.0; @@ -1401,7 +1401,7 @@ fn glyphs(app: &SolveApp, painter: &egui::Painter, proj: &Proj, hover: Option Tokens { // Malformed hand-edited saved settings cannot introduce non-finite drawing geometry. t.borders = parse_borders(&theme.borders).unwrap_or_default(); t.icon_palette = parse_icon_palette(&theme.icon_palette).unwrap_or_default(); + // Conflicting sketch geometry is drawn in the theme's own error colour unless it sets one of + // its own (#7244). + if !theme.colors.contains_key("sketch_conflict") { + t.sketch_conflict = t.error; + } // A file that sets no colours is its base palette, exactly. if !theme.colors.is_empty() { file_view_from_theme(&mut t, theme.base.is_dark(), |k| theme.colors.contains_key(k)); @@ -1211,6 +1216,27 @@ mod tests { assert_eq!(p.text, Tokens::light().text); } + /// Conflicting sketch geometry (#7244) is the error red by default, follows a theme's own + /// `error` when the theme leaves `sketch_conflict` out, and takes the theme's own key when set. + #[test] + fn sketch_conflict_defaults_to_the_error_colour_and_a_theme_can_set_its_own() { + for t in [Tokens::light(), Tokens::dark()] { + assert_eq!(t.sketch_conflict, t.error); + } + let file = |colors: &str| { + resolve(&parse(&format!(r#"{{"format":"solidcraft-theme/1","name":"Conflict","base":"light","colors":{{{colors}}}}}"#)).unwrap()) + }; + let (red, green) = (Color32::from_rgb(0xcc, 0x24, 0x1d), Color32::from_rgb(0x12, 0xab, 0x34)); + assert_eq!(file(r##""error":"#cc241d""##).sketch_conflict, red, "the theme's error colour"); + assert_eq!(file(r##""error":"#cc241d","sketch_conflict":"#12ab34""##).sketch_conflict, green, "the theme's own key wins"); + assert_eq!(file(r##""panel":"#102030""##).sketch_conflict, Tokens::light().error); + for theme in builtin() { + let t = resolve(theme); + assert_eq!(t.sketch_conflict, t.error, "{}: conflicts in the theme's error colour", theme.id); + } + assert!(keys().contains(&"sketch_conflict"), "exported and imported by name"); + } + /// A theme file written before the axes were one set (#976) still reads: its view triad and /// Move gizmo lists colour every axis, the triad over the gizmo and `axis_*` over both. #[test] diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 82228cd8a..32ea91e07 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -496,6 +496,8 @@ fn sketch_scene_key(app: &SolveApp, proj: &Proj) -> u64 { app.preferences.sketch_halo.hash(&mut h); // The grid previews the plane Create Sketch would take (#6975). previewed_sketch_plane(app).map(|p| [p.origin, p.x, p.y].map(|v| [v.x, v.y, v.z].map(f64::to_bits))).hash(&mut h); + // Conflicting curves in their own colour, or as before (#7244). + app.preferences.sketch_conflict_colour.hash(&mut h); (std::sync::Arc::as_ptr(&crate::open_meshing::shown_world(app)) as usize).hash(&mut h); crate::sketch_display::projection_key(proj, app.viewport.pixels_per_point()).hash(&mut h); h.finish() @@ -1586,12 +1588,22 @@ fn build_sketch_scene(app: &SolveApp, proj: &Proj) -> GpuScene { // All the halos go first, so one curve's halo never cuts into another where they meet. let unit = grid_step(app.cam.half_height()).0; let mut strokes = Vec::new(); - for (pts, col, cons) in sketch_lines_with_sampler(&ss.sketch, &ss.plane, active, &ss.report.curve_determined, |_, index, plane| { - crate::sketch_display::curve_sample(app, sid, index, plane, proj).parts.clone() - }) { + // The open sketch's curves a failing constraint holds take the conflict colour (#7244). + // The lines come curve by curve, each curve's parts in the order its sampler returned + // them, before the virtual corners and 3D curves: `owners` names each part's curve. + let conflict = if active { Conflict::of(app, &ss.sketch, &ss.report) } else { Conflict::default() }; + let mut owners = Vec::new(); + let lines = sketch_lines_with_sampler(&ss.sketch, &ss.plane, active, &ss.report.curve_determined, |_, index, plane| { + let parts = crate::sketch_display::curve_sample(app, sid, index, plane, proj).parts.clone(); + owners.extend(std::iter::repeat_n(index, parts.len())); + parts + }); + for (k, (pts, col, cons)) in lines.into_iter().enumerate() { + let conflicting = owners.get(k).is_some_and(|&curve| conflict.curve(curve)); let segs = sketch_segments(&pts, sketch_line_mode(col, cons), unit); let haloed = app.preferences.sketch_halo && !active && col != colors::SKETCH_PROJECTED && col != colors::SKETCH_LOST; - strokes.push((segs, sc.color(sketch_color(&tk, col)), if cons { 1.2 } else { 2.0 }, haloed)); + let colour = if conflicting { c4(tk.sketch_conflict) } else { sketch_color(&tk, col) }; + strokes.push((segs, sc.color(colour), if cons { 1.2 } else { 2.0 }, haloed)); } // Active sketches retain their existing through-body display. Inactive sketches // can opt into the same behaviour in Preferences. @@ -5401,6 +5413,7 @@ fn overlays(app: &SolveApp, painter: &egui::Painter, proj: &Proj) { let Some(ss) = st.sketch(sid) else { return }; let sk = &ss.sketch; let locked = sk.locked_points(); + let conflict = Conflict::of(app, sk, &ss.report); let virtual_corners: Vec = sk.virtual_corners().into_iter().map(|(i, _)| i).collect(); let visible = solidcraft_engine::view::SketchPointVisibility::new(sk); for (i, p) in sk.points.iter().enumerate() { @@ -5410,7 +5423,9 @@ fn overlays(app: &SolveApp, painter: &egui::Painter, proj: &Proj) { let hidden = (sk.view.hide_points && i != 0) || (sk.view.hide_projected && p.link.is_some()); let Some(sp) = proj.to_screen(ss.plane.to_world(p.pos)).filter(|_| !hidden) else { continue }; let det = ss.report.point_determined.get(i).copied().unwrap_or(false); - let c = if p.link.is_none() && locked.get(i).copied().unwrap_or(false) { + let c = if conflict.point(i) { + t.sketch_conflict + } else if p.link.is_none() && locked.get(i).copied().unwrap_or(false) { t.sketch_locked } else if det { t.sketch_point @@ -5455,6 +5470,52 @@ fn overlays(app: &SolveApp, painter: &egui::Painter, proj: &Proj) { } } +/// The curves and points of a sketch that its failing constraints hold (the solve's `failing`: +/// the constraints still violated after a failed solve). They are drawn in `sketch_conflict` +/// until the conflict is gone (#7244); redundant constraints that hold are not failing. None +/// while the Sketch preference `sketch_conflict_colour` is off. +#[derive(Default)] +pub(crate) struct Conflict { + curves: Vec, + points: Vec, +} + +impl Conflict { + pub(crate) fn of(app: &SolveApp, sk: &solidcraft_engine::sketch::Sketch, report: &solidcraft_engine::sketch::SolveReport) -> Conflict { + let mut out = Conflict::default(); + if !app.preferences.sketch_conflict_colour || report.failing.is_empty() { + return out; + } + out.curves = vec![false; sk.curves.len()]; + out.points = vec![false; sk.points.len()]; + for c in sk.constraints.iter().filter(|c| report.failing.contains(&c.id)) { + let (points, curves) = c.kind.indices(); + for (held, of) in [(points, &mut out.points), (curves, &mut out.curves)] { + for i in held { + if let Some(slot) = of.get_mut(i) { + *slot = true; + } + } + } + } + out + } + + pub(crate) fn curve(&self, i: usize) -> bool { + self.curves.get(i).copied().unwrap_or(false) + } + + pub(crate) fn point(&self, i: usize) -> bool { + self.points.get(i).copied().unwrap_or(false) + } + + /// A failing constraint's glyph or dimension: `sketch_conflict`, or with the preference off + /// the error red it always had. + pub(crate) fn glyph_colour(app: &SolveApp, t: &Tokens) -> Color32 { + if app.preferences.sketch_conflict_colour { t.sketch_conflict } else { t.error } + } +} + /// Where a profile can fail: a ring round each open end (it touches no other curve) and a /// diamond round each untied one (it touches another curve only by position), told apart by /// shape. Both are warnings, not errors: an open sketch (a sweep path, an axis) is valid. diff --git a/crates/ui-egui/src/viewport_appearance_tests.rs b/crates/ui-egui/src/viewport_appearance_tests.rs index 60613e315..aa011d424 100644 --- a/crates/ui-egui/src/viewport_appearance_tests.rs +++ b/crates/ui-egui/src/viewport_appearance_tests.rs @@ -405,3 +405,108 @@ fn inspect_menu_toggles_component_colors_without_a_dialog_and_refreshes_scene() let info = command.info(&h.app.session); assert_eq!((info.label, info.icon), ("Enable Component Colors", "colored_components")); } + +/// Every shape the last frame painted in `colour`: point squares, glyph outlines, dimension +/// lines and arrows. +fn painted_in(shapes: &[egui::epaint::ClippedShape], colour: egui::Color32) -> usize { + fn walk(shape: &egui::Shape, colour: egui::Color32) -> usize { + let solid = |c: &egui::epaint::ColorMode| matches!(c, egui::epaint::ColorMode::Solid(x) if *x == colour); + match shape { + egui::Shape::Vec(shapes) => shapes.iter().map(|s| walk(s, colour)).sum(), + egui::Shape::Rect(r) => usize::from(r.fill == colour || r.stroke.color == colour), + egui::Shape::Circle(c) => usize::from(c.fill == colour || c.stroke.color == colour), + egui::Shape::LineSegment { stroke, .. } => usize::from(stroke.color == colour), + egui::Shape::Path(p) => usize::from(p.fill == colour || solid(&p.stroke.color)), + _ => 0, + } + } + shapes.iter().map(|s| walk(&s.shape, colour)).sum() +} + +#[test] +fn conflicting_curves_points_glyphs_and_dimensions_take_the_conflict_colour_until_the_conflict_is_gone() { + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + // A conflict colour nothing else in a sketch uses: every line and shape in it is a conflict's. + let marker = egui::Color32::from_rgb(0x12, 0xab, 0x34); + h.call( + "ui.prefs", + json!({"theme_import": {"format":"solidcraft-theme/1","name":"Conflict marker","base":"light","colors":{"sketch_conflict":"#12ab34"}}}), + ); + h.frame(); + assert_eq!(crate::theme::Tokens::get().sketch_conflict, marker); + // `w` places a guide line; a second sketch ends a 12 mm line on it. Moving the guide out of + // reach makes the second sketch's constraints conflict (#7244). + let app = &mut h.app; + app.run("parameters.add", json!({"name": "w", "expression": "10 mm"})).unwrap(); + app.run("sketch.create", json!({"plane": "XY", "name": "Guide"})).unwrap(); + app.run("sketch.line", json!({"points": [[10, -30], [10, 30]], "ids": ["guide"], "connect": false})).unwrap(); + app.run("sketch.constraint.horizontal_vertical", json!({"line": "guide", "mode": "vertical"})).unwrap(); + app.run("sketch.dimension", json!({"entities": ["origin", "guide.start"], "type": "horizontal", "value": "w"})).unwrap(); + app.run("sketch.finish", json!({})).unwrap(); + let reach = app.run("sketch.create", json!({"plane": "XY", "name": "Reach"})).unwrap()["sketch"].as_u64().unwrap(); + let projected = app.run("sketch.project", json!({"refs": [{"sketch": "Guide", "curve": "guide"}]})).unwrap()["links"][0]["curves"][0] + .as_str() + .unwrap() + .to_string(); + let line = app.run("sketch.line", json!({"points": [[0, 0], [10, -(44.0_f64).sqrt()]]})).unwrap()["curves"][0].as_str().unwrap().to_string(); + app.run("sketch.dimension", json!({"entities": [line], "value": 12})).unwrap(); + app.run("sketch.constraint.coincident", json!({"a": format!("{line}.end"), "b": projected})).unwrap(); + // A second, unrelated line: never part of the conflict. + let other = app.run("sketch.line", json!({"points": [[-20, 5], [-5, 5]]})).unwrap()["curves"][0].as_str().unwrap().to_string(); + app.run("sketch.finish", json!({})).unwrap(); + let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0)); + let conflict_lines = |app: &SolveApp| { + let scene = super::build_sketch_scene(app, &super::projection(app, rect)); + let (lines, _) = scene.overlay.as_chunks::<{ crate::gpu::LINE_SIZE }>(); + // A line names its colour by palette index (bytes 24..28). + lines + .iter() + .filter_map(|line| line.get(24..28)?.try_into().ok().map(u32::from_le_bytes)) + .filter(|&i| scene.palette.get(crate::gpu::PaletteIndex(i)) == Some(super::c4(marker))) + .count() + }; + for (w, conflicting, preference) in [("10 mm", false, true), ("20 mm", true, true), ("20 mm", true, false), ("10 mm", false, true)] { + h.app.preferences.sketch_conflict_colour = preference; + if h.app.session.active_sketch.is_some() { + h.app.run("sketch.finish", json!({})).unwrap(); + } + h.app.run("parameters.change", json!({"name": "w", "expression": w})).unwrap(); + h.app.edit_sketch(reach); + h.settle(); + assert_eq!(h.app.session.active_sketch, Some(reach)); + let st = h.app.session.world_state(); + let ss = st.sketch(reach).unwrap(); + assert_eq!(!ss.report.ok(), conflicting, "w = {w}: {:?}", ss.report); + let conflict = super::Conflict::of(&h.app, &ss.sketch, &ss.report); + let failing: Vec<_> = ss.sketch.constraints.iter().filter(|c| ss.report.failing.contains(&c.id)).collect(); + assert_eq!(failing.is_empty(), !conflicting, "w = {w}: {:?}", ss.report); + // With the preference off, nothing is in the conflict colour: the failing glyphs and + // dimensions are red (`error`), as before. + let failing: Vec<_> = if preference { failing } else { Vec::new() }; + // Exactly the curves and points the failing constraints hold. + for (i, curve) in ss.sketch.curves.iter().enumerate() { + let held = failing.iter().any(|c| c.kind.indices().1.contains(&i)); + assert_eq!(conflict.curve(i), held, "w = {w}: curve {}", curve.id); + } + for i in 0..ss.sketch.points.len() { + assert_eq!(conflict.point(i), failing.iter().any(|c| c.kind.indices().0.contains(&i)), "w = {w}: point {i}"); + } + let other = ss.sketch.curve_index(&other).unwrap(); + assert!(!conflict.curve(other)); + // Drawn: the held curves' lines, and the held points, the failing glyphs and dimensions. + let (lines, shapes) = (conflict_lines(&h.app), painted_in(&h.shapes, marker)); + if conflicting && preference { + assert!(lines > 0, "the held curves are drawn in the conflict colour"); + assert!(shapes > 0, "points, glyphs or dimensions in the conflict colour"); + } else { + assert_eq!((lines, shapes), (0, 0), "w = {w}, preference {preference}: nothing in the conflict colour"); + } + if conflicting && !preference { + let error = crate::theme::Tokens::get().error; + assert!(painted_in(&h.shapes, error) > 0, "the failing glyphs and dimensions stay red"); + } + } + h.call("ui.prefs", json!({"theme": "dark"})); + h.frame(); +} diff --git a/docs/book/src/guide/sketching.md b/docs/book/src/guide/sketching.md index b763b0f70..29146f17f 100644 --- a/docs/book/src/guide/sketching.md +++ b/docs/book/src/guide/sketching.md @@ -316,6 +316,15 @@ shows the remaining degrees of freedom. A constraint or dimension that would ove sketch is refused rather than applied. Drag a point to move it; the solver keeps every constraint while you drag. +A sketch's constraints can still come to conflict through a change elsewhere: a parameter, or an +earlier sketch that projected geometry follows. While they do, the curves and points a failing +constraint holds, and that constraint's glyph or dimension, are drawn in the conflict colour (red; +the theme key `sketch_conflict`, which follows a theme's `error` colour unless the theme sets it), +so the constraint to change or remove is easy to find. Constraints that are only redundant (implied +by others, still holding) keep their usual look. Preferences › Sketch › **Conflicting geometry in +the conflict colour** (on by default) turns this off: then only the glyphs and dimensions of the +failing constraints are red, as in earlier versions. + ## Profiles Closed loops become profiles automatically, including regions split by crossing lines and diff --git a/docs/control-protocol.md b/docs/control-protocol.md index b2dd2342c..089346536 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -363,6 +363,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own - `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle) - `sketch_auto_dimensions` (default false: each shape drawn in a sketch gets all its dimensions at the sizes drawn, as `sketch.draw.dimensioned` with `as_drawn`; typed values win) - `sketch_auto_locate` (default false; with `sketch_auto_dimensions`, new shapes are also placed from the sketch origin until fully constrained, as `sketch.draw.dimensioned` with `locate`) +- `sketch_conflict_colour` (default true: while the open sketch's constraints conflict, the curves and points a failing constraint holds are drawn in the theme's `sketch_conflict` colour too, not only its glyph or dimension; false: only the glyphs and dimensions are red, in `error`, as before, #7244) - `sketch_exit_view` (`keep` (default: the view stays where it is when a sketch ends), `previous` (back to the view from before the sketch), `unless_rotated` (back unless the sketch view was turned)) - `sketch_state_icons` (default true: a sketch's icon in History and the browser takes the colour of its solve state, `sketch` under constrained, `sketch_fixed` fully constrained, `error` while its constraints conflict, and its tooltip names the state; false: every sketch row's icon and tooltip as before, #7245) - `sketch_tab_always` (default false: the SKETCH tab stays in the ribbon right after MODEL while no sketch is open; a tool in its CREATE or REFERENCE section then opens Create Sketch, on the selected plane or planar face or else on the plane picked next, and starts in the new sketch, #7904)