diff --git a/ltn/src/auto.rs b/ltn/src/auto.rs index 6f08154c7e..74ba2442b4 100644 --- a/ltn/src/auto.rs +++ b/ltn/src/auto.rs @@ -4,9 +4,8 @@ use abstutil::Timer; use map_model::RoadID; use widgetry::{Choice, EventCtx}; -use super::rat_runs::find_rat_runs; -use super::Neighborhood; -use crate::App; +use crate::rat_runs::find_rat_runs; +use crate::{after_edit, App, Neighborhood}; #[derive(Clone, Copy, Debug, PartialEq)] pub enum Heuristic { @@ -64,6 +63,7 @@ impl Heuristic { } app.session.modal_filters.cancel_empty_edit(); + after_edit(ctx, app); } } diff --git a/ltn/src/browse.rs b/ltn/src/browse.rs index f1fda1acb4..29cf26e22c 100644 --- a/ltn/src/browse.rs +++ b/ltn/src/browse.rs @@ -12,14 +12,13 @@ use widgetry::{ use super::auto::Heuristic; use super::{Neighborhood, NeighborhoodID, Partitioning}; -use crate::{App, ModalFilters, Toggle3Zoomed, Transition}; +use crate::{App, ModalFilters, Transition}; pub struct BrowseNeighborhoods { panel: Panel, world: World, draw_over_roads: ToggleZoomed, labels: DrawRoadLabels, - draw_all_filters: Toggle3Zoomed, draw_boundary_roads: ToggleZoomed, } @@ -34,13 +33,13 @@ impl BrowseNeighborhoods { app.session.modal_filters = ModalFilters::default(); crate::filters::transform_existing_filters(ctx, app, timer); app.session.partitioning = Partitioning::seed_using_heuristics(app, timer); + app.session.draw_all_filters = app.session.modal_filters.draw(ctx, &app.map); } ( make_world(ctx, app, timer), draw_over_roads(ctx, app, timer), ) }); - let draw_all_filters = app.session.modal_filters.draw(ctx, &app.map, None); let panel = Panel::new_builder(Widget::col(vec![ crate::app_header(ctx, app), @@ -107,7 +106,6 @@ impl BrowseNeighborhoods { world, draw_over_roads, labels: DrawRoadLabels::only_major_roads(), - draw_all_filters, draw_boundary_roads: draw_boundary_roads(ctx, app), }) } @@ -195,7 +193,7 @@ impl State for BrowseNeighborhoods { if self.panel.is_checked("highlight boundary roads") { self.draw_boundary_roads.draw(g); } - self.draw_all_filters.draw(g); + app.session.draw_all_filters.draw(g); if g.canvas.is_unzoomed() { self.labels.draw(g, app); } diff --git a/ltn/src/connectivity.rs b/ltn/src/connectivity.rs index a6c9ae3e87..3389e6e0d2 100644 --- a/ltn/src/connectivity.rs +++ b/ltn/src/connectivity.rs @@ -148,7 +148,7 @@ impl State for Viewer { g.redraw(&self.neighborhood.fade_irrelevant); self.panel.draw(g); - self.neighborhood.draw_filters.draw(g); + app.session.draw_all_filters.draw(g); // TODO Since we cover such a small area, treating multiple segments of one road as the // same might be nice. And we should seed the quadtree with the locations of filters and // arrows, possibly. diff --git a/ltn/src/filters/mod.rs b/ltn/src/filters/mod.rs index 7aed531d22..1c68896d83 100644 --- a/ltn/src/filters/mod.rs +++ b/ltn/src/filters/mod.rs @@ -10,7 +10,6 @@ use widgetry::mapspace::{DrawUnzoomedShapes, ToggleZoomed}; use widgetry::{Color, EventCtx, GeomBatch, GfxCtx}; pub use self::existing::transform_existing_filters; -use super::Neighborhood; use crate::App; /// Stored in App session state. Before making any changes, call `before_edit`. @@ -84,25 +83,12 @@ impl ModalFilters { true } - /// Draw all modal filters. If `only_neighborhood` is specified, only draw filters belonging to - /// one area. - pub fn draw( - &self, - ctx: &EventCtx, - map: &Map, - only_neighborhood: Option<&Neighborhood>, - ) -> Toggle3Zoomed { + /// Draw all modal filters + pub fn draw(&self, ctx: &EventCtx, map: &Map) -> Toggle3Zoomed { let mut batch = ToggleZoomed::builder(); let mut low_zoom = DrawUnzoomedShapes::builder(); for (r, dist) in &self.roads { - if only_neighborhood - .map(|n| !n.orig_perimeter.interior.contains(r)) - .unwrap_or(false) - { - continue; - } - let road = map.get_r(*r); if let Ok((pt, angle)) = road.center_pts.dist_along(*dist) { let road_width = road.get_width(); @@ -135,14 +121,7 @@ impl ModalFilters { ); } } - for (i, filter) in &self.intersections { - if only_neighborhood - .map(|n| !n.interior_intersections.contains(i)) - .unwrap_or(false) - { - continue; - } - + for (_, filter) in &self.intersections { let line = filter.geometry(map); // It's really hard to see a tiny squished line thickened, so use the same circle diff --git a/ltn/src/impact/ui.rs b/ltn/src/impact/ui.rs index f0c271576f..29f6464c19 100644 --- a/ltn/src/impact/ui.rs +++ b/ltn/src/impact/ui.rs @@ -9,14 +9,13 @@ use widgetry::{ }; use super::{end_of_day, Filters, Impact}; -use crate::{App, BrowseNeighborhoods, Toggle3Zoomed, Transition}; +use crate::{App, BrowseNeighborhoods, Transition}; // TODO Share structure or pieces with Ungap's predict mode // ... can't we just produce data of a certain shape, and have a UI pretty tuned for that? pub struct ShowResults { draw_all_neighborhoods: Drawable, - draw_all_filters: Toggle3Zoomed, } impl ShowResults { @@ -66,7 +65,6 @@ impl ShowResults { >::new_state( panel, Box::new(ShowResults { - draw_all_filters: app.session.modal_filters.draw(ctx, &app.map, None), draw_all_neighborhoods, }), ) @@ -153,7 +151,7 @@ impl SimpleState for ShowResults { fn draw(&self, g: &mut GfxCtx, app: &App) { g.redraw(&self.draw_all_neighborhoods); app.session.impact.compare_counts.draw(g); - self.draw_all_filters.draw(g); + app.session.draw_all_filters.draw(g); } } diff --git a/ltn/src/lib.rs b/ltn/src/lib.rs index b12df2e605..457ac86b1c 100644 --- a/ltn/src/lib.rs +++ b/ltn/src/lib.rs @@ -5,7 +5,8 @@ use structopt::StructOpt; use widgetry::{lctrl, EventCtx, GfxCtx, Key, Line, Settings, Widget}; pub use browse::BrowseNeighborhoods; -pub use filters::{DiagonalFilter, ModalFilters, Toggle3Zoomed}; +use filters::Toggle3Zoomed; +pub use filters::{DiagonalFilter, ModalFilters}; pub use neighborhood::{Cell, DistanceInterval, Neighborhood}; pub use partition::{NeighborhoodID, Partitioning}; @@ -60,6 +61,7 @@ fn run(mut settings: Settings) { let session = Session { partitioning: Partitioning::empty(), modal_filters: ModalFilters::default(), + draw_all_filters: Toggle3Zoomed::empty(ctx), impact: impact::Impact::empty(ctx), @@ -120,6 +122,7 @@ pub fn run_wasm(root_dom_id: String, assets_base_url: String, assets_are_gzipped pub struct Session { pub partitioning: Partitioning, pub modal_filters: ModalFilters, + pub draw_all_filters: Toggle3Zoomed, pub impact: impact::Impact, @@ -213,3 +216,7 @@ fn handle_app_header_click(ctx: &mut EventCtx, app: &App, x: &str) -> Option None, } } + +pub fn after_edit(ctx: &EventCtx, app: &mut App) { + app.session.draw_all_filters = app.session.modal_filters.draw(ctx, &app.map); +} diff --git a/ltn/src/neighborhood.rs b/ltn/src/neighborhood.rs index aa9f0a96df..260260021d 100644 --- a/ltn/src/neighborhood.rs +++ b/ltn/src/neighborhood.rs @@ -7,7 +7,7 @@ use map_gui::tools::DrawRoadLabels; use map_model::{IntersectionID, Map, PathConstraints, Perimeter, RoadID}; use widgetry::{Drawable, EventCtx, GeomBatch}; -use crate::{App, ModalFilters, NeighborhoodID, Toggle3Zoomed}; +use crate::{App, ModalFilters, NeighborhoodID}; pub struct Neighborhood { pub id: NeighborhoodID, @@ -23,7 +23,6 @@ pub struct Neighborhood { pub cells: Vec, pub fade_irrelevant: Drawable, - pub draw_filters: Toggle3Zoomed, pub labels: DrawRoadLabels, } @@ -73,7 +72,6 @@ impl Neighborhood { cells: Vec::new(), fade_irrelevant: Drawable::empty(ctx), - draw_filters: Toggle3Zoomed::empty(ctx), // Temporary value labels: DrawRoadLabels::only_major_roads(), }; @@ -123,8 +121,6 @@ impl Neighborhood { &app.session.modal_filters, ); - n.draw_filters = app.session.modal_filters.draw(ctx, map, Some(&n)); - let mut label_roads = n.perimeter.clone(); label_roads.extend(n.orig_perimeter.interior.clone()); n.labels = DrawRoadLabels::new(Box::new(move |r| label_roads.contains(&r.id))); diff --git a/ltn/src/pathfinding.rs b/ltn/src/pathfinding.rs index cc5331a677..218e31e872 100644 --- a/ltn/src/pathfinding.rs +++ b/ltn/src/pathfinding.rs @@ -295,7 +295,7 @@ impl State for RoutePlanner { g.redraw(&self.neighborhood.fade_irrelevant); self.draw_routes.draw(g); - self.neighborhood.draw_filters.draw(g); + app.session.draw_all_filters.draw(g); if g.canvas.is_unzoomed() { self.neighborhood.labels.draw(g, app); } diff --git a/ltn/src/per_neighborhood.rs b/ltn/src/per_neighborhood.rs index 6333683a0e..44407dbd12 100644 --- a/ltn/src/per_neighborhood.rs +++ b/ltn/src/per_neighborhood.rs @@ -7,8 +7,9 @@ use widgetry::{ VerticalAlignment, Widget, DEFAULT_CORNER_RADIUS, }; -use super::{BrowseNeighborhoods, DiagonalFilter, Neighborhood, NeighborhoodID}; -use crate::{App, Transition}; +use crate::{ + after_edit, App, BrowseNeighborhoods, DiagonalFilter, Neighborhood, NeighborhoodID, Transition, +}; #[derive(PartialEq)] pub enum Tab { @@ -206,6 +207,7 @@ pub fn handle_world_outcome( app.session.modal_filters.roads.insert(r, distance); } + after_edit(ctx, app); true } WorldOutcome::ClickedObject(FilterableObj::InteriorIntersection(i)) => { @@ -234,6 +236,7 @@ pub fn handle_world_outcome( .intersections .insert(i, all.remove(0)); } + after_edit(ctx, app); true } WorldOutcome::Keypress("debug", FilterableObj::InteriorIntersection(i)) => { diff --git a/ltn/src/rat_run_viewer.rs b/ltn/src/rat_run_viewer.rs index 8b3636f061..a701c0caef 100644 --- a/ltn/src/rat_run_viewer.rs +++ b/ltn/src/rat_run_viewer.rs @@ -201,7 +201,7 @@ impl State for BrowseRatRuns { } g.redraw(&self.neighborhood.fade_irrelevant); - self.neighborhood.draw_filters.draw(g); + app.session.draw_all_filters.draw(g); if g.canvas.is_unzoomed() { self.neighborhood.labels.draw(g, app); }