Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/block_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub(crate) fn export_work(s: &Session, p: &Value) -> Result<super::exports::Work
notes.push((
warn,
format!(
"{path}: the walls are too tall for their textures at this size, so their pictures are squeezed up and down to {:.0}% and their patterns flatter than on the map: give a smaller texture",
"{path}: the walls are too tall for their textures at this size, so their pictures are squeezed to as little as {:.0}% of their height and their patterns look flatter than on the map: give a smaller texture",
flat.squeeze * 100.0
),
));
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu
let (center, scale) = fit_frame(s.map(), &extent, rectangle.as_ref(), whole_globe, (inner_w, inner_h))
.ok_or("the extent can't be drawn on the map's projection")?;
// A name given past the limit is refused, as layout.new refuses it, not cut (#2639).
let given = crate::cmd::within("name", "a layout's name", ps(p, "name").unwrap_or("Publication").trim(), crate::cmd::MAX_NAME)?;
let given = crate::cmd::within("name", "a layout's name", ps(p, "name").unwrap_or(PUBLICATION_NAME).trim(), crate::cmd::MAX_NAME)?;
let (name, name_cut) = unique_name(s, "New Publication Layout", "the name given", &given);
let mut l = Layout::new(name.clone(), w, h);
(l.decimal_comma, l.paper) = (comma, page_colour);
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/cmd/layout/publication/sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}";
/// give them.
pub const PUBLICATION_HEADINGS: [&str; 2] = ["Sources", "Cartographic reference"];

/// The publication's layout name when `"name"` doesn't give one (numbered when a layout already
/// has it): data, not translated.
pub const PUBLICATION_NAME: &str = "Publication";

/// The cartographic reference's lines when `"reference"` isn't given, with a graticule or without
/// one (`{projection}`, `{datum}` and `{grid}` are filled with the sheet's).
pub fn publication_default_reference(graticule: bool) -> [&'static str; 2] {
Expand Down
14 changes: 14 additions & 0 deletions crates/engine/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ impl State {
"name": e.name,
"description": e.description,
"tab": e.tab,
// Where its buttons are when it has no tab of its own.
"place": e.place,
"enabled": self.is_on(e.id),
"default": e.default_on,
"chosen": self.chosen.get(e.id),
Expand Down Expand Up @@ -246,6 +248,18 @@ mod tests {
}
}

#[test]
fn the_list_says_where_an_extension_without_a_tab_is() {
let list = State::default().list();
let entry = |id: &str| list.as_array().and_then(|l| l.iter().find(|e| e["id"] == id)).cloned().unwrap_or_default();
let assistant = entry("assistant");
assert_eq!(assistant["place"], "Analyze › AI");
assert!(assistant["tab"].is_null());
let imagery = entry("imagery");
assert!(imagery["place"].is_null());
assert!(!imagery["tab"].is_null());
}

#[test]
fn a_session_of_its_own_has_every_extension_on_and_the_apps_start_at_the_defaults() {
const { assert!(!IMAGERY.default_on) };
Expand Down
8 changes: 8 additions & 0 deletions crates/engine/src/received.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ impl Session {
pub fn receiving(&mut self, reach: Option<Reach>) -> Option<Reach> {
std::mem::replace(&mut self.received, reach)
}

/// The reach the files opened next are read as from, as `receiving` last set it.
///
/// Returns:
/// The reach set, or `None` when files are read as this computer's own.
pub fn received_reach(&self) -> Option<Reach> {
self.received
}
}

/// What a file names on this computer or the local network, gathered as it is read
Expand Down
7 changes: 6 additions & 1 deletion crates/render/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,14 @@ fn draw_page(

/// `stroke` dashed along `path` by an element's pattern (points, at `ppp` pixels a point), as a
/// line layer's stroke is ([`crate::dash_steps`]): solid when it has none, or when the pattern is
/// under a pixel a round or would cut the path into too many dashes.
/// under a pixel a round or would cut the path into too many dashes, which is counted as a line
/// layer's is ([`crate::approximations::dashes_drawn_solid`]) and said with the page.
fn dashed(stroke: Stroke, dash: Option<&rustgis_map::symbology::Dash>, ppp: f64, path: &tiny_skia::Path) -> Stroke {
let asked = dash.is_some();
let dash = dash.and_then(|d| crate::dash_steps(d, ppp as f32, path)).and_then(|steps| tiny_skia::StrokeDash::new(steps, 0.0));
if asked && dash.is_none() {
crate::approximations::dashes_drawn_solid();
Comment thread
giswqs marked this conversation as resolved.
Resolved
Comment thread
giswqs marked this conversation as resolved.
Resolved
}
Stroke { dash, ..stroke }
}

Expand Down
21 changes: 21 additions & 0 deletions crates/render/src/layout/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3601,6 +3601,27 @@ fn dashed_lines_and_outlines_have_gaps() {
assert!(round(&png(oval(dash))) >= 20, "{}", round(&png(oval(dash))));
}

/// A layout element's dash pattern under a pixel a round is drawn solid and said once with the
/// page; a pattern that can be drawn says nothing.
#[test]
fn a_layout_dash_drawn_solid_is_said() {
let rect = |steps: &[f32]| ElementKind::Rectangle {
fill: Rgba::new(0, 0, 0, 0),
outline: Rgba::rgb(0, 0, 0),
width: 2.0,
radius: 0.0,
dash: rustgis_map::symbology::Dash::new(steps),
};
let dashes =
|said: &crate::ShadowsSaid| said.notices.iter().filter(|n| n.contains("dashed line(s) drawn solid")).cloned().collect::<Vec<_>>();
let (_, said) = crate::shadows_said(|| render(&shape_page(rect(&[0.1, 0.1])), &mut [], 96.0, &PageInfo::default()).unwrap());
let solid = dashes(&said);
assert_eq!(solid.len(), 1, "{said:?}");
assert!(solid[0].contains(": 1 dashed line(s)"), "{solid:?}");
let (_, said) = crate::shadows_said(|| render(&shape_page(rect(&[6.0, 6.0])), &mut [], 96.0, &PageInfo::default()).unwrap());
assert!(dashes(&said).is_empty(), "{said:?}");
}

/// A dashed box round a turned text, on one page (#1763): the picture has the box's gaps and
/// the text running down the page inside it; the recorded page (the PDF's) keeps the dashes as
/// pieces and the text as glyphs; the SVG writes the dash array and the turn.
Expand Down
38 changes: 32 additions & 6 deletions crates/tiles/src/boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,36 @@ fn catalogue_url(level: &str) -> String {
format!("{API}/ALL/{level}/")
}

/// Available countries at one level, with a unit count when the service supplies one.
/// Available countries at one level, with a unit count when the service supplies one, and how
/// many counts given couldn't be read.
/// Reject the entire catalogue on any malformed country entry: skipping it would incorrectly
/// mark that country's level unavailable. The caller offers unknown levels and explains why.
pub fn parse_availability(bytes: &[u8]) -> Result<std::collections::BTreeMap<String, Option<u64>>, String> {
/// A count that isn't a non-negative whole number (as a number, `26.0` included, or as text) is
/// treated as absent: the level is still offered, without a count, and the count is in the
/// number returned for the caller to say. A missing or null count is none to read.
pub fn parse_availability(bytes: &[u8]) -> Result<(std::collections::BTreeMap<String, Option<u64>>, usize), String> {
let v: Value = serde_json::from_slice(bytes).map_err(|_| "the geoBoundaries list isn't JSON".to_string())?;
v.as_array()
let mut unreadable = 0usize;
let available = v
.as_array()
.ok_or_else(|| "the geoBoundaries list isn't a list".to_string())?
.iter()
.map(|entry| {
let iso = country(entry.get("boundaryISO").and_then(Value::as_str).ok_or("missing country code")?)
.map_err(|_| "the geoBoundaries list has an invalid country code")?;
let count = entry.get("admUnitCount").and_then(|n| n.as_u64().or_else(|| n.as_str()?.parse().ok()));
let given = entry.get("admUnitCount").filter(|n| !n.is_null());
let count = given.and_then(|n| {
n.as_u64()
.or_else(|| n.as_f64().filter(|f| f.fract() == 0.0 && (0.0..u64::MAX as f64).contains(f)).map(|f| f as u64))
.or_else(|| n.as_str()?.trim().parse().ok())
});
if given.is_some() && count.is_none() {
unreadable += 1;
}
Ok((iso, count))
})
.collect()
.collect::<Result<_, String>>()?;
Ok((available, unreadable))
}

/// A country's level, as the API describes it.
Expand Down Expand Up @@ -131,11 +146,22 @@ mod tests {
#[test]
fn availability_keeps_counts_and_rejects_unreadable_catalogues() {
let list = br#"[{"boundaryISO":"PER","admUnitCount":"196"},{"boundaryISO":"CHE","admUnitCount":26},{"boundaryISO":"KEN"}]"#;
let parsed = parse_availability(list).unwrap();
let (parsed, unreadable) = parse_availability(list).unwrap();
assert_eq!(unreadable, 0, "every count given is read");
assert_eq!(parsed.get("PER"), Some(&Some(196)));
assert_eq!(parsed.get("CHE"), Some(&Some(26)));
assert_eq!(parsed.get("KEN"), Some(&None));
assert!(!parsed.contains_key("NZL"));
// A whole number written as a float is a count; a negative or unreadable one is none,
// and the country is still listed.
let odd = br#"[{"boundaryISO":"CHE","admUnitCount":26.0},{"boundaryISO":"PER","admUnitCount":-3},{"boundaryISO":"KEN","admUnitCount":"x"},{"boundaryISO":"NZL","admUnitCount":2.5},{"boundaryISO":"FJI","admUnitCount":18446744073709551616.0}]"#;
let (parsed, unreadable) = parse_availability(odd).unwrap();
assert_eq!(unreadable, 4, "-3, x, 2.5 and 2^64 are counted as unreadable");
assert_eq!(parsed.get("CHE"), Some(&Some(26)));
assert_eq!(parsed.get("PER"), Some(&None));
assert_eq!(parsed.get("KEN"), Some(&None));
assert_eq!(parsed.get("NZL"), Some(&None));
assert_eq!(parsed.get("FJI"), Some(&None), "2^64 is past u64");
assert!(parse_availability(b"{}").is_err());
assert!(parse_availability(br#"[{"boundaryName":"Peru"}]"#).is_err());
assert!(parse_availability(br#"[{"boundaryISO":"?"}]"#).is_err());
Expand Down
2 changes: 1 addition & 1 deletion crates/ui-egui/src/assistant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub(crate) fn ensure_loaded(app: &mut RustGisApp, ctx: &egui::Context) {
app.assistant.remember_key = provider::remembers_keys(pref(app, provider::REMEMBER_KEY_PREF).as_deref());
let provider = pref(app, provider::PROVIDER_PREF)
.or_else(|| std::env::var("RUSTGIS_ASSISTANT_PROVIDER").ok())
// One saved before the web app stopped offering it (Ollama Cloud) falls back there.
// One the web app can't use (Ollama Cloud, or a ChatGPT sign-in) falls back there.
.filter(|p| provider::usable_choice(p, cfg!(target_arch = "wasm32")))
// The first provider with a key in the environment (a ChatGPT sign-in and Ollama Cloud are
// chosen, not assumed).
Expand Down
36 changes: 34 additions & 2 deletions crates/ui-egui/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,10 @@ pub fn command_search(app: &mut RustGisApp, ctx: &egui::Context) {
// Enter and the number keys pass over them.
let shown: Vec<_> = hits.iter().take(40).map(|h| (h, search_disabled(app, &h.0))).collect();
let runnable = shown.iter().filter(|(_, why)| why.is_none()).count();
// A new query or a palette opened again starts from the first row, scrolled to.
let reset = !matches!(&cursor, Some(c) if c.query == q && c.pass + 1 >= pass);
let row = match &cursor {
Some(c) if c.query == q && c.pass + 1 >= pass => c.row,
Some(c) if !reset => c.row,
_ => 0,
};
let row = step_row(row, runnable, down, up);
Expand Down Expand Up @@ -2044,7 +2046,7 @@ pub fn command_search(app: &mut RustGisApp, ctx: &egui::Context) {
if !resp.hovered() {
ui.painter().set(under, egui::Shape::rect_filled(resp.rect, CornerRadius::same(5), t.selection));
}
if down || up {
if down || up || reset {
resp.scroll_to_me(None);
}
}
Expand Down Expand Up @@ -2109,6 +2111,8 @@ pub fn command_search(app: &mut RustGisApp, ctx: &egui::Context) {
} else {
ctx.memory_mut(|m| m.surrender_focus(edit_id));
app.ui.command_search_composing = false;
// Opened again, even on the next pass, it starts from the first row.
ctx.data_mut(|d| d.remove::<SearchCursor>(cursor_id));
}
}

Expand Down Expand Up @@ -2427,6 +2431,34 @@ mod tests {
}
}

/// Command Search closed with a row picked and opened again on the next pass starts from the
/// first row: Enter runs it, not the row picked before.
#[test]
fn command_search_opened_again_starts_from_the_first_row() {
use crate::RightPane;
let mut app = RustGisApp::with_sample();
app.session.run("layer.select", &json!({"layer": "Cities"})).unwrap();
app.ui.command_search = Some("ui.pane.la".into());
let mut h = egui_kittest::Harness::builder()
.with_size(vec2(800.0, 600.0))
.build_ui_state(|ui, app: &mut RustGisApp| command_search(app, ui.ctx()), app);
h.run();
h.key_press(Key::ArrowDown);
h.run();
h.key_press(Key::Escape);
h.step();
assert!(h.state().ui.command_search.is_none(), "Escape closes the palette");
// The picked row is forgotten as it closes: a palette opened again in the very next pass
// (a harness step runs two) would otherwise take it back.
let kept: Option<SearchCursor> = h.ctx.data(|d| d.get_temp(egui::Id::unique("command_search_cursor")));
assert!(kept.is_none(), "the picked row is kept after closing: {:?}", kept.map(|c| c.row));
h.state_mut().ui.command_search = Some("ui.pane.la".into());
h.key_press(Key::Enter);
h.step();
h.run();
assert_eq!(h.state().ui.right, Some(RightPane::Labeling), "the first row runs");
}

/// Ctrl (⌘) with a digit runs that row of Command Search; one past the list does nothing.
#[test]
fn command_search_number_keys_run_their_row() {
Expand Down
Loading
Loading