Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions crates/ui-egui/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,6 @@ fn occurrence_panel(app: &mut SolveApp, ui: &mut egui::Ui) {
}
});
});
triad(app, ui, &mut m);
if (m.translate, m.angles) != before {
apply_occurrence_move(app, &m);
}
Expand Down Expand Up @@ -1977,18 +1976,22 @@ pub fn apply_occurrence_move(app: &mut SolveApp, m: &OccMove) {
);
}

/// The move triad of an occurrence being moved, at its origin carried by the move so far.
pub(crate) fn occurrence_triad(m: &OccMove) -> Option<crate::gizmo::Triad> {
let center = m.pivot? + solidcraft_engine::geom::Vec3::new(m.translate[0], m.translate[1], m.translate[2]);
Some(crate::gizmo::Triad { center, translate: true, rotate: true })
}

/// The shared move triad at the occurrence's origin: arrows and squares move it, rings turn it.
fn triad(app: &mut SolveApp, ui: &mut egui::Ui, m: &mut OccMove) {
/// Drawn by the viewport with the Move window's triad (`canvas::show`): on a painter layer of
/// its own no pointer was ever over it, so it never lit up or dragged (#3203).
pub(crate) fn occurrence_move_triad(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &crate::viewport::Proj) {
use crate::gizmo::{self, Change};
let (Some(rect), Some(pivot)) = (app.viewport.rect, m.pivot) else { return };
let proj = crate::viewport::projection(app, rect);
let center = pivot + solidcraft_engine::geom::Vec3::new(m.translate[0], m.translate[1], m.translate[2]);
let layer = egui::LayerId::new(egui::Order::Middle, egui::Id::new("sc_occ_triad_layer"));
let mut gui = ui.new_child(egui::UiBuilder::new().layer_id(layer).max_rect(rect));
let painter = gui.painter().with_clip_rect(rect);
let t = gizmo::Triad { center, translate: true, rotate: true };
let Some(mut m) = app.tree.occurrence_move.clone() else { return };
let Some(t) = occurrence_triad(&m) else { return };
let step = crate::canvas::snap_step(app.cam.half_height());
let Some(g) = gizmo::show(&mut gui, &painter, &proj, egui::Id::new("sc_occ_triad"), &t, step) else { return };
let Some(g) = gizmo::show(ui, painter, proj, egui::Id::new("sc_occ_triad"), &t, step) else { return };
let before = (m.translate, m.angles);
if g.started || m.drag0.is_none() {
m.drag0 = Some((m.translate, m.angles));
}
Expand All @@ -2004,6 +2007,10 @@ fn triad(app: &mut SolveApp, ui: &mut egui::Ui, m: &mut OccMove) {
if g.done {
m.drag0 = None;
}
if (m.translate, m.angles) != before {
apply_occurrence_move(app, &m);
}
app.tree.occurrence_move = Some(m);
}

/// Dimensions of finished sketches whose dimensions are shown (Show Dimensions), drawn over the
Expand Down
8 changes: 7 additions & 1 deletion crates/ui-egui/src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,17 @@ pub(crate) fn blend_grow_dir(m: &Mesh, index: usize, p: Vec3) -> Option<Vec3> {
pub(crate) fn owns_pointer(app: &SolveApp, proj: &Proj, p: Pos2) -> bool {
// The triad only registers an egui hit widget after a handle is under the pointer.
// Test its geometry before navigation, including the first frame entering a handle.
app.dialog.as_ref().and_then(|d| crate::dialogs_move::triad(app, d)).is_some_and(|t| crate::gizmo::contains_pointer(proj, &t, p))
app.dialog
.as_ref()
.and_then(|d| crate::dialogs_move::triad(app, d))
.into_iter()
.chain(app.tree.occurrence_move.as_ref().and_then(crate::browser::occurrence_triad))
.any(|t| crate::gizmo::contains_pointer(proj, &t, p))
}

/// Draw the manipulator and the value box (called by the viewport after the model is drawn).
pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) {
crate::browser::occurrence_move_triad(app, ui, painter, proj);
// While OK computes, the inputs hold what it computes: no arrow to drag, no box to type in.
if app.applying.is_some() {
return;
Expand Down
26 changes: 26 additions & 0 deletions crates/ui-egui/src/occurrence_ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,29 @@ fn occurrence_distance_editor_reads_inches_and_keeps_four_digits_in_model_space(
crate::browser::revert_occurrence_dialog(&mut h.app, &movement);
assert!(h.app.session.pending_moves.is_empty());
}

/// #3203: the triad of Move on an occurrence (an inserted STEP file is one) is under the
/// pointer like the Move window's: dragging its X arrow moves the occurrence, not the camera.
#[test]
fn dragging_the_occurrence_triad_moves_the_occurrence() {
let (mut h, _component, first, _second) = fixture();
h.app.home.open = false;
h.step(&json!({"call":"ui.view","params":{"view":"fit"}})).unwrap();
h.settle();
let target = Target::Occurrence { path: vec![first] };
let movement = context_menu::items(&h.app, &target).into_iter().find(|i| i.id == "ui.moveOccurrence").unwrap();
context_menu::run_item(&mut h.app, &movement, egui::Pos2::ZERO);
h.frames(4);
let min_x = |h: &Harness| {
let state = h.app.session.world_state();
state.bodies.iter().map(|b| b.mesh().bounds().min.x).fold(f64::INFINITY, f64::min)
};
let (x0, camera) = (min_x(&h), h.app.cam);
let [x, y] = h.at(&json!({"handle": "move_x"})).unwrap();
h.step(&json!({"drag": [[x, y], [x + 80.0, y]]})).unwrap();
h.frames(3);
let moved = h.app.tree.occurrence_move.as_ref().unwrap().translate;
assert!(moved[0] > 1.0 && moved[1] == 0.0 && moved[2] == 0.0, "the X arrow moved it along X: {moved:?}");
assert!((min_x(&h) - x0 - moved[0]).abs() < 1e-6, "the occurrence followed: {} -> {}", x0, min_x(&h));
assert_eq!(format!("{:?}", h.app.cam), format!("{camera:?}"), "the camera stayed put");
}