Repository navigation
fix(terrain): a project opens without the water level and block water depth fields its water layer lost (#2456) #2578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ use std::path::PathBuf; | |
| use serde_json::{Value, json}; | ||
|
|
||
| use super::ps; | ||
| use crate::notice_text::NoticeText; | ||
| use crate::{CmdResult, CommandSpec as C, Project, Session, Tool}; | ||
|
|
||
| pub fn commands() -> Vec<C> { | ||
|
|
@@ -449,6 +450,101 @@ fn reset(s: &mut Session, p: Project) { | |
| ); | ||
| } | ||
| } | ||
| // The water's level field (#1915) and the block's water depth field (#2317) are numeric fields | ||
| // of the water layer, as `map.terrain` checks them: one the layer lost, or holds as text, since | ||
| // the project was saved (its data replaced outside RustGIS) is cleared and said, as | ||
| // `edit.deleteField` does. A field matching but for case is kept; a water layer that isn't | ||
| // there is left alone (the water keeps its name for a layer of that name). | ||
| let (mut levels, mut depths) = (Vec::new(), Vec::new()); | ||
| for m in s.project.maps.iter_mut() { | ||
| let Some(t) = m.view.terrain.as_ref() else { continue }; | ||
| let Some(w) = t.water.as_ref() else { continue }; | ||
| let Some(l) = m.layer_by_name(&w.layer) else { continue }; | ||
| let numeric = |f: &str| l.dataset.field_index(f).and_then(|i| l.dataset.fields.get(i)).is_some_and(|f| f.ty.is_numeric()); | ||
| let level = w.level.clone().filter(|f| !numeric(f)); | ||
| let depth = | ||
| t.block.as_ref().and_then(|b| b.water.as_ref()).and_then(|bw| bw.field.clone().filter(|f| !numeric(f)).map(|f| (f, bw.depth))); | ||
| let layer = l.name.clone(); | ||
| let Some(t) = m.view.terrain.as_mut() else { continue }; | ||
| if let Some(field) = level { | ||
| if let Some(w) = t.water.as_mut() { | ||
| w.level = None; | ||
| } | ||
| levels.push((m.name.clone(), field, layer.clone())); | ||
| } | ||
| if let Some((field, d)) = depth { | ||
| if let Some(b) = t.block.as_mut() { | ||
| match d { | ||
| Some(_) => { | ||
| if let Some(bw) = b.water.as_mut() { | ||
| bw.field = None; | ||
| } | ||
| } | ||
| None => b.water = None, | ||
| } | ||
| } | ||
| depths.push((m.name.clone(), field, layer, d)); | ||
| } | ||
| } | ||
| let lit = |s: &String| -> NoticeText { s.clone().into() }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nits, grouped for the release quality pass:
|
||
| match levels.as_slice() { | ||
| [] => {} | ||
| [(map, field, layer)] => s.notify_text( | ||
| NoticeText::format( | ||
| "{map}: the terrain's water level field '{field}' isn't a numeric field of '{layer}', so its lakes lie at their shores' lowest heights", | ||
| [("map", lit(map)), ("field", lit(field)), ("layer", lit(layer))], | ||
| ), | ||
| false, | ||
| ), | ||
| _ => { | ||
| let maps = NoticeText::list(levels.iter().map(|(map, field, layer)| { | ||
| NoticeText::format("{map} ('{field}' of '{layer}')", [("map", lit(map)), ("field", lit(field)), ("layer", lit(layer))]) | ||
| })); | ||
| s.notify_text( | ||
| NoticeText::format( | ||
| "{count} maps have a terrain water level field that isn't a numeric field of their water layer, so their lakes lie at their shores' lowest heights: {maps}", | ||
| [("count", levels.len().to_string().into()), ("maps", maps)], | ||
| ), | ||
| false, | ||
| ); | ||
| } | ||
| } | ||
| match depths.as_slice() { | ||
| [] => {} | ||
| [(map, field, layer, d)] => { | ||
| let (key, mut args) = match d { | ||
| Some(d) => ( | ||
| "{map}: the block's water depth field '{field}' isn't a numeric field of '{layer}', so its walls show all the water {depth} m deep", | ||
| vec![("depth", d.to_string().into())], | ||
| ), | ||
| None => ( | ||
| "{map}: the block's water depth field '{field}' isn't a numeric field of '{layer}', so its walls show no water", | ||
| vec![], | ||
| ), | ||
| }; | ||
| args.extend([("map", lit(map)), ("field", lit(field)), ("layer", lit(layer))]); | ||
| s.notify_text(NoticeText::format(key, args), false); | ||
| } | ||
| _ => { | ||
| let maps = NoticeText::list(depths.iter().map(|(map, field, layer, d)| { | ||
| let args = [("map", lit(map)), ("field", lit(field)), ("layer", lit(layer))]; | ||
| match d { | ||
| Some(d) => NoticeText::format( | ||
| "{map} ('{field}' of '{layer}', its walls showing all the water {depth} m deep)", | ||
| args.into_iter().chain([("depth", d.to_string().into())]), | ||
| ), | ||
| None => NoticeText::format("{map} ('{field}' of '{layer}', its walls showing no water)", args), | ||
| } | ||
| })); | ||
| s.notify_text( | ||
| NoticeText::format( | ||
| "{count} maps have a block water depth field that isn't a numeric field of their water layer: {maps}", | ||
| [("count", depths.len().to_string().into()), ("maps", maps)], | ||
| ), | ||
| false, | ||
| ); | ||
| } | ||
| } | ||
| // A terrain saved on a DEM name two layers share draws the first of them: said, as the | ||
| // project opens (its layers keep their names). | ||
| let shared: Vec<(String, String)> = s | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"format":2,"name":"Terrain water fields lost","maps":[{"name":"Map","layers":[{"id":1,"name":"lagos","visible":true,"dataset":{"name":"lagos","geometry_type":"Polygon","fields":[{"name":"nome","ty":"Text","alias":null},{"name":"prof","ty":"Text","alias":null}],"features":[]},"renderer":{"Single":{"fill":[224,123,57,170],"stroke":[134,74,34,255],"stroke_width":0.7,"size":0.0,"marker":"Circle"}},"labels":{"enabled":false,"field":"nome","size":10.0,"color":[43,43,43,255],"halo":true,"bold":false,"min_scale":null,"max_scale":null,"closest":null,"farthest":null,"placement":"Auto"},"transparency":0.0,"min_scale":null,"max_scale":null,"definition_query":null,"selection":[],"expanded":true,"selectable":true,"graphics":false,"blend":"Normal","mask":null,"display_filters":[],"aggregation":null,"extrusion":null,"priority":0,"geometry_rev":0}],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":{"source":{"Layer":"dem"},"exaggeration":2.0,"block":{"extent":[-500000.0,1500000.0,500000.0,2500000.0],"depth":150.0,"walls":[200,184,154,255],"water":{"depth":8.0,"field":"prof"}},"water":{"layer":"lagos","level":"nivel"}}},"animation":[],"next_layer_id":2}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[],"folders":[],"styles":[],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"requires":["terrain-block","terrain-water","terrain-block-water"]} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question (low confidence, possibly intended): the block-water depth check is skipped whenever the terrain has no water (
let Some(w) = t.water.as_ref() else { continue };). That includes the case where the streamed-water drop just above has clearedt.waterin the same open pass. The block's water field then survives the open unchecked and unsaid. The renderer is inert without terrain water (water_runsreturns early), andmap.terrainre-checks the field when water is set again, so nothing visible breaks. Could you confirm that is the intent, and maybe note it in the doc comment or add a test that a stale block water field with no water is left as it is?