SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
History: a face picked in the view lights the feature that made it (#6910)
tr1pp4d0c594d311cb
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rsindex b5f2bdab84..a68aad20f9 100644--- a/crates/ui-egui/src/browser.rs+++ b/crates/ui-egui/src/browser.rs@@ -128,6 +128,9 @@ pub struct TreeState {/// Find in Timeline: the feature the history scrolls to the next time it draws its items, in/// the bottom strip or in the history on the left (#5850).pub timeline_reveal: Option<u64>,+ /// The feature of the face or edge last picked in the view, so a new pick scrolls the+ /// history to it once.+ pub view_pick: Option<u64>,/// The Edit Canvas / Calibrate panel.pub canvas_panel: Option<CanvasPanel>,/// The bodies a row at the top of the history lights this frame (`history_rows`), for thediff --git a/crates/ui-egui/src/browser/features.rs b/crates/ui-egui/src/browser/features.rsindex 5ebae12a0a..2d6728c98e 100644--- a/crates/ui-egui/src/browser/features.rs+++ b/crates/ui-egui/src/browser/features.rs@@ -71,6 +71,9 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path:.filter_map(|(i, f)| (f.component == component && !matches!(f.kind, FeatureKind::Sketch { .. })).then_some(i)).collect(),};+ // The feature that made what is under the cursor or picked in the viewport, as the history+ // lights it.+ let from_view = [crate::timeline::hovered_feature(app), crate::timeline::picked_feature(app)];for index in indices {let Some(feature) = app.session.doc.features.get(index) else { continue };let (id, label, icon) = (feature.id, feature.name.clone(), crate::timeline::icon_of(&feature.kind));@@ -78,6 +81,7 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path:// Behind the history marker or suppressed: not built, drawn faint as in the timeline.let dim = feature.suppressed || app.session.doc.marker.is_some_and(|marker| index >= marker);let selected = app.session.selection.contains(&Sel::Feature { id });+ let mark = if from_view.contains(&Some(id)) { Mark::Here } else { Mark::None };app.tree.remember(&format!("f:{id}"));let action = sketch.map(|_| ("sketch", "Edit Profile Sketch"));// The bodies it made show and hide with its eye (#5099); a component listed on its own@@ -89,7 +93,7 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path:let r = draw_row(ui,ui.id().with(("browser_feature", id)),- &Row { depth: depth + 1, eye, icon, label: &label, selected, dim: dim || eye == Some(false), action, ..Default::default() },+ &Row { depth: depth + 1, eye, icon, label: &label, selected, dim: dim || eye == Some(false), mark, action, ..Default::default() },);if r.eye {let mut p = json!({"visible": !visible, "features": [id]});diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rsindex 74a84cb615..e82635d7db 100644--- a/crates/ui-egui/src/context_menu.rs+++ b/crates/ui-egui/src/context_menu.rs@@ -450,6 +450,11 @@ fn picked_face_feature(app: &SolveApp) -> Option<u64> {Sel::Face { body, index, .. } => Some((body, *index)),_ => None,})?;+ face_feature(app, body, index)+}++/// The feature that made face `index` of `body` (by its world name).+pub(crate) fn face_feature(app: &SolveApp, body: &str, index: usize) -> Option<u64> {let state = app.session.world_state();let body = state.body(body)?;let names = solidcraft_engine::doc::naming::face_names(body);diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 6132443d3d..85625449cf 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -2180,6 +2180,7 @@ impl SolveApp {}}let floating = ui_kit::Container::new(ui.ctx(), ui_kit::Surface::Panel).floating();+ timeline::follow_view_pick(self);let show_timeline = self.ui.show_timeline && !render_workspace::active(self);let left_timeline = show_timeline && self.preferences.timeline_left;timeline_left::animate_folds(self, ui.ctx());diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rsindex 909be62e1e..e263a7974e 100644--- a/crates/ui-egui/src/timeline.rs+++ b/crates/ui-egui/src/timeline.rs@@ -26,6 +26,46 @@ pub(crate) fn run_transport(app: &mut SolveApp, control: crate::ui_kit::HistoryTlet _ = app.run_heavy("timeline.roll_to", params);}+/// The feature that made a face, edge or vertex of `body` (its world name): a face's own creator,+/// as Edit Feature on a face finds it (the hole, not the plate it was cut into), else the feature+/// that made the body.+fn geometry_feature(app: &SolveApp, body: &str, face: Option<usize>) -> Option<u64> {+ face.and_then(|index| crate::context_menu::face_feature(app, body, index))+ .or_else(|| app.session.world_state().body(body).map(|b| b.feature))+ .filter(|id| app.session.doc.feature(*id).is_some())+}++/// The feature of the face, edge or vertex under the pointer in the view.+pub(crate) fn hovered_feature(app: &SolveApp) -> Option<u64> {+ match &app.viewport.hover {+ Some(crate::viewport::Hit::Face { body, index, .. }) => geometry_feature(app, body, Some(*index)),+ Some(crate::viewport::Hit::Edge { body, .. } | crate::viewport::Hit::Vertex { body, .. }) => geometry_feature(app, body, None),+ _ => None,+ }+}++/// The feature of the first face or edge picked in the view.+pub(crate) fn picked_feature(app: &SolveApp) -> Option<u64> {+ app.session.selection.iter().find_map(|selection| match selection {+ solidcraft_engine::Sel::Face { body, index, .. } => geometry_feature(app, body, Some(*index)),+ solidcraft_engine::Sel::Edge { body, .. } => geometry_feature(app, body, None),+ _ => None,+ })+}++/// A new face or edge picked in the view scrolls the history shown to the feature that made it,+/// once per pick; the history stays where it is while the pick does not change.+pub(crate) fn follow_view_pick(app: &mut SolveApp) {+ let picked = picked_feature(app);+ if picked == app.tree.view_pick {+ return;+ }+ app.tree.view_pick = picked;+ if picked.is_some() && app.ui.show_timeline {+ app.tree.timeline_reveal = picked;+ }+}+// Snapshot only the data used by timeline interactions. Cloning FeatureKind here would// also copy imported mesh vertices and triangles on every frame.#[derive(Clone, Copy)]@@ -510,14 +550,8 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {let order: Vec<u64> = feats.iter().map(|f| f.0).collect();// Find in Timeline: scroll the found feature into the strip on this frame (#5850).let reveal = app.tree.timeline_reveal.take();- // The feature whose body is under the cursor in the viewport.- let st = app.session.world_state();- let from_view = match &app.viewport.hover {- Some(- crate::viewport::Hit::Face { body, .. } | crate::viewport::Hit::Edge { body, .. } | crate::viewport::Hit::Vertex { body, .. },- ) => st.body(body).map(|b| b.feature),- _ => None,- };+ // The feature that made what is under the cursor or picked in the viewport.+ let from_view = [hovered_feature(app), picked_feature(app)];let drag_id = ui.id().with("tl_drag");let mut drag: Option<Drag> = ui.data(|d| d.get_temp(drag_id));let pointer = ui.input(|i| i.pointer.hover_pos());@@ -551,7 +585,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {name,kind: ty,selected: sel,- hovered: resp.hovered() || from_view == Some(*id),+ hovered: resp.hovered() || from_view.contains(&Some(*id)),dim: rolled,suppressed: *suppressed,error: err.is_some(),@@ -929,6 +963,52 @@ mod tests {}}+ /// A face picked in the view lights the feature that made it, the hole rather than the block+ /// it was cut into, and scrolls both timelines to it once; hovering finds the same feature.+ #[test]+ fn a_face_picked_in_the_view_scrolls_both_timelines_to_the_feature_that_made_it() {+ for left in [false, true] {+ let mut h = Harness::new();+ h.app.preferences.timeline_left = left;+ let block =+ h.app.run("solid.box", json!({"length": 20, "width": 20, "height": 10, "name": "Block", "body_name": "Plate"})).unwrap()["feature"]+ .as_u64()+ .unwrap();+ for i in 0..80 {+ h.app.run("sketch.create", json!({"plane": "XY", "name": format!("S{i}")})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ }+ let hole = h+ .app+ .run("solid.cylinder", json!({"base": [10, 10, -1], "radius": 3, "height": 12, "operation": "cut", "name": "Hole"}))+ .unwrap()["feature"]+ .as_u64()+ .unwrap();+ h.app.run("select.clear", json!({})).unwrap();+ h.frames(4);+ let shown = |h: &Harness| h.app.shell.history.unwrap().contains(crate::scenario::handle_at("timeline:Hole").unwrap());+ assert!(!shown(&h), "left={left}: the hole starts outside the timeline");++ let state = h.app.session.world_state();+ let body = state.bodies.first().unwrap();+ let names = solidcraft_engine::doc::naming::face_names(body);+ let index = names.iter().position(|name| solidcraft_engine::doc::persistent_name::made_by(name) == Some(hole)).unwrap();+ let plate = body.name.clone();+ h.app.viewport.hover = Some(crate::viewport::Hit::Face { body: plate.clone(), index, point: solidcraft_engine::geom::Vec3::ZERO });+ assert_eq!(crate::timeline::hovered_feature(&h.app), Some(hole), "left={left}: hovering the hole's face finds the hole");+ h.app.viewport.hover = Some(crate::viewport::Hit::Vertex { body: plate.clone(), point: solidcraft_engine::geom::Vec3::ZERO });+ assert_eq!(crate::timeline::hovered_feature(&h.app), Some(block), "left={left}: a vertex finds the feature that made its body");+ h.app.viewport.hover = None;++ h.app.run("select.set", json!({"items": [{"type": "face", "body": plate, "index": index, "point": [0, 0, 0]}]})).unwrap();+ h.frames(30);+ assert_eq!(crate::timeline::picked_feature(&h.app), Some(hole), "left={left}");+ assert_eq!(h.app.tree.view_pick, Some(hole), "left={left}");+ assert!(shown(&h), "left={left}: the pick scrolled the hole into the timeline");+ assert!(h.app.tree.timeline_reveal.is_none(), "left={left}: once, not on every frame");+ }+ }+#[test]fn the_feature_menu_edits_its_profile_sketch_in_both_timelines() {for left in [false, true] {diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex e07a3e6e32..bc9ca93a3b 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -1036,7 +1036,7 @@ struct Rows<'a> {/// Find in Timeline: the feature to scroll into view this frame (#5850).reveal: Option<u64>,/// The feature whose body is under the pointer in the 3D view.- from_view: Option<u64>,+ from_view: [Option<u64>; 2],/// A sketch that has a reference row and one of whose rows was hovered last frame: all its/// rows light up.linked_hover: Option<u64>,@@ -1081,12 +1081,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) {.iter().map(|group| (group.id, group_last_feature(&groups, &features, group.id).map_or(features.len(), |index| index.saturating_add(1)))).collect();- let from_view = match &app.viewport.hover {- Some(crate::viewport::Hit::Face { body, .. } | crate::viewport::Hit::Edge { body, .. } | crate::viewport::Hit::Vertex { body, .. }) => {- app.session.world_state().body(body).map(|body| body.feature)- }- _ => None,- };+ let from_view = [crate::timeline::hovered_feature(app), crate::timeline::picked_feature(app)];let drag_id = ui.id().with("tl_vertical_drag");let mut rows = Rows {names,@@ -1329,7 +1324,7 @@ fn feature_row(app: &mut SolveApp, ui: &mut egui::Ui, rows: &mut Rows, index: usname,kind: ty,selected,- hovered: response.hovered() || rows.from_view == Some(id) || rows.linked_hover == Some(id),+ hovered: response.hovered() || rows.from_view.contains(&Some(id)) || rows.linked_hover == Some(id),dim: rolled,suppressed: *suppressed,error: error.is_some(),