diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a4fc8f7da..bc982542d 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2248,13 +2248,14 @@ fn object_type_row(d: &mut Dialog, ui: &mut egui::Ui) { /// Rows above the selection inputs: the pattern type and object type, the Hole placement (one /// face point, or sketch points). -fn placement_row(d: &mut Dialog, ui: &mut egui::Ui, session: &Session) { +fn placement_row(d: &mut Dialog, ui: &mut egui::Ui, app: &SolveApp) { + let session = &app.session; if matches!(d.kind, Kind::Mirror) { object_type_row(d, ui); return; } if matches!(d.kind, Kind::Move { .. }) { - crate::dialogs_move::type_row(d, ui, &session.doc); + crate::dialogs_move::type_row(app, d, ui); return; } let current = match d.kind { diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index ede0ecca9..650e9bf33 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -183,7 +183,7 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: if let Some(key) = manage_hint { ui_kit::text(ui, tr(key), ui_kit::Text::Hint("manage")); } - placement_row(d, ui, &app.session); + placement_row(d, ui, app); if crate::hole_refs::takes(d) { // Each reference edge with its distance (#37, #6380). enter |= crate::hole_refs::input_rows(d, ui, &app.session, app.preferences.origin_plane_names); diff --git a/crates/ui-egui/src/dialogs_move.rs b/crates/ui-egui/src/dialogs_move.rs index 87c98d81e..e243e11d9 100644 --- a/crates/ui-egui/src/dialogs_move.rs +++ b/crates/ui-egui/src/dialogs_move.rs @@ -1,12 +1,15 @@ //! Move/Copy: the move types (Free Move, Translate, Rotate, Point to Point, Point to Position), //! their rows and inputs, the triad on the canvas and the solid.move they make. Nothing -//! moves until a value is typed or the triad is dragged. +//! moves until a value is typed or the triad is dragged. Switching the type keeps the move made +//! so far, and the next type moves the bodies on from where it left them: one solid.move holds +//! the whole chain. use crate::selection::SelectionExt as _; use crate::ui_kit::{choice_row, expr_row}; use serde_json::{Value, json}; use solidcraft_engine::Sel; use solidcraft_engine::doc::expr::Kind as ValueKind; +use solidcraft_engine::doc::{Mat, apply_point, apply_vector, is_identity, mat_inverse, mat_mul, rigid}; use solidcraft_engine::geom::Vec3; use crate::SolveApp; @@ -45,27 +48,113 @@ pub fn inputs(mode: usize) -> Vec { v } -/// The Move Type row (above the inputs); switching keeps the bodies and resets the values. -pub fn type_row(d: &mut Dialog, ui: &mut egui::Ui, doc: &solidcraft_engine::doc::Document) { +/// The Move Type row (above the inputs); switching keeps the bodies and the move made so far +/// (`chain`), and starts the new type's values at zero. +pub fn type_row(app: &SolveApp, d: &mut Dialog, ui: &mut egui::Ui) { let Kind::Move { mode, .. } = d.kind else { return }; let mut m = mode; choice_row(ui, "Move Type", "move_type", &mut m, &TYPES); if m != mode { - let bodies = d.inputs.first().map(|i| i.items.clone()).unwrap_or_default(); - d.kind = kind(m, doc); - d.inputs = inputs(m); - if let Some(i) = d.inputs.first_mut() { - i.items = bodies; - } - d.extra.remove("pivot"); - d.active = if bodies_empty(d) { 0 } else { 1.min(d.inputs.len() - 1) }; + switch_type(app, d, m); } } +/// Change the Move Type to `m`, keeping the move made so far. +fn switch_type(app: &SolveApp, d: &mut Dialog, m: usize) { + // A type whose picks are missing or whose values don't evaluate adds nothing. + if let Ok(Step::Made(p)) = step(app, d) + && let Ok(made) = transform(app, &p) + { + let total = chain(d).map_or(made, |c| mat_mul(&made, &c)); + d.extra.insert("chain".into(), json!(total)); + } + let bodies = d.inputs.first().map(|i| i.items.clone()).unwrap_or_default(); + d.kind = kind(m, &app.session.doc); + d.inputs = inputs(m); + if let Some(i) = d.inputs.first_mut() { + i.items = bodies; + } + d.extra.remove("pivot"); + d.active = if bodies_empty(d) { 0 } else { 1.min(d.inputs.len() - 1) }; +} + fn bodies_empty(d: &Dialog) -> bool { d.inputs.first().is_none_or(|i| i.items.is_empty()) } +/// The move made under earlier types, which the current type moves the bodies on from. +fn chain(d: &Dialog) -> Option { + let m: Mat = serde_json::from_value(d.extra.get("chain")?.clone()).ok()?; + (!is_identity(&m)).then_some(m) +} + +/// The moved bodies and where the move so far puts them (the earlier types' move, then the +/// current type's as far as it is made), while a Move dialog moves any: the picker finds them, +/// and their highlights and centres show, where the preview draws them, also mid-drag. +pub(crate) fn chained(app: &SolveApp) -> Option<(Vec, Mat)> { + let d = app.dialog.as_ref().filter(|d| matches!(d.kind, Kind::Move { .. }))?; + let m = match (made(app, d), chain(d)) { + (Some(s), Some(c)) => mat_mul(&s, &c), + (Some(s), None) => s, + (None, c) => c?, + }; + (!is_identity(&m)).then(|| (items(d, 0).body_names(), m)) +} + +/// Whether the triad is being dragged in a Move dialog (`drag` keeps the values it began from). +pub(crate) fn dragging(app: &SolveApp) -> bool { + app.dialog.as_ref().is_some_and(|d| matches!(d.kind, Kind::Move { .. }) && d.extra.contains_key("drag0")) +} + +/// The current type's own move, when its picks and values make one. +fn made(app: &SolveApp, d: &Dialog) -> Option { + match step(app, d) { + Ok(Step::Made(p)) => transform(app, &p).ok(), + _ => None, + } +} + +/// Where a point a pick keeps on moved body `body` (see [`from_shown`]) shows: moved on by the +/// current type's own move. +pub(crate) fn shown_point(app: &SolveApp, body: &str, p: Vec3) -> Vec3 { + let Some(d) = app.dialog.as_ref().filter(|d| matches!(d.kind, Kind::Move { .. }) && items(d, 0).body_names().iter().any(|n| n == body)) else { + return p; + }; + made(app, d).map_or(p, |m| apply_point(&m, p)) +} + +/// A pick on a moved body is made where the move so far shows it; the current type measures +/// from where the earlier types leave the body, so the pick is taken back by the current type's +/// own move. Kept there, a pivot or From point picked mid-move doesn't move with the move it +/// sets. +pub(crate) fn from_shown(app: &SolveApp, sel: Sel) -> Sel { + let Some(d) = app.dialog.as_ref().filter(|d| matches!(d.kind, Kind::Move { .. }) && on_moved(d, &sel)) else { return sel }; + let Some(back) = made(app, d).and_then(|m| mat_inverse(&m)) else { return sel }; + match sel { + Sel::Edge { body, index, point } => Sel::Edge { body, index, point: apply_point(&back, point) }, + Sel::Face { body, index, point } => Sel::Face { body, index, point: apply_point(&back, point) }, + Sel::Vertex { body, point } => Sel::Vertex { body, point: apply_point(&back, point) }, + other => other, + } +} + +/// Whether a pick is on one of the bodies being moved. +fn on_moved(d: &Dialog, s: &Sel) -> bool { + match s { + Sel::Edge { body, .. } | Sel::Face { body, .. } | Sel::Vertex { body, .. } => items(d, 0).body_names().contains(body), + _ => false, + } +} + +/// A point of the model before this move where the earlier types' move puts it: on a moved body +/// (`moved`) or, for the bodies' centre, always. +fn carried(d: &Dialog, moved: bool, p: Vec3) -> Vec3 { + match chain(d) { + Some(c) if moved => apply_point(&c, p), + _ => p, + } +} + /// The value rows after the inputs; true when Enter was pressed in one. pub fn rows(ui: &mut egui::Ui, k: &mut Kind) -> bool { let Kind::Move { mode, x, y, z, rx, ry, rz, angle } = k else { return false }; @@ -96,13 +185,15 @@ pub fn rows(ui: &mut egui::Ui, k: &mut Kind) -> bool { /// move, in the world (a body of a placed component where its occurrence puts it, as it was /// picked); any other pick is where it was picked. fn sel_point(app: &SolveApp, d: &Dialog, s: Option<&Sel>) -> Option { - match s? { + let s = s?; + match s { Sel::Edge { body, index, point } => { let st = match d.editing { Some((id, _)) => std::sync::Arc::new(solidcraft_engine::doc::world_state(&app.session.doc, &app.session.model.state_before(id))), None => app.session.world_state(), }; - Some(crate::dialogs::edge_circle_in(&st, body, *index).map_or(*point, |(c, ..)| c)) + // The centre is found where the body was modelled; the picked point is where it stands. + Some(crate::dialogs::edge_circle_in(&st, body, *index).map_or(*point, |(c, ..)| carried(d, on_moved(d, s), c))) } Sel::Vertex { point, .. } | Sel::Face { point, .. } => Some(*point), _ => None, @@ -113,7 +204,7 @@ fn items(d: &Dialog, i: usize) -> &[Sel] { crate::selection::items(&d.inputs, i) } -/// The centre of the picked bodies where they are before this move. +/// The centre of the picked bodies where they are before this move (after the earlier types'). fn bodies_center(app: &SolveApp, d: &Dialog) -> Option { let st = match d.editing { Some((id, _)) => app.session.model.state_before(id), @@ -131,7 +222,7 @@ fn bodies_center(app: &SolveApp, d: &Dialog) -> Option { ), }); } - bb.map(|(lo, hi)| (lo + hi) * 0.5) + bb.map(|(lo, hi)| carried(d, true, (lo + hi) * 0.5)) } /// What a Free Move turns about: the picked pivot, else the kept one (editing), else the @@ -170,8 +261,67 @@ fn deg(v: f64) -> String { format!("{} deg", if s == "-0" || s.is_empty() { "0" } else { s }) } -/// The solid.move parameters (bodies, translate, axis, angle). +/// The solid.move parameters (bodies, translate, axis, angle): the current type's move after +/// the earlier types' (`chain`), which alone is made while the current type's picks are missing. pub fn params(app: &SolveApp, d: &Dialog) -> Result { + let mut p = match (step(app, d)?, chain(d)) { + (Step::Made(p), None) => p, + (Step::Needs(e), None) => return Err(e), + (Step::Made(p), Some(c)) => { + let made = transform(app, &p)?; + with_transform(p, &mat_mul(&made, &c)) + } + (Step::Needs(_), Some(c)) => with_transform(json!({ "bodies": items(d, 0).body_names() }), &c), + }; + if d.extra.get("copy").and_then(Value::as_bool).unwrap_or(false) { + p["copy"] = json!(true); + } + Ok(p) +} + +/// The current type's move, or what it still needs picked. +enum Step { + Made(Value), + Needs(String), +} + +/// The rigid transform of solid.move parameters: the turn about the origin, then the translation. +fn transform(app: &SolveApp, p: &Value) -> Result { + let value = |v: &Value, f: fn(&SolveApp, &str) -> Result| match v { + Value::String(e) => f(app, e), + Value::Number(n) => n.as_f64().ok_or_else(|| "not a number".to_string()), + _ => Err("not a number".into()), + }; + let t = match p.get("translate").and_then(Value::as_array) { + Some(a) if a.len() == 3 => Vec3::new(value(&a[0], len)?, value(&a[1], len)?, value(&a[2], len)?), + _ => Vec3::ZERO, + }; + let Some(angle) = p.get("angle") else { return Ok(rigid(t, Vec3::ZERO, Vec3::Z, 0.0)) }; + let axis = match p.get("axis").and_then(Value::as_array) { + Some(a) if a.len() == 3 => Vec3::new(value(&a[0], len)?, value(&a[1], len)?, value(&a[2], len)?), + _ => Vec3::Z, + }; + Ok(rigid(t, Vec3::ZERO, axis, value(angle, ang)?)) +} + +/// `p` with its translation and turn replaced by `m`'s. +fn with_transform(mut p: Value, m: &Mat) -> Value { + let rows = [0, 1, 2].map(|r| [m[0][r], m[1][r], m[2][r]]); + let (axis, th) = gizmo::axis_angle(&rows); + p["translate"] = json!([mm(m[3][0]), mm(m[3][1]), mm(m[3][2])]); + if let Some(o) = p.as_object_mut() { + o.remove("axis"); + o.remove("angle"); + } + if th.abs() > 1e-12 { + p["axis"] = json!([axis.x, axis.y, axis.z]); + p["angle"] = json!(deg(th)); + } + p +} + +/// The current type's own move, from where the earlier types leave the bodies. +fn step(app: &SolveApp, d: &Dialog) -> Result { let Kind::Move { mode, x, y, z, rx, ry, rz, angle } = &d.kind else { return Err("not a move".into()) }; let bodies = items(d, 0).body_names(); if bodies.is_empty() { @@ -214,10 +364,9 @@ pub fn params(app: &SolveApp, d: &Dialog) -> Result { } } ROTATE => { - let (o, a) = items(d, 1) - .first() - .and_then(|s| axis_line(app, s)) - .ok_or("select an axis, a straight or circular edge, or a cylinder, cone or torus face first")?; + let Some((o, a)) = items(d, 1).first().and_then(|s| axis_line(app, d, s)) else { + return Ok(Step::Needs("select an axis, a straight or circular edge, or a cylinder, cone or torus face first".into())); + }; let th = ang(app, angle)?; let r = gizmo::rotation(a, th); p["translate"] = num(o - gizmo::apply(&r, o)); @@ -225,24 +374,36 @@ pub fn params(app: &SolveApp, d: &Dialog) -> Result { p["angle"] = json!(angle); } POINT_TO_POINT => { - let (from, to) = (need_point(1, "the point to move from")?, need_point(2, "the point to move to")?); + let (from, to) = match (need_point(1, "the point to move from"), need_point(2, "the point to move to")) { + (Ok(from), Ok(to)) => (from, to), + (Err(e), _) | (_, Err(e)) => return Ok(Step::Needs(e)), + }; p["translate"] = num(to - from); } _ => { - let from = need_point(1, "the point to move")?; + let from = match need_point(1, "the point to move") { + Ok(from) => from, + Err(e) => return Ok(Step::Needs(e)), + }; let at = Vec3::new(len(app, x)?, len(app, y)?, len(app, z)?); p["translate"] = num(at - from); } } - if d.extra.get("copy").and_then(Value::as_bool).unwrap_or(false) { - p["copy"] = json!(true); - } - Ok(p) + Ok(Step::Made(p)) } /// An axis line: origin axes and sketch lines, a straight or circular body edge, or a cylinder, -/// cone or torus face (`dialogs::axis_of`), or a straight edge of a body where it was modelled. -fn axis_line(app: &SolveApp, s: &Sel) -> Option<(Vec3, Vec3)> { +/// cone or torus face (`dialogs::axis_of`), or a straight edge of a body where it was modelled; +/// on a moved body, where the earlier types' move puts it. +fn axis_line(app: &SolveApp, d: &Dialog, s: &Sel) -> Option<(Vec3, Vec3)> { + let (o, a) = modelled_axis(app, s)?; + match chain(d) { + Some(c) if on_moved(d, s) => Some((apply_point(&c, o), apply_vector(&c, a))), + _ => Some((o, a)), + } +} + +fn modelled_axis(app: &SolveApp, s: &Sel) -> Option<(Vec3, Vec3)> { if let Some(a) = crate::dialogs::axis_of(app, s) { return Some(a); } @@ -272,7 +433,7 @@ pub(crate) fn rotation_axis(app: &SolveApp, d: &Dialog) -> Option<(Vec3, Vec3)> return None; } let centre = bodies_center(app, d)?; - let (origin, axis) = axis_line(app, items(d, 1).first()?)?; + let (origin, axis) = axis_line(app, d, items(d, 1).first()?)?; let axis = axis.normalized()?; Some((origin + axis * (centre - origin).dot(axis), axis)) } diff --git a/crates/ui-egui/src/dialogs_move_tests.rs b/crates/ui-egui/src/dialogs_move_tests.rs index 7aa2d1431..e2e0119fb 100644 --- a/crates/ui-egui/src/dialogs_move_tests.rs +++ b/crates/ui-egui/src/dialogs_move_tests.rs @@ -482,3 +482,61 @@ fn triad_drag_ends_where_the_button_was_released() { h.frame_with(vec![button(released, false), egui::Event::PointerMoved(pos(later))]); assert_eq!(value(&h), "20 mm", "the drag ends where the button was released"); } + +/// A Move dialog on the 20 × 30 × 10 box, translated 10 mm along X. +fn translated_box() -> crate::scenario::Harness { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 20, "width": 30, "height": 10})).unwrap(); + h.app.start("solid.move"); + let d = h.app.dialog.as_mut().unwrap(); + d.kind = kind(TRANSLATE, &h.app.session.doc); + d.inputs = inputs(TRANSLATE); + d.inputs[0].items = vec![Sel::Body { name: "Body1".into() }]; + if let Kind::Move { x, .. } = &mut d.kind { + *x = "10 mm".into(); + } + h +} + +/// #8746: changing the Move Type keeps the move made so far, and the new type moves the body +/// on from there; one solid.move holds the chain. +#[test] +fn changing_the_move_type_keeps_the_move_made_so_far() { + let mut h = translated_box(); + let corners = |b: solidcraft_engine::geom::Aabb3| [b.min, b.max]; + let before = corners(h.app.session.world_state().body("Body1").unwrap().mesh().bounds()); + let mut d = h.app.dialog.take().unwrap(); + switch_type(&h.app, &mut d, ROTATE); + // No axis yet: the translation alone is made. + let p = params(&h.app, &d).unwrap(); + assert_eq!(p["translate"], json!(["10 mm", "0 mm", "0 mm"]), "{p}"); + assert!(p.get("angle").is_none(), "{p}"); + // A quarter turn about Z, after the translation. + d.inputs[1].items = vec![Sel::Axis { name: "Z".into() }]; + if let Kind::Move { angle, .. } = &mut d.kind { + *angle = "90 deg".into(); + } + for (command, params) in crate::dialogs::apply_commands(&h.app, &d).unwrap() { + h.app.run(&command, params).unwrap(); + } + let after = h.app.session.world_state().body("Body1").unwrap().mesh().bounds(); + let turn = |p: Vec3| Vec3::new(-p.y, p.x + 10.0, p.z); + let mut want = solidcraft_engine::geom::Aabb3::EMPTY; + for c in before { + want.add(turn(c)); + } + assert!((after.min - want.min).len() < 1e-6 && (after.max - want.max).len() < 1e-6, "{after:?} != {want:?}"); +} + +/// #8746: a pick on the moving body is made where the preview draws it, and is kept where the +/// current type's move starts from. +#[test] +fn a_pick_on_the_moved_body_is_taken_back_by_the_current_move() { + let h = translated_box(); + let shown = Sel::Vertex { body: "Body1".into(), point: Vec3::new(30.0, 30.0, 10.0) }; + let kept = from_shown(&h.app, shown); + assert_eq!(kept, Sel::Vertex { body: "Body1".into(), point: Vec3::new(20.0, 30.0, 10.0) }); + assert_eq!(shown_point(&h.app, "Body1", Vec3::new(20.0, 30.0, 10.0)), Vec3::new(30.0, 30.0, 10.0)); + let elsewhere = Sel::Vertex { body: "Other".into(), point: Vec3::new(30.0, 30.0, 10.0) }; + assert_eq!(from_shown(&h.app, elsewhere.clone()), elsewhere, "a pick on another body stays where it was made"); +} diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index c9f79d2df..d48fc523d 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -767,6 +767,25 @@ fn drawn_mesh(app: &SolveApp, b: &solidcraft_engine::doc::ModelBody) -> std::syn if current() == DisplayQuality::Normal { b.mesh() } else { b.plan_mesh().unwrap_or_else(|| b.mesh()) } } +/// The move a Move dialog's earlier types made to body `name`, if it is one they moved +/// (`dialogs_move::chained`): its edges, faces and centres are shown where that move puts them. +fn chain_of(chain: Option<&(Vec, solidcraft_engine::doc::Mat)>, name: &str) -> Option { + chain.filter(|(names, _)| names.iter().any(|n| n == name)).map(|(_, c)| *c) +} + +/// `mesh` moved by `chain`, or as it is without one. +fn carried_mesh( + chain: Option, + mesh: std::sync::Arc, +) -> std::sync::Arc { + let Some(c) = chain else { return mesh }; + let mut m = (*mesh).clone(); + m.positions.iter_mut().for_each(|p| *p = solidcraft_engine::doc::apply_point(&c, *p)); + m.normals.iter_mut().for_each(|n| *n = solidcraft_engine::doc::apply_vector(&c, *n)); + m.edges.iter_mut().flatten().for_each(|p| *p = solidcraft_engine::doc::apply_point(&c, *p)); + std::sync::Arc::new(m) +} + /// How long (ms) the camera must stand still before display refinements are chosen and swapped in. const REFINE_STILL_MS: f64 = 200.0; @@ -1981,10 +2000,19 @@ pub(crate) fn round_pick_feedback(app: &SolveApp) -> (Vec<(Vec3, Vec3)>, Vec (solidcraft_engine::doc::apply_point(&c, p), solidcraft_engine::doc::apply_vector(&c, dir)), + None => (p, dir), + }; if inp.accept == crate::selection::AXIS_PICKS { let bb = view_bounds(app); for sel in hovered.iter().chain(inp.items.iter()) { - if let Some((o, dir)) = crate::dialogs::round_axis(s, sel) + let body = match sel { + Sel::Edge { body, .. } | Sel::Face { body, .. } => body.as_str(), + _ => "", + }; + if let Some((o, dir)) = crate::dialogs::round_axis(s, sel).map(|(o, dir)| carry(body, o, dir)) && !lines.iter().any(|(_, _, q, e)| q.dist(o) < 1e-9 && e.cross(dir).len() < 1e-9) { let (a, b) = axis_span(app, &bb, o, dir); @@ -1996,7 +2024,7 @@ pub(crate) fn round_pick_feedback(app: &SolveApp) -> (Vec<(Vec3, Vec3)>, Vec continue, Some(t0) if !all && bestf.as_ref().is_some_and(|(bt, _)| t0 > *bt) => continue, _ => {} @@ -2450,7 +2500,7 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool, } // A placed part is picked in its own frame, from its shared mesh and index: the ray is // moved there (a rigid move keeps distances along it), so no moved copy is made. - let (m, place) = b.mesh_in_place(); + let (m, place) = placed(b); let index = app.viewport.pick_index.of(&m); // The nearest kept face: past any the section removes (a bounded walk along the ray). let mut nearest = None; @@ -2508,15 +2558,15 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool, continue; } let mut body_slack = slack; - if let Some((_, bb)) = bounds.get(i) { + if let Some(bb) = body_box(i, b) { // Only bodies whose outline on screen is near the cursor can have an edge under it. - if screen_box(proj, bb, 8.0).is_some_and(|r| !r.contains(pos)) { + if screen_box(proj, &bb, 8.0).is_some_and(|r| !r.contains(pos)) { continue; } body_slack = pick_slack(bb.diagonal()); } // In the part's own frame, as for faces; its points are moved back to where it stands. - let (m, place) = b.mesh_in_place(); + let (m, place) = placed(b); let Some((lo, ld)) = local_ray(&place, o, d) else { continue }; let moved = !solidcraft_engine::doc::is_identity(&place); let at = |p: Vec3| if moved { solidcraft_engine::doc::apply_point(&place, p) } else { p }; @@ -3049,6 +3099,7 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) { app.start("solid.press_pull"); return; } + let sel = crate::dialogs_move::from_shown(app, sel); let Some(mut d) = app.dialog.take() else { return }; // With holes moving by clicking (Preferences), a Single hole picked again on its face moves there. if app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel) { @@ -3295,6 +3346,12 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 { crate::theme_files::color_key(&Tokens::get()).hash(&mut h); app.preview.effective_replaced().hash(&mut h); app.preview.rolled_back.hash(&mut h); + // Where a Move dialog has moved its bodies; while its triad is dragged, only that it is. + if crate::dialogs_move::dragging(app) { + "dragging".hash(&mut h); + } else { + crate::dialogs_move::chained(app).map(|(_, c)| c.iter().flatten().map(|v| v.to_bits()).collect::>()).hash(&mut h); + } app.origin_visible().hash(&mut h); app.picking_plane().hash(&mut h); app.preferences.reference_geometry_through_bodies.hash(&mut h); @@ -3516,7 +3573,17 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { let active_bodies = s.active_occurrence_path.as_ref().and_then(|p| s.occurrence_bodies(p, true).ok()); // Faces lit over the model use the triangles the model shows them with. let product = crate::render_workspace::active(app); - let shown = |b: &solidcraft_engine::doc::ModelBody| if product { b.mesh() } else { shown_mesh(app, b, &active_bodies) }; + // Bodies a Move dialog moves are lit where they stand (as they are picked). While its triad + // is dragged they aren't lit at all, so the highlight is built again once, when it lets go, + // rather than every frame. + let live = crate::dialogs_move::chained(app); + let dragging = crate::dialogs_move::dragging(app); + let moving = |name: &str| dragging && chain_of(live.as_ref(), name).is_some(); + let chained = live.as_ref().filter(|_| !dragging); + let carry = |b: &solidcraft_engine::doc::ModelBody| chain_of(chained, &b.name); + let replaced = |name: &str| moving(name) || (app.preview.effective_replaced().iter().any(|n| n == name) && chain_of(chained, name).is_none()); + let shown = |b: &solidcraft_engine::doc::ModelBody| carried_mesh(carry(b), if product { b.mesh() } else { shown_mesh(app, b, &active_bodies) }); + let drawn = |b: &solidcraft_engine::doc::ModelBody| carried_mesh(carry(b), drawn_mesh(app, b)); let items = app.highlighted(); let sketches = selected_sketches(app, &items); let mut sel = Vec::new(); @@ -3654,9 +3721,9 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { match x { Sel::Face { body, index, .. } => { // A live preview stands in for the body: its old faces would fight with it. - if let Some(b) = st.body(body).filter(|_| app.session.body_visible(body) && !app.preview.effective_replaced().contains(body)) { + if let Some(b) = st.body(body).filter(|_| app.session.body_visible(body) && !replaced(body)) { face_tris(&mut feedback, &shown(b), *index, c4(t.sel_face), false); - hidden_face_outline(&mut feedback, &drawn_mesh(app, b), *index, t.sel_edge); + hidden_face_outline(&mut feedback, &drawn(b), *index, t.sel_edge); } } Sel::Body { name } => { @@ -3674,9 +3741,11 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { Sel::Edge { body, index, point } => { if let Some(b) = st.body(body) && app.session.body_visible(body) + && !moving(body) { - let m = drawn_mesh(app, b); - if let Some(e) = edge_of(&m, *index, *point) { + let m = drawn(b); + let point = if carry(b).is_some() { crate::dialogs_move::shown_point(app, body, *point) } else { *point }; + if let Some(e) = edge_of(&m, *index, point) { edge_lines(&mut feedback, e, selected_edge, 3.0, &edge_normals(&m, e)); } } @@ -3815,13 +3884,12 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { } } Some(Hit::Face { body, index, .. }) - if !app.preview.effective_replaced().contains(body) - && !sel.iter().any(|x| matches!(x, Sel::Face { body: b, index: i, .. } if b == body && i == index)) => + if !replaced(body) && !sel.iter().any(|x| matches!(x, Sel::Face { body: b, index: i, .. } if b == body && i == index)) => { if let Some(b) = st.body(body) { let k = t.hover_face_lift; let c = body_rgb(app, body); - let m = drawn_mesh(app, b); + let m = drawn(b); let patch = m.surface_patch(*index); let lit = shown(b); for &f in &patch { @@ -3836,10 +3904,10 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene { } } } - Some(Hit::Edge { body, index, mid, .. }) => { + Some(Hit::Edge { body, index, mid, .. }) if !moving(body) => { if let Some(b) = st.body(body) { // Lit over the drawn edges (finer away from Normal display quality). - let m = drawn_mesh(app, b); + let m = drawn(b); for i in m.circular_rim(*index) { let selected = sel.iter().any(|x| matches!(x, Sel::Edge { body: b, index: j, .. } if b == body && *j == i)); if !selected && let Some(e) = if i == *index { edge_of(&m, i, *mid) } else { m.edges.get(i) } {