From 2bbe191604bdfe9e8d143cb084c6452e01a5df2d Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 13:56:37 +0100 Subject: [PATCH 1/7] Edit Vertices and the phone's shape editing say which feature has no place in longitude/latitude to edit (#2032 C2f-4b-4) --- crates/ui-egui/src/mapview.rs | 5 ++ crates/ui-egui/src/vertexedit.rs | 82 ++++++++++++++++++++++++++++++++ crates/ui-touch/src/edit.rs | 15 ++++-- crates/ui-touch/src/lib.rs | 24 ++++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 97dc521115..4614a1212e 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -313,6 +313,9 @@ pub struct MapView { pub vertex_drag: Option, /// Non-owning source identity for the held vertex gesture; never persisted with the project. pub(crate) vertex_drag_owner: Option, + /// The selected features Edit Vertices last said it can't give handles to (their place can't + /// be given in longitude/latitude), so it says so once per selection. + pub(crate) vertex_unplaced_said: Vec<(u32, usize)>, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. pub move_shared_vertices: bool, /// A sketch vertex clicked on an edge follows that edge from the previous vertex (Trace); @@ -450,6 +453,7 @@ impl Default for MapView { vertex_owner: None, vertex_drag: None, vertex_drag_owner: None, + vertex_unplaced_said: Vec::new(), move_shared_vertices: false, trace_edges: false, sketch_full_said: false, @@ -810,6 +814,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { crate::modelbuilder::follow_view(app); view_tabs(app, ui, &t); crate::vertexedit::cancel_stale_drag(app); + crate::vertexedit::say_unplaced(app); if app.mb.shown() { crate::modelbuilder::show(app, ui); return; diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index b53c8007cb..0039029e82 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -181,6 +181,55 @@ fn targets(app: &RustGisApp) -> Vec<(u32, usize, Cow<'_, Geometry>)> { out } +/// The selected features [`targets`] leaves out, by layer and row, while Edit Vertices is on: +/// those with a place that can't be given in longitude/latitude (#2032 C2f-4b), where handles are +/// drawn and dragged. On a map in the layer's own system such a feature is drawn and selected. +fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { + let m = app.session.map(); + if app.session.tool != rustgis_engine::Tool::EditVertices || !m.editing.settings.enabled { + return Vec::new(); + } + let mut out = Vec::new(); + for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { + for r in l.selection.iter().take(MAX_FEATURES) { + if let Some(g) = l.dataset.features.get(*r).and_then(|f| f.geometry.as_ref()) + && l.dataset.geometry_to_lonlat(g).is_err() + { + out.push((l.id, *r)); + } + } + } + out +} + +/// Says once per selection which selected features Edit Vertices gives no handles to, by layer: +/// one is named, several counted ([`unplaced_targets`]). +pub(crate) fn say_unplaced(app: &mut RustGisApp) { + let left = unplaced_targets(app); + if left == app.map.vertex_unplaced_said { + return; + } + let mut said = Vec::new(); + for layer in left.iter().map(|(l, _)| *l).collect::>() { + let Some(l) = app.session.map().layer(layer) else { continue }; + let rows: Vec = left.iter().filter(|(id, _)| *id == layer).map(|(_, r)| *r).collect(); + let text = match rows.as_slice() { + [r] => l.dataset.features.get(*r).and_then(|f| l.dataset.feature_to_lonlat(f.id, f.geometry.as_ref()?).err()), + rows => Some(format!( + "{}: {} of the selected features have a place in {} that can't be given in longitude/latitude, so their vertices can't be edited there", + l.name, + rows.len(), + l.dataset.coord_crs().label() + )), + }; + said.extend(text); + } + app.map.vertex_unplaced_said = left; + for text in said { + app.session.notify(text, true); + } +} + /// The screen points of an edge's ends, when both are in view. fn edge_on_screen(app: &RustGisApp, rect: Rect, a: Coord, b: Coord) -> Option<(Pos2, Pos2)> { Some((lonlat_to_screen(app, rect, a)?, lonlat_to_screen(app, rect, b)?)) @@ -542,6 +591,39 @@ mod tests { app } + /// A selected feature with a place that can't be given in longitude/latitude gets no handles, + /// and that is said once for the selection, naming it (#2032 C2f-4b); several are counted. + #[test] + fn a_selected_feature_with_no_place_in_longitude_latitude_is_said_once() { + let mut app = app([square(0.), square(2.), square(4.)].into_iter()); + let id = app.session.active_layer.unwrap(); + let utm = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); + let layer = app.session.map_mut().layer_mut(id).unwrap(); + layer.dataset.hold_in(utm).unwrap(); + let far = + |x: f64| Geometry::Polygon(vec![vec![vec![Coord::new(x, 0.), Coord::new(1e9, 0.), Coord::new(x, 1.), Coord::new(x, 0.)]]]); + layer.dataset.features[0].geometry = Some(far(500_000.)); + app.session.map_mut().editing.settings.enabled = true; + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + say_unplaced(&mut app); + let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert_eq!(said.len(), 1, "{said:?}"); + assert!(said[0].contains("feature 0 has a place") && said[0].contains("can't be edited there"), "{said:?}"); + assert!(targets(&app).is_empty()); + // Two of them, selected: counted, once. + let layer = app.session.map_mut().layer_mut(id).unwrap(); + layer.dataset.features[1].geometry = Some(far(500_100.)); + layer.selection = vec![0, 1, 2]; + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + say_unplaced(&mut app); + let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert_eq!(said.len(), 1, "{said:?}"); + assert!(said[0].contains("2 of the selected features"), "{said:?}"); + assert_eq!(targets(&app).len(), 1); + } + /// A held gesture scans once, retains no rows, reprojects after camera changes, and drops /// its cache when any row changes. Restarting captures fresh edges under the new identity. #[test] diff --git a/crates/ui-touch/src/edit.rs b/crates/ui-touch/src/edit.rs index 76570be890..fd38040c51 100644 --- a/crates/ui-touch/src/edit.rs +++ b/crates/ui-touch/src/edit.rs @@ -67,14 +67,23 @@ pub(crate) fn shape(app: &RustGisApp, id: u32, row: usize) -> Option { shape_ref(app, id, row).map(std::borrow::Cow::into_owned) } -/// [`shape`], borrowed while the layer's coordinates are longitude/latitude (as every layer's are -/// today): what is drawn and checked each frame isn't copied for it. Converted from the layer's -/// own coordinates otherwise; `None` when it can't be. +/// [`shape`], borrowed while the layer's coordinates are longitude/latitude: what is drawn and +/// checked each frame isn't copied for it. Converted from the layer's own coordinates otherwise; +/// `None` when it can't be ([`unplaced`] says why). pub(crate) fn shape_ref(app: &RustGisApp, id: u32, row: usize) -> Option> { let l = app.session.map().layer(id)?; l.dataset.geometry_to_lonlat(l.dataset.features.get(row)?.geometry.as_ref()?).ok() } +/// Why the shape of the feature in row `row` of layer `id` can't be edited here ([`shape_ref`] is +/// `None`): one of its places can't be given in longitude/latitude, said naming the layer and the +/// feature. `None` when it can be, or the row is gone. +pub(crate) fn unplaced(app: &RustGisApp, id: u32, row: usize) -> Option { + let l = app.session.map().layer(id)?; + let f = l.dataset.features.get(row)?; + l.dataset.feature_to_lonlat(f.id, f.geometry.as_ref()?).err() +} + /// Whether putting vertex `v` of `shape` at `at` (`move`), or a new one there after it /// (`insert`), would leave two vertices in one place in a row: on the screen, within a point of /// each other. The edge between them would have no length, which the capture draft refuses too. diff --git a/crates/ui-touch/src/lib.rs b/crates/ui-touch/src/lib.rs index 49031c9c3f..b9d7696e86 100644 --- a/crates/ui-touch/src/lib.rs +++ b/crates/ui-touch/src/lib.rs @@ -1389,7 +1389,13 @@ fn edit_sheet( }; // The shape is borrowed for each look at it, not copied each frame: the buttons change it. let Some(status) = edit::shape_ref(app, target.id, row).map(|shape| edit::status(target.kind, &shape, editing.vertex)) else { + // A feature with a place that can't be given in longitude/latitude (#2032 C2f-4b): drawn + // on a map in its layer's own system, but shapes are edited here in longitude/latitude. + // Said, as editing it ends. state.editing = None; + if let Some(why) = edit::unplaced(app, target.id, row) { + app.session.notify(why, true); + } return; }; ui.label(RichText::new(status).size(14.0).color(t.text)); @@ -2456,6 +2462,24 @@ mod tests { assert_eq!(edit::Editing::feature(7).picking(Some(VertexId::new(0, 0, 9)), Some(&abc)).vertex, None); } + /// A feature with a place that can't be given in longitude/latitude (#2032 C2f-4b) has no + /// shape to edit here, and why is said, naming it; a placed one has. + #[test] + fn a_feature_with_no_place_in_longitude_latitude_says_why_it_cant_be_edited() { + use rustgis_ui_egui::rustgis_engine::data::{Coord, Geometry, raster::Crs}; + let mut app = RustGisApp::with_sample(); + let cities = target(&mut app, GeometryType::Point); + let layer = app.session.map_mut().layer_mut(cities.id).unwrap(); + layer.dataset.hold_in(Crs::from_epsg(8857).unwrap()).unwrap(); + let id = layer.dataset.features[0].id; + layer.dataset.features[0].geometry = Some(Geometry::Point(Coord::new(1e9, 0.0))); + assert!(edit::shape_ref(&app, cities.id, 0).is_none()); + let why = edit::unplaced(&app, cities.id, 0).unwrap(); + assert!(why.contains(&format!("feature {id} has a place")) && why.contains("can't be edited there"), "{why}"); + assert!(edit::shape_ref(&app, cities.id, 1).is_some()); + assert_eq!(edit::unplaced(&app, cities.id, 1), None); + } + #[test] fn move_point_here_moves_a_point_and_refuses_a_multipoint() { let mut app = RustGisApp::with_sample(); From 64fc9b382d7b21b28215525aaaab06b59e20af8c Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 14:19:30 +0100 Subject: [PATCH 2/7] Review: Edit Vertices counts as it looks (one conversion a layer, its cap), says it in the user's language, forgets on another project; guide (#2032 C2f-4b-4) --- crates/ui-egui/src/mapview.rs | 1 + crates/ui-egui/src/vertexedit.rs | 38 ++++++++++++++++++++------------ crates/ui-touch/src/edit.rs | 3 ++- docs/user-guide/editing.md | 4 +++- docs/user-guide/field-work.md | 4 +++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 4614a1212e..827bd3c612 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -527,6 +527,7 @@ impl MapView { self.split_gpu = None; self.live_rev = None; self.gpu_turn_declined = None; + self.vertex_unplaced_said.clear(); self.labels.clear(); self.label_lonlat.clear(); self.label_map.clear(); diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index 0039029e82..8c10470cf4 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; use egui::{Color32, Painter, Pos2, Rect, Stroke, vec2}; -use rustgis_engine::data::{Feature, Geometry, VertexId}; +use rustgis_engine::data::{Dataset, Feature, Geometry, VertexId}; use rustgis_engine::geom::Coord; use serde_json::json; @@ -189,13 +189,20 @@ fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { if app.session.tool != rustgis_engine::Tool::EditVertices || !m.editing.settings.enabled { return Vec::new(); } - let mut out = Vec::new(); + // The features `targets` looks at, in its order and up to its cap, so a feature past it (which + // gets no handles either way) isn't counted; each layer's conversion made once. + let (mut out, mut seen) = (Vec::new(), 0usize); for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { - for r in l.selection.iter().take(MAX_FEATURES) { - if let Some(g) = l.dataset.features.get(*r).and_then(|f| f.geometry.as_ref()) - && l.dataset.geometry_to_lonlat(g).is_err() - { - out.push((l.id, *r)); + let to = l.dataset.shown_conversion(); + for r in &l.selection { + if seen >= MAX_FEATURES { + return out; + } + if let Some(g) = l.dataset.features.get(*r).and_then(|f| f.geometry.as_ref()) { + seen += 1; + if to.as_ref().map_or(true, |to| Dataset::converted_to_lonlat(to, g).is_none()) { + out.push((l.id, *r)); + } } } } @@ -215,11 +222,9 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { let rows: Vec = left.iter().filter(|(id, _)| *id == layer).map(|(_, r)| *r).collect(); let text = match rows.as_slice() { [r] => l.dataset.features.get(*r).and_then(|f| l.dataset.feature_to_lonlat(f.id, f.geometry.as_ref()?).err()), - rows => Some(format!( - "{}: {} of the selected features have a place in {} that can't be given in longitude/latitude, so their vertices can't be edited there", - l.name, - rows.len(), - l.dataset.coord_crs().label() + rows => Some(crate::i18n::fmt( + "{layer}: {count} of the selected features have a place in {system} that can't be given in longitude/latitude, so their vertices can't be edited there", + &[("layer", &l.name), ("count", &rows.len().to_string()), ("system", &l.dataset.coord_crs().label())], )), }; said.extend(text); @@ -598,12 +603,17 @@ mod tests { let mut app = app([square(0.), square(2.), square(4.)].into_iter()); let id = app.session.active_layer.unwrap(); let utm = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); + app.session.map_mut().editing.settings.enabled = true; + app.session.map_mut().layer_mut(id).unwrap().dataset.hold_in(utm).unwrap(); + // Placed features: nothing to say. + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + assert!(app.session.notices_since(mark).is_empty()); + assert_eq!(targets(&app).len(), 1); let layer = app.session.map_mut().layer_mut(id).unwrap(); - layer.dataset.hold_in(utm).unwrap(); let far = |x: f64| Geometry::Polygon(vec![vec![vec![Coord::new(x, 0.), Coord::new(1e9, 0.), Coord::new(x, 1.), Coord::new(x, 0.)]]]); layer.dataset.features[0].geometry = Some(far(500_000.)); - app.session.map_mut().editing.settings.enabled = true; let mark = app.session.notice_mark(); say_unplaced(&mut app); say_unplaced(&mut app); diff --git a/crates/ui-touch/src/edit.rs b/crates/ui-touch/src/edit.rs index fd38040c51..2e7ef801e3 100644 --- a/crates/ui-touch/src/edit.rs +++ b/crates/ui-touch/src/edit.rs @@ -69,7 +69,8 @@ pub(crate) fn shape(app: &RustGisApp, id: u32, row: usize) -> Option { /// [`shape`], borrowed while the layer's coordinates are longitude/latitude: what is drawn and /// checked each frame isn't copied for it. Converted from the layer's own coordinates otherwise; -/// `None` when it can't be ([`unplaced`] says why). +/// `None` when it can't be (for a feature whose place can't be given in longitude/latitude, +/// [`unplaced`] says why). pub(crate) fn shape_ref(app: &RustGisApp, id: u32, row: usize) -> Option> { let l = app.session.map().layer(id)?; l.dataset.geometry_to_lonlat(l.dataset.features.get(row)?.geometry.as_ref()?).ok() diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index 96d4001981..0b65ff7d13 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -133,7 +133,9 @@ you edit the value or choose units; click **Apply elevation** to apply the new i - **Edit Vertices** (Edit › Features): reshape the selected features on the map. Their vertices show as square handles and each edge has a round midpoint handle. Drag a vertex to move it; drag a midpoint, or click an edge, to insert a vertex; click a vertex and press ++delete++ to - remove it (a line keeps at least two vertices, a polygon ring three). Clicking elsewhere + remove it (a line keeps at least two vertices, a polygon ring three). A selected feature with + a place that can't be given in longitude/latitude (see [Places with no longitude/latitude](data-formats.md#places-with-no-longitudelatitude)) + gets no handles, and a notice names it once. Clicking elsewhere selects the feature there (++shift++ adds it). Multipart features and polygon holes work the same way, dragged vertices snap when snapping is on, and each move, insertion or deletion is one undo step. ++esc++ finishes. From scripts and the command line, `edit.vertex` does the diff --git a/docs/user-guide/field-work.md b/docs/user-guide/field-work.md index 965df02179..925496063a 100644 --- a/docs/user-guide/field-work.md +++ b/docs/user-guide/field-work.md @@ -110,7 +110,9 @@ marked with a green ring, when adding and editing alike. **Edit**, beside **Add** at the top of the Capture sheet, changes shapes already on the map, again at the cross: -- **Pick Feature at Cross** picks the feature under the cross and draws its vertices. +- **Pick Feature at Cross** picks the feature under the cross and draws its vertices. A feature + with a place that can't be given in longitude/latitude can't be reshaped here: a notice names it + and the pick ends. - For a line or polygon, **Pick Vertex at Cross** picks the nearest vertex. Then **Move Here** moves it to the cross, **Add After** adds a vertex there after it, and **Delete Vertex** removes it. From 02e9a314d8f7d775fbb32cc21ee774296bfb30f3 Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 14:43:54 +0100 Subject: [PATCH 3/7] Review: the unplaced count stops where the handles do; kept with its map; row accessors; LiDAR places checked past a dropped point (#2032 C2f-4b-4) --- crates/data/src/lidar.rs | 14 ++++---- crates/ui-egui/src/mapview.rs | 5 +-- crates/ui-egui/src/vertexedit.rs | 62 +++++++++++++++++++++++++------- crates/ui-touch/src/edit.rs | 4 +-- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/crates/data/src/lidar.rs b/crates/data/src/lidar.rs index c5281101d2..2d31771eed 100644 --- a/crates/data/src/lidar.rs +++ b/crates/data/src/lidar.rs @@ -692,25 +692,27 @@ mod tests { /// the source, while missing records still prevent a whole read. #[test] fn source_materializes_with_counted_losses() { - let mut bytes = las(2, 0, &[(0.0, 0.0, 3.0, 2), (1.0, 0.0, 4.0, 2)], Some("EPSG:32632")); - // A finite scale overflows only the second point's X during coordinate decoding. + let mut bytes = las(2, 0, &[(0.0, 0.0, 3.0, 2), (1.0, 0.0, 4.0, 2), (0.0, 0.0, 5.0, 2)], Some("EPSG:32632")); + // A finite scale overflows only the second point's X during coordinate decoding: the one in + // the middle. bytes[131..139].copy_from_slice(&f64::MAX.to_le_bytes()); let (direct, report) = read_bytes(&bytes, "lossy", None).unwrap(); - assert_eq!(direct.features.len(), 1); + assert_eq!(direct.features.len(), 2); assert!(!direct.crs_incomplete); assert_eq!(report.skipped, 1); assert_eq!(report.messages, ["lossy: one point has a coordinate that isn't a number (NaN or infinite) and was left out"]); let src = crate::source::open_bytes("lossy.las", bytes.clone(), None).unwrap(); - assert_eq!(src.info().count, Some(2)); + assert_eq!(src.info().count, Some(3)); let (ds, report) = crate::source::materialize(src.as_ref()).unwrap(); assert_eq!(ds.features, direct.features); assert!(!ds.crs_incomplete); assert_eq!(report.skipped, 1); assert_eq!(report.messages.len(), 1, "{:?}", report.messages); - // The sample's places stay in step with its points past the one left out. + // The sample's places stay in step with its points past the one left out: the point after + // it is found by its own place. let around = Extent::new(4.0, -1.0, 5.0, 1.0); let batch = src.read(&crate::source::Request { extent: Some(around), limit: 10, own: None }).unwrap(); - assert_eq!(batch.features.iter().map(|f| f.id).collect::>(), [0]); + assert_eq!(batch.features.iter().map(|f| f.id).collect::>(), [0, 2]); bytes.truncate(bytes.len() - usize::from(RECORD_LEN[0])); assert!(crate::io::read_bytes("truncated.las", &bytes).is_err()); let truncated = crate::source::open_bytes("truncated.las", bytes, None).unwrap(); diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 827bd3c612..c271f74a8f 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -314,8 +314,9 @@ pub struct MapView { /// Non-owning source identity for the held vertex gesture; never persisted with the project. pub(crate) vertex_drag_owner: Option, /// The selected features Edit Vertices last said it can't give handles to (their place can't - /// be given in longitude/latitude), so it says so once per selection. - pub(crate) vertex_unplaced_said: Vec<(u32, usize)>, + /// be given in longitude/latitude), by map index, layer and row, so it says so once per + /// selection. + pub(crate) vertex_unplaced_said: Vec<(usize, u32, usize)>, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. pub move_shared_vertices: bool, /// A sketch vertex clicked on an edge follows that edge from the previous vertex (Trace); diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index 8c10470cf4..387837b484 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -189,19 +189,20 @@ fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { if app.session.tool != rustgis_engine::Tool::EditVertices || !m.editing.settings.enabled { return Vec::new(); } - // The features `targets` looks at, in its order and up to its cap, so a feature past it (which - // gets no handles either way) isn't counted; each layer's conversion made once. - let (mut out, mut seen) = (Vec::new(), 0usize); + // The features `targets` looks at, in its order, until it has its cap of placed ones: a + // feature past that gets no handles either way, so isn't counted. Each layer's conversion is + // made once. + let (mut out, mut placed) = (Vec::new(), 0usize); for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { let to = l.dataset.shown_conversion(); for r in &l.selection { - if seen >= MAX_FEATURES { + if placed >= MAX_FEATURES { return out; } - if let Some(g) = l.dataset.features.get(*r).and_then(|f| f.geometry.as_ref()) { - seen += 1; - if to.as_ref().map_or(true, |to| Dataset::converted_to_lonlat(to, g).is_none()) { - out.push((l.id, *r)); + if let Some(g) = l.dataset.features.geometry(*r) { + match to.as_ref().ok().and_then(|to| Dataset::converted_to_lonlat(to, g)) { + Some(_) => placed += 1, + None => out.push((l.id, *r)), } } } @@ -212,16 +213,18 @@ fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { /// Says once per selection which selected features Edit Vertices gives no handles to, by layer: /// one is named, several counted ([`unplaced_targets`]). pub(crate) fn say_unplaced(app: &mut RustGisApp) { - let left = unplaced_targets(app); + // The map's index goes with the features: another map's layers may have the same ids. + let map = app.session.project.active_map; + let left: Vec<(usize, u32, usize)> = unplaced_targets(app).into_iter().map(|(l, r)| (map, l, r)).collect(); if left == app.map.vertex_unplaced_said { return; } let mut said = Vec::new(); - for layer in left.iter().map(|(l, _)| *l).collect::>() { + for layer in left.iter().map(|(_, l, _)| *l).collect::>() { let Some(l) = app.session.map().layer(layer) else { continue }; - let rows: Vec = left.iter().filter(|(id, _)| *id == layer).map(|(_, r)| *r).collect(); + let rows: Vec = left.iter().filter(|(_, id, _)| *id == layer).map(|(_, _, r)| *r).collect(); let text = match rows.as_slice() { - [r] => l.dataset.features.get(*r).and_then(|f| l.dataset.feature_to_lonlat(f.id, f.geometry.as_ref()?).err()), + [r] => l.dataset.features.row(*r).and_then(|f| l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err()), rows => Some(crate::i18n::fmt( "{layer}: {count} of the selected features have a place in {system} that can't be given in longitude/latitude, so their vertices can't be edited there", &[("layer", &l.name), ("count", &rows.len().to_string()), ("system", &l.dataset.coord_crs().label())], @@ -634,6 +637,41 @@ mod tests { assert_eq!(targets(&app).len(), 1); } + /// The count stops where the handles do: at their cap of placed features. With 49 placed + /// ones selected first, the two unplaced after them are both counted; past 50 placed, one + /// isn't, as it gets no handles either way. + #[test] + fn the_unplaced_count_follows_the_handles_cap() { + let squares = (0..53).map(|i| square(f64::from(i) * 0.05)); + let mut app = app(squares); + let id = app.session.active_layer.unwrap(); + let utm = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); + app.session.map_mut().editing.settings.enabled = true; + let layer = app.session.map_mut().layer_mut(id).unwrap(); + layer.dataset.hold_in(utm).unwrap(); + let far = Geometry::Polygon(vec![vec![vec![ + Coord::new(500_000., 0.), + Coord::new(1e9, 0.), + Coord::new(500_000., 1.), + Coord::new(500_000., 0.), + ]]]); + for r in [49, 50, 52] { + layer.dataset.features.set_geometry(r, Some(far.clone())); + } + layer.selection = (0..53).collect(); + // 49 placed, two unplaced (49, 50), the 50th placed (51): the cap; 52 is past it. + assert_eq!(unplaced_targets(&app), [(id, 49), (id, 50)]); + assert_eq!(targets(&app).len(), MAX_FEATURES); + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(said.len() == 1 && said[0].contains("2 of the selected features"), "{said:?}"); + // What was said is kept with its map, so another map's layer of the same id and rows is + // said for itself. + let map = app.session.project.active_map; + assert_eq!(app.map.vertex_unplaced_said, [(map, id, 49), (map, id, 50)]); + } + /// A held gesture scans once, retains no rows, reprojects after camera changes, and drops /// its cache when any row changes. Restarting captures fresh edges under the new identity. #[test] diff --git a/crates/ui-touch/src/edit.rs b/crates/ui-touch/src/edit.rs index 2e7ef801e3..d9f8372fd3 100644 --- a/crates/ui-touch/src/edit.rs +++ b/crates/ui-touch/src/edit.rs @@ -81,8 +81,8 @@ pub(crate) fn shape_ref(app: &RustGisApp, id: u32, row: usize) -> Option Option { let l = app.session.map().layer(id)?; - let f = l.dataset.features.get(row)?; - l.dataset.feature_to_lonlat(f.id, f.geometry.as_ref()?).err() + let f = l.dataset.features.row(row)?; + l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err() } /// Whether putting vertex `v` of `shape` at `at` (`move`), or a new one there after it From 0fb105fe841b0baeb0cf63eda503983383ac786a Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 15:16:38 +0100 Subject: [PATCH 4/7] Review: one translated notice for every layer, naming a lone feature; the selection looked at again only when it, its layer or the map changes (#2032 C2f-4b-4) --- crates/ui-egui/src/mapview.rs | 4 ++ crates/ui-egui/src/vertexedit.rs | 64 ++++++++++++++++++++++++-------- crates/ui-touch/src/edit.rs | 6 ++- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index c271f74a8f..ed60cdbe8d 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -317,6 +317,8 @@ pub struct MapView { /// be given in longitude/latitude), by map index, layer and row, so it says so once per /// selection. pub(crate) vertex_unplaced_said: Vec<(usize, u32, usize)>, + /// What those features were last looked for under, so they aren't looked for each frame. + pub(crate) vertex_unplaced_seen: Option, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. pub move_shared_vertices: bool, /// A sketch vertex clicked on an edge follows that edge from the previous vertex (Trace); @@ -455,6 +457,7 @@ impl Default for MapView { vertex_drag: None, vertex_drag_owner: None, vertex_unplaced_said: Vec::new(), + vertex_unplaced_seen: None, move_shared_vertices: false, trace_edges: false, sketch_full_said: false, @@ -529,6 +532,7 @@ impl MapView { self.live_rev = None; self.gpu_turn_declined = None; self.vertex_unplaced_said.clear(); + self.vertex_unplaced_seen = None; self.labels.clear(); self.label_lonlat.clear(); self.label_map.clear(); diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index 387837b484..b9258fb548 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -210,30 +210,60 @@ fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { out } -/// Says once per selection which selected features Edit Vertices gives no handles to, by layer: -/// one is named, several counted ([`unplaced_targets`]). +/// What [`unplaced_targets`] depends on: the map, the tool, editing, and each layer it looks at +/// (its id, geometry revision and rows' allocation, which any mutable row access renews, system, +/// the map system it is shown through, and selection). While it is +/// unchanged, the selection isn't converted again each frame. +fn unplaced_signature(app: &RustGisApp) -> u64 { + use std::hash::{Hash, Hasher}; + let m = app.session.map(); + let mut h = std::collections::hash_map::DefaultHasher::new(); + (app.session.project.active_map, app.session.tool == rustgis_engine::Tool::EditVertices, m.editing.settings.enabled).hash(&mut h); + for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { + let rows = l.dataset.features.allocation_key().as_ptr() as usize; + (l.id, l.geometry_rev, rows, l.dataset.coord_crs(), l.dataset.shown_in, &l.selection).hash(&mut h); + } + h.finish() +} + +/// Says once per selection which selected features Edit Vertices gives no handles to, in one +/// notice: one is named, several counted ([`unplaced_targets`]). pub(crate) fn say_unplaced(app: &mut RustGisApp) { + let signature = unplaced_signature(app); + if app.map.vertex_unplaced_seen == Some(signature) { + return; + } + app.map.vertex_unplaced_seen = Some(signature); // The map's index goes with the features: another map's layers may have the same ids. let map = app.session.project.active_map; let left: Vec<(usize, u32, usize)> = unplaced_targets(app).into_iter().map(|(l, r)| (map, l, r)).collect(); if left == app.map.vertex_unplaced_said { return; } - let mut said = Vec::new(); - for layer in left.iter().map(|(_, l, _)| *l).collect::>() { - let Some(l) = app.session.map().layer(layer) else { continue }; - let rows: Vec = left.iter().filter(|(_, id, _)| *id == layer).map(|(_, _, r)| *r).collect(); - let text = match rows.as_slice() { - [r] => l.dataset.features.row(*r).and_then(|f| l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err()), - rows => Some(crate::i18n::fmt( - "{layer}: {count} of the selected features have a place in {system} that can't be given in longitude/latitude, so their vertices can't be edited there", - &[("layer", &l.name), ("count", &rows.len().to_string()), ("system", &l.dataset.coord_crs().label())], - )), - }; - said.extend(text); - } + let m = app.session.map(); + let text = match left.as_slice() { + [] => None, + [(_, layer, r)] => m.layer(*layer).and_then(|l| { + Some(crate::i18n::fmt( + "{layer}: feature {id} has a place in {system} that can't be given in longitude/latitude, so its vertices can't be edited there", + &[("layer", &l.name), ("id", &l.dataset.features.row(*r)?.id().to_string()), ("system", &l.dataset.coord_crs().label())], + )) + }), + several => { + let mut layers: Vec<&str> = Vec::new(); + for (_, id, _) in several { + if let Some(l) = m.layer(*id).filter(|l| !layers.contains(&l.name.as_str())) { + layers.push(&l.name); + } + } + Some(crate::i18n::fmt( + "{layers}: {count} of the selected features have a place that can't be given in longitude/latitude, so their vertices can't be edited there", + &[("layers", &layers.join(", ")), ("count", &several.len().to_string())], + )) + } + }; app.map.vertex_unplaced_said = left; - for text in said { + if let Some(text) = text { app.session.notify(text, true); } } @@ -617,6 +647,7 @@ mod tests { let far = |x: f64| Geometry::Polygon(vec![vec![vec![Coord::new(x, 0.), Coord::new(1e9, 0.), Coord::new(x, 1.), Coord::new(x, 0.)]]]); layer.dataset.features[0].geometry = Some(far(500_000.)); + layer.touch_geometry(); let mark = app.session.notice_mark(); say_unplaced(&mut app); say_unplaced(&mut app); @@ -627,6 +658,7 @@ mod tests { // Two of them, selected: counted, once. let layer = app.session.map_mut().layer_mut(id).unwrap(); layer.dataset.features[1].geometry = Some(far(500_100.)); + layer.touch_geometry(); layer.selection = vec![0, 1, 2]; let mark = app.session.notice_mark(); say_unplaced(&mut app); diff --git a/crates/ui-touch/src/edit.rs b/crates/ui-touch/src/edit.rs index d9f8372fd3..a3c0b9ebcf 100644 --- a/crates/ui-touch/src/edit.rs +++ b/crates/ui-touch/src/edit.rs @@ -82,7 +82,11 @@ pub(crate) fn shape_ref(app: &RustGisApp, id: u32, row: usize) -> Option Option { let l = app.session.map().layer(id)?; let f = l.dataset.features.row(row)?; - l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err() + l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err()?; + Some(rustgis_ui_egui::i18n::fmt( + "{layer}: feature {id} has a place in {system} that can't be given in longitude/latitude, so its vertices can't be edited there", + &[("layer", &l.name), ("id", &f.id().to_string()), ("system", &l.dataset.coord_crs().label())], + )) } /// Whether putting vertex `v` of `shape` at `at` (`move`), or a new one there after it From 78691a0f5b3953dd290bdf3e928027416f58327f Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 15:36:16 +0100 Subject: [PATCH 5/7] Review: nothing looked at while Edit Vertices is off; the scan bounded ("at least"); live layers; one notice text for desktop and phone (#2032 C2f-4b-4) --- crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/mapview.rs | 6 +- crates/ui-egui/src/vertexedit.rs | 129 +++++++++++++++++++++++-------- crates/ui-touch/src/edit.rs | 5 +- docs/user-guide/editing.md | 2 +- 5 files changed, 102 insertions(+), 41 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0d1bb0fb2c..30af8d0dbd 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -154,6 +154,7 @@ pub use chrome::{DoubleClick, TitlebarMetrics}; pub use coordreadout::{CoordReadout, MapSystem}; pub use rustgis_assistant; pub use rustgis_engine; +pub use vertexedit::unplaced_feature_notice; pub use widgets::big_split_menu; /// Reconciles only command-result wrappers, not parameters or other arbitrary JSON. diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index ed60cdbe8d..16f60f0faa 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -314,9 +314,9 @@ pub struct MapView { /// Non-owning source identity for the held vertex gesture; never persisted with the project. pub(crate) vertex_drag_owner: Option, /// The selected features Edit Vertices last said it can't give handles to (their place can't - /// be given in longitude/latitude), by map index, layer and row, so it says so once per - /// selection. - pub(crate) vertex_unplaced_said: Vec<(usize, u32, usize)>, + /// be given in longitude/latitude), by map index, live layer ([`rustgis_engine::map::Layer::instance_id`]) + /// and row, so it says so once per selection. + pub(crate) vertex_unplaced_said: Vec<(usize, u64, usize)>, /// What those features were last looked for under, so they aren't looked for each frame. pub(crate) vertex_unplaced_seen: Option, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index b9258fb548..077cc3a9e4 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -181,14 +181,16 @@ fn targets(app: &RustGisApp) -> Vec<(u32, usize, Cow<'_, Geometry>)> { out } +/// The most selected features [`say_unplaced`] looks for with no place in longitude/latitude: past +/// it, the notice says "at least" so many, and the scan stops. +const MAX_UNPLACED: usize = 1000; + /// The selected features [`targets`] leaves out, by layer and row, while Edit Vertices is on: /// those with a place that can't be given in longitude/latitude (#2032 C2f-4b), where handles are /// drawn and dragged. On a map in the layer's own system such a feature is drawn and selected. -fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { +/// Up to [`MAX_UNPLACED`] of them; `true` when there are more. +fn unplaced_targets(app: &RustGisApp) -> (Vec<(u32, usize)>, bool) { let m = app.session.map(); - if app.session.tool != rustgis_engine::Tool::EditVertices || !m.editing.settings.enabled { - return Vec::new(); - } // The features `targets` looks at, in its order, until it has its cap of placed ones: a // feature past that gets no handles either way, so isn't counted. Each layer's conversion is // made once. @@ -197,69 +199,98 @@ fn unplaced_targets(app: &RustGisApp) -> Vec<(u32, usize)> { let to = l.dataset.shown_conversion(); for r in &l.selection { if placed >= MAX_FEATURES { - return out; + return (out, false); } if let Some(g) = l.dataset.features.geometry(*r) { match to.as_ref().ok().and_then(|to| Dataset::converted_to_lonlat(to, g)) { Some(_) => placed += 1, + None if out.len() >= MAX_UNPLACED => return (out, true), None => out.push((l.id, *r)), } } } } - out + (out, false) } -/// What [`unplaced_targets`] depends on: the map, the tool, editing, and each layer it looks at -/// (its id, geometry revision and rows' allocation, which any mutable row access renews, system, -/// the map system it is shown through, and selection). While it is -/// unchanged, the selection isn't converted again each frame. +/// What [`unplaced_targets`] depends on: the map and each layer it looks at (the live layer, its +/// replacement and geometry revisions and rows' allocation, which any mutable row access renews, +/// its system, the map system it is shown through, and its selection). While it is unchanged, the +/// selection isn't converted again each frame. fn unplaced_signature(app: &RustGisApp) -> u64 { use std::hash::{Hash, Hasher}; let m = app.session.map(); let mut h = std::collections::hash_map::DefaultHasher::new(); - (app.session.project.active_map, app.session.tool == rustgis_engine::Tool::EditVertices, m.editing.settings.enabled).hash(&mut h); + app.session.project.active_map.hash(&mut h); for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { let rows = l.dataset.features.allocation_key().as_ptr() as usize; - (l.id, l.geometry_rev, rows, l.dataset.coord_crs(), l.dataset.shown_in, &l.selection).hash(&mut h); + let revisions = (l.instance_id(), l.replacement_revision(), l.geometry_rev, rows); + (revisions, l.dataset.coord_crs(), l.dataset.shown_in, &l.selection).hash(&mut h); } h.finish() } +/// The notice for a feature whose vertices can't be edited, as `layer` holds it in `system`: one of +/// its places can't be given in longitude/latitude (#2032 C2f-4b). The desktop's Edit Vertices and +/// the phone's shape editing say it alike. +pub fn unplaced_feature_notice(layer: &str, id: u64, system: &str) -> String { + crate::i18n::fmt( + "{layer}: feature {id} has a place in {system} that can't be given in longitude/latitude, so its vertices can't be edited there", + &[("layer", layer), ("id", &id.to_string()), ("system", system)], + ) +} + /// Says once per selection which selected features Edit Vertices gives no handles to, in one -/// notice: one is named, several counted ([`unplaced_targets`]). +/// notice: one is named, several counted ([`unplaced_targets`]). Nothing is looked at while the +/// tool or editing is off. pub(crate) fn say_unplaced(app: &mut RustGisApp) { + if app.session.tool != rustgis_engine::Tool::EditVertices || !app.session.map().editing.settings.enabled { + // Coming back to the tool says the selection again. + app.map.vertex_unplaced_said.clear(); + app.map.vertex_unplaced_seen = None; + return; + } let signature = unplaced_signature(app); if app.map.vertex_unplaced_seen == Some(signature) { return; } app.map.vertex_unplaced_seen = Some(signature); - // The map's index goes with the features: another map's layers may have the same ids. + // The map's index and the live layer go with the features: another map's layers, or a layer + // added in a removed one's place, may have the same ids. let map = app.session.project.active_map; - let left: Vec<(usize, u32, usize)> = unplaced_targets(app).into_iter().map(|(l, r)| (map, l, r)).collect(); + let (found, more) = unplaced_targets(app); + let m = app.session.map(); + let live = |id: u32| m.layer(id).map_or(0, |l| l.instance_id()); + let left: Vec<(usize, u64, usize)> = found.iter().map(|(l, r)| (map, live(*l), *r)).collect(); if left == app.map.vertex_unplaced_said { return; } - let m = app.session.map(); - let text = match left.as_slice() { - [] => None, - [(_, layer, r)] => m.layer(*layer).and_then(|l| { - Some(crate::i18n::fmt( - "{layer}: feature {id} has a place in {system} that can't be given in longitude/latitude, so its vertices can't be edited there", - &[("layer", &l.name), ("id", &l.dataset.features.row(*r)?.id().to_string()), ("system", &l.dataset.coord_crs().label())], - )) - }), - several => { + let text = match (found.as_slice(), more) { + ([], _) => None, + ([(layer, r)], false) => m + .layer(*layer) + .and_then(|l| Some(unplaced_feature_notice(&l.name, l.dataset.features.row(*r)?.id(), &l.dataset.coord_crs().label()))), + (several, more) => { let mut layers: Vec<&str> = Vec::new(); - for (_, id, _) in several { + for (id, _) in several { if let Some(l) = m.layer(*id).filter(|l| !layers.contains(&l.name.as_str())) { layers.push(&l.name); } } - Some(crate::i18n::fmt( - "{layers}: {count} of the selected features have a place that can't be given in longitude/latitude, so their vertices can't be edited there", - &[("layers", &layers.join(", ")), ("count", &several.len().to_string())], - )) + let count = several.len().to_string(); + let args = [("layers", layers.join(", ")), ("count", count)]; + let args: Vec<(&str, &str)> = args.iter().map(|(k, v)| (*k, v.as_str())).collect(); + Some(if more { + crate::i18n::fmt( + "{layers}: at least {count} of the selected features have a place that can't be given in longitude/latitude, so their vertices can't be edited there", + &args, + ) + } else { + crate::i18n::fmt( + "{layers}: {count} of the selected features have a place that can't be given in longitude/latitude, so their vertices can't be edited there", + &args, + ) + }) } }; app.map.vertex_unplaced_said = left; @@ -692,7 +723,7 @@ mod tests { } layer.selection = (0..53).collect(); // 49 placed, two unplaced (49, 50), the 50th placed (51): the cap; 52 is past it. - assert_eq!(unplaced_targets(&app), [(id, 49), (id, 50)]); + assert_eq!(unplaced_targets(&app), (vec![(id, 49), (id, 50)], false)); assert_eq!(targets(&app).len(), MAX_FEATURES); let mark = app.session.notice_mark(); say_unplaced(&mut app); @@ -700,8 +731,40 @@ mod tests { assert!(said.len() == 1 && said[0].contains("2 of the selected features"), "{said:?}"); // What was said is kept with its map, so another map's layer of the same id and rows is // said for itself. - let map = app.session.project.active_map; - assert_eq!(app.map.vertex_unplaced_said, [(map, id, 49), (map, id, 50)]); + let (map, live) = (app.session.project.active_map, app.session.map().layer(id).unwrap().instance_id()); + assert_eq!(app.map.vertex_unplaced_said, [(map, live, 49), (map, live, 50)]); + // Another tool forgets it, so coming back says it again. + app.run("tool.set", json!({"tool": "explore"})).unwrap(); + say_unplaced(&mut app); + assert!(app.map.vertex_unplaced_said.is_empty()); + app.run("tool.set", json!({"tool": "editVertices"})).unwrap(); + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + assert_eq!(app.session.notices_since(mark).len(), 1); + } + + /// The scan stops at [`MAX_UNPLACED`] features with no place, and the notice says "at least". + #[test] + fn a_selection_with_no_place_at_all_is_counted_up_to_a_bound() { + let far = Geometry::Polygon(vec![vec![vec![ + Coord::new(500_000., 0.), + Coord::new(1e9, 0.), + Coord::new(500_000., 1.), + Coord::new(500_000., 0.), + ]]]); + let mut app = app(std::iter::repeat_n(far, MAX_UNPLACED + 5)); + let id = app.session.active_layer.unwrap(); + app.session.map_mut().editing.settings.enabled = true; + let layer = app.session.map_mut().layer_mut(id).unwrap(); + layer.dataset.held_in = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); + layer.touch_geometry(); + layer.selection = (0..MAX_UNPLACED + 5).collect(); + let (found, more) = unplaced_targets(&app); + assert!(found.len() == MAX_UNPLACED && more); + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(said.len() == 1 && said[0].contains(&format!("at least {MAX_UNPLACED} of the selected")), "{said:?}"); } /// A held gesture scans once, retains no rows, reprojects after camera changes, and drops diff --git a/crates/ui-touch/src/edit.rs b/crates/ui-touch/src/edit.rs index a3c0b9ebcf..b94d2d0b8f 100644 --- a/crates/ui-touch/src/edit.rs +++ b/crates/ui-touch/src/edit.rs @@ -83,10 +83,7 @@ pub(crate) fn unplaced(app: &RustGisApp, id: u32, row: usize) -> Option let l = app.session.map().layer(id)?; let f = l.dataset.features.row(row)?; l.dataset.feature_to_lonlat(f.id(), f.geometry()?).err()?; - Some(rustgis_ui_egui::i18n::fmt( - "{layer}: feature {id} has a place in {system} that can't be given in longitude/latitude, so its vertices can't be edited there", - &[("layer", &l.name), ("id", &f.id().to_string()), ("system", &l.dataset.coord_crs().label())], - )) + Some(rustgis_ui_egui::unplaced_feature_notice(&l.name, f.id(), &l.dataset.coord_crs().label())) } /// Whether putting vertex `v` of `shape` at `at` (`move`), or a new one there after it diff --git a/docs/user-guide/editing.md b/docs/user-guide/editing.md index 0b65ff7d13..79261e3fea 100644 --- a/docs/user-guide/editing.md +++ b/docs/user-guide/editing.md @@ -135,7 +135,7 @@ you edit the value or choose units; click **Apply elevation** to apply the new i drag a midpoint, or click an edge, to insert a vertex; click a vertex and press ++delete++ to remove it (a line keeps at least two vertices, a polygon ring three). A selected feature with a place that can't be given in longitude/latitude (see [Places with no longitude/latitude](data-formats.md#places-with-no-longitudelatitude)) - gets no handles, and a notice names it once. Clicking elsewhere + gets no handles, and a notice says so once, naming it or counting them. Clicking elsewhere selects the feature there (++shift++ adds it). Multipart features and polygon holes work the same way, dragged vertices snap when snapping is on, and each move, insertion or deletion is one undo step. ++esc++ finishes. From scripts and the command line, `edit.vertex` does the From 78b0bfe21d663a24a5998502c9c7d3b0ac9ef797 Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 16:03:36 +0100 Subject: [PATCH 6/7] Review: only the selected rows the scan can reach are hashed; "at least" said when the bound is passed (#2032 C2f-4b-4) --- crates/ui-egui/src/mapview.rs | 4 ++++ crates/ui-egui/src/vertexedit.rs | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 16f60f0faa..ea00adb7ae 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -317,6 +317,8 @@ pub struct MapView { /// be given in longitude/latitude), by map index, live layer ([`rustgis_engine::map::Layer::instance_id`]) /// and row, so it says so once per selection. pub(crate) vertex_unplaced_said: Vec<(usize, u64, usize)>, + /// Whether there were more than those, the notice saying "at least" so many. + pub(crate) vertex_unplaced_more: bool, /// What those features were last looked for under, so they aren't looked for each frame. pub(crate) vertex_unplaced_seen: Option, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. @@ -457,6 +459,7 @@ impl Default for MapView { vertex_drag: None, vertex_drag_owner: None, vertex_unplaced_said: Vec::new(), + vertex_unplaced_more: false, vertex_unplaced_seen: None, move_shared_vertices: false, trace_edges: false, @@ -532,6 +535,7 @@ impl MapView { self.live_rev = None; self.gpu_turn_declined = None; self.vertex_unplaced_said.clear(); + self.vertex_unplaced_more = false; self.vertex_unplaced_seen = None; self.labels.clear(); self.label_lonlat.clear(); diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index 077cc3a9e4..3241f79039 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -215,8 +215,9 @@ fn unplaced_targets(app: &RustGisApp) -> (Vec<(u32, usize)>, bool) { /// What [`unplaced_targets`] depends on: the map and each layer it looks at (the live layer, its /// replacement and geometry revisions and rows' allocation, which any mutable row access renews, -/// its system, the map system it is shown through, and its selection). While it is unchanged, the -/// selection isn't converted again each frame. +/// its system, the map system it is shown through, and its selection: its length and the rows the +/// scan can reach, at most [`MAX_FEATURES`] placed and [`MAX_UNPLACED`] not, so a large selection +/// isn't hashed whole each frame). While it is unchanged, the selection isn't converted again. fn unplaced_signature(app: &RustGisApp) -> u64 { use std::hash::{Hash, Hasher}; let m = app.session.map(); @@ -225,7 +226,8 @@ fn unplaced_signature(app: &RustGisApp) -> u64 { for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { let rows = l.dataset.features.allocation_key().as_ptr() as usize; let revisions = (l.instance_id(), l.replacement_revision(), l.geometry_rev, rows); - (revisions, l.dataset.coord_crs(), l.dataset.shown_in, &l.selection).hash(&mut h); + let reached = l.selection.get(..l.selection.len().min(MAX_FEATURES + MAX_UNPLACED)).unwrap_or_default(); + (revisions, l.dataset.coord_crs(), l.dataset.shown_in, l.selection.len(), reached).hash(&mut h); } h.finish() } @@ -247,6 +249,7 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { if app.session.tool != rustgis_engine::Tool::EditVertices || !app.session.map().editing.settings.enabled { // Coming back to the tool says the selection again. app.map.vertex_unplaced_said.clear(); + app.map.vertex_unplaced_more = false; app.map.vertex_unplaced_seen = None; return; } @@ -262,7 +265,8 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { let m = app.session.map(); let live = |id: u32| m.layer(id).map_or(0, |l| l.instance_id()); let left: Vec<(usize, u64, usize)> = found.iter().map(|(l, r)| (map, live(*l), *r)).collect(); - if left == app.map.vertex_unplaced_said { + // Whether there were more goes with them: past the bound, the count turns to "at least". + if (&left, more) == (&app.map.vertex_unplaced_said, app.map.vertex_unplaced_more) { return; } let text = match (found.as_slice(), more) { @@ -294,6 +298,7 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { } }; app.map.vertex_unplaced_said = left; + app.map.vertex_unplaced_more = more; if let Some(text) = text { app.session.notify(text, true); } @@ -759,6 +764,14 @@ mod tests { layer.dataset.held_in = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); layer.touch_geometry(); layer.selection = (0..MAX_UNPLACED + 5).collect(); + // Exactly the bound: counted as it is. + app.session.map_mut().layer_mut(id).unwrap().selection = (0..MAX_UNPLACED).collect(); + let mark = app.session.notice_mark(); + say_unplaced(&mut app); + let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(said.len() == 1 && said[0].contains(&format!(": {MAX_UNPLACED} of the selected")), "{said:?}"); + // One more: the same features found, and more, which is said. + app.session.map_mut().layer_mut(id).unwrap().selection = (0..MAX_UNPLACED + 5).collect(); let (found, more) = unplaced_targets(&app); assert!(found.len() == MAX_UNPLACED && more); let mark = app.session.notice_mark(); From a373f3038fdaa98a7eb5a9ff8f1068fe42b2853a Mon Sep 17 00:00:00 2001 From: Dominik Strebel Date: Tue, 24 Nov 2026 16:19:27 +0100 Subject: [PATCH 7/7] Review: the selection hashed as far as the last scan went, rows without geometry included (#2032 C2f-4b-4) --- crates/ui-egui/src/mapview.rs | 4 ++ crates/ui-egui/src/vertexedit.rs | 86 ++++++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index ea00adb7ae..63da2526d5 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -319,6 +319,8 @@ pub struct MapView { pub(crate) vertex_unplaced_said: Vec<(usize, u64, usize)>, /// Whether there were more than those, the notice saying "at least" so many. pub(crate) vertex_unplaced_more: bool, + /// How many of each layer's selected rows that scan went through, by live layer. + pub(crate) vertex_unplaced_visited: Vec<(u64, usize)>, /// What those features were last looked for under, so they aren't looked for each frame. pub(crate) vertex_unplaced_seen: Option, /// Session-only opt-in for coincident polygon moves; never saved with a project or preference. @@ -460,6 +462,7 @@ impl Default for MapView { vertex_drag_owner: None, vertex_unplaced_said: Vec::new(), vertex_unplaced_more: false, + vertex_unplaced_visited: Vec::new(), vertex_unplaced_seen: None, move_shared_vertices: false, trace_edges: false, @@ -536,6 +539,7 @@ impl MapView { self.gpu_turn_declined = None; self.vertex_unplaced_said.clear(); self.vertex_unplaced_more = false; + self.vertex_unplaced_visited.clear(); self.vertex_unplaced_seen = None; self.labels.clear(); self.label_lonlat.clear(); diff --git a/crates/ui-egui/src/vertexedit.rs b/crates/ui-egui/src/vertexedit.rs index 3241f79039..f215498240 100644 --- a/crates/ui-egui/src/vertexedit.rs +++ b/crates/ui-egui/src/vertexedit.rs @@ -188,36 +188,56 @@ const MAX_UNPLACED: usize = 1000; /// The selected features [`targets`] leaves out, by layer and row, while Edit Vertices is on: /// those with a place that can't be given in longitude/latitude (#2032 C2f-4b), where handles are /// drawn and dragged. On a map in the layer's own system such a feature is drawn and selected. -/// Up to [`MAX_UNPLACED`] of them; `true` when there are more. -fn unplaced_targets(app: &RustGisApp) -> (Vec<(u32, usize)>, bool) { +/// Up to [`MAX_UNPLACED`] of them. +struct Unplaced { + rows: Vec<(u32, usize)>, + /// There are more than [`MAX_UNPLACED`]. + more: bool, + /// How many of each layer's selected rows the scan went through, by live layer: past them, + /// nothing it says depends on the selection ([`unplaced_signature`]). + visited: Vec<(u64, usize)>, +} + +fn unplaced_targets(app: &RustGisApp) -> Unplaced { let m = app.session.map(); // The features `targets` looks at, in its order, until it has its cap of placed ones: a // feature past that gets no handles either way, so isn't counted. Each layer's conversion is - // made once. - let (mut out, mut placed) = (Vec::new(), 0usize); + // made once. A row without geometry counts towards neither bound. + let mut found = Unplaced { rows: Vec::new(), more: false, visited: Vec::new() }; + let mut placed = 0usize; for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { let to = l.dataset.shown_conversion(); + let mut visited = 0; for r in &l.selection { if placed >= MAX_FEATURES { - return (out, false); + break; } + visited += 1; if let Some(g) = l.dataset.features.geometry(*r) { match to.as_ref().ok().and_then(|to| Dataset::converted_to_lonlat(to, g)) { Some(_) => placed += 1, - None if out.len() >= MAX_UNPLACED => return (out, true), - None => out.push((l.id, *r)), + None if found.rows.len() >= MAX_UNPLACED => { + found.more = true; + break; + } + None => found.rows.push((l.id, *r)), } } } + found.visited.push((l.instance_id(), visited)); + if placed >= MAX_FEATURES || found.more { + break; + } } - (out, false) + found } /// What [`unplaced_targets`] depends on: the map and each layer it looks at (the live layer, its /// replacement and geometry revisions and rows' allocation, which any mutable row access renews, /// its system, the map system it is shown through, and its selection: its length and the rows the -/// scan can reach, at most [`MAX_FEATURES`] placed and [`MAX_UNPLACED`] not, so a large selection -/// isn't hashed whole each frame). While it is unchanged, the selection isn't converted again. +/// last scan went through, `visited`, so a large selection isn't hashed whole each frame). While +/// those are unchanged, the scan would go through the same rows and stop where it did, so the +/// selection isn't converted again. fn unplaced_signature(app: &RustGisApp) -> u64 { use std::hash::{Hash, Hasher}; let m = app.session.map(); @@ -226,7 +246,8 @@ fn unplaced_signature(app: &RustGisApp) -> u64 { for l in m.layers.iter().filter(|l| m.shows(l) && !l.selection.is_empty() && !l.is_raster() && !l.graphics && !l.is_streamed()) { let rows = l.dataset.features.allocation_key().as_ptr() as usize; let revisions = (l.instance_id(), l.replacement_revision(), l.geometry_rev, rows); - let reached = l.selection.get(..l.selection.len().min(MAX_FEATURES + MAX_UNPLACED)).unwrap_or_default(); + let visited = app.map.vertex_unplaced_visited.iter().find(|(id, _)| *id == l.instance_id()).map_or(0, |(_, n)| *n); + let reached = l.selection.get(..l.selection.len().min(visited)).unwrap_or_default(); (revisions, l.dataset.coord_crs(), l.dataset.shown_in, l.selection.len(), reached).hash(&mut h); } h.finish() @@ -251,6 +272,7 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { app.map.vertex_unplaced_said.clear(); app.map.vertex_unplaced_more = false; app.map.vertex_unplaced_seen = None; + app.map.vertex_unplaced_visited.clear(); return; } let signature = unplaced_signature(app); @@ -261,7 +283,8 @@ pub(crate) fn say_unplaced(app: &mut RustGisApp) { // The map's index and the live layer go with the features: another map's layers, or a layer // added in a removed one's place, may have the same ids. let map = app.session.project.active_map; - let (found, more) = unplaced_targets(app); + let Unplaced { rows: found, more, visited } = unplaced_targets(app); + app.map.vertex_unplaced_visited = visited; let m = app.session.map(); let live = |id: u32| m.layer(id).map_or(0, |l| l.instance_id()); let left: Vec<(usize, u64, usize)> = found.iter().map(|(l, r)| (map, live(*l), *r)).collect(); @@ -728,7 +751,8 @@ mod tests { } layer.selection = (0..53).collect(); // 49 placed, two unplaced (49, 50), the 50th placed (51): the cap; 52 is past it. - assert_eq!(unplaced_targets(&app), (vec![(id, 49), (id, 50)], false)); + let found = unplaced_targets(&app); + assert_eq!((found.rows, found.more), (vec![(id, 49), (id, 50)], false)); assert_eq!(targets(&app).len(), MAX_FEATURES); let mark = app.session.notice_mark(); say_unplaced(&mut app); @@ -772,14 +796,46 @@ mod tests { assert!(said.len() == 1 && said[0].contains(&format!(": {MAX_UNPLACED} of the selected")), "{said:?}"); // One more: the same features found, and more, which is said. app.session.map_mut().layer_mut(id).unwrap().selection = (0..MAX_UNPLACED + 5).collect(); - let (found, more) = unplaced_targets(&app); - assert!(found.len() == MAX_UNPLACED && more); + let found = unplaced_targets(&app); + assert!(found.rows.len() == MAX_UNPLACED && found.more); let mark = app.session.notice_mark(); say_unplaced(&mut app); let said: Vec = app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); assert!(said.len() == 1 && said[0].contains(&format!("at least {MAX_UNPLACED} of the selected")), "{said:?}"); } + /// Rows without geometry count towards neither bound, so the scan goes past them, and a change + /// in the selection beyond them is looked at again: a different unplaced feature there is said. + #[test] + fn an_unplaced_feature_past_rows_without_geometry_is_said_when_it_changes() { + let far = Geometry::Polygon(vec![vec![vec![ + Coord::new(500_000., 0.), + Coord::new(1e9, 0.), + Coord::new(500_000., 1.), + Coord::new(500_000., 0.), + ]]]); + let n = MAX_FEATURES + MAX_UNPLACED + 10; + let mut app = app(std::iter::repeat_n(far, n + 2)); + let id = app.session.active_layer.unwrap(); + app.session.map_mut().editing.settings.enabled = true; + let layer = app.session.map_mut().layer_mut(id).unwrap(); + layer.dataset.held_in = rustgis_engine::data::raster::Crs::from_epsg(32631).unwrap(); + for r in 0..n { + layer.dataset.features.set_geometry(r, None); + } + layer.touch_geometry(); + let said = |app: &mut RustGisApp, rows: Vec| { + app.session.map_mut().layer_mut(id).unwrap().selection = rows; + let mark = app.session.notice_mark(); + say_unplaced(app); + app.session.notices_since(mark).iter().map(|n| n.text.clone()).collect::>() + }; + let first = said(&mut app, (0..n).chain([n]).collect()); + assert!(first.len() == 1 && first[0].contains(&format!("feature {n} has a place")), "{first:?}"); + let second = said(&mut app, (0..n).chain([n + 1]).collect()); + assert!(second.len() == 1 && second[0].contains(&format!("feature {} has a place", n + 1)), "{second:?}"); + } + /// A held gesture scans once, retains no rows, reprojects after camera changes, and drops /// its cache when any row changes. Restarting captures fresh edges under the new identity. #[test]