Popup a message when the auto-filter has no effect

This commit is contained in:
Dustin Carlino 2022-03-19 15:33:12 +00:00
parent b87995840d
commit c434bfcb85
4 changed files with 33 additions and 16 deletions

View File

@ -165,7 +165,8 @@ impl State<App> for BrowseNeighborhoods {
{
timer.next();
let neighborhood = Neighborhood::new(ctx, app, id);
app.session.heuristic.apply(ctx, app, &neighborhood, timer);
// Ignore errors
let _ = app.session.heuristic.apply(ctx, app, &neighborhood, timer);
}
});
return Transition::Replace(BrowseNeighborhoods::new_state(ctx, app));

View File

@ -4,7 +4,7 @@ use geom::{Angle, ArrowCap, Distance, PolyLine};
use map_gui::tools::ColorNetwork;
use map_model::{IntersectionID, Perimeter};
use widgetry::mapspace::{ToggleZoomed, World};
use widgetry::tools::PolyLineLasso;
use widgetry::tools::{PolyLineLasso, PopupMsg};
use widgetry::{
DrawBaselayer, EventCtx, GfxCtx, Key, Line, Outcome, Panel, ScreenPt, State, Text, TextExt,
Toggle, Widget,
@ -115,14 +115,24 @@ impl State<App> for Viewer {
match self.left_panel.event(ctx) {
Outcome::Clicked(x) => {
if x == "Automatically stop rat-runs" {
ctx.loading_screen("automatically filter a neighborhood", |ctx, timer| {
match ctx.loading_screen("automatically filter a neighborhood", |ctx, timer| {
app.session
.heuristic
.apply(ctx, app, &self.neighborhood, timer);
});
self.neighborhood = Neighborhood::new(ctx, app, self.neighborhood.id);
self.update(ctx, app);
return Transition::Keep;
.apply(ctx, app, &self.neighborhood, timer)
}) {
Ok(()) => {
self.neighborhood = Neighborhood::new(ctx, app, self.neighborhood.id);
self.update(ctx, app);
return Transition::Keep;
}
Err(err) => {
return Transition::Push(PopupMsg::new_state(
ctx,
"Error",
vec![err.to_string()],
));
}
}
} else if x == "Create filters along a shape" {
return Transition::Push(FreehandFilters::new_state(
ctx,

View File

@ -1,5 +1,7 @@
//! Experiments to make a neighborhood be low-traffic by automatically placing filters to prevent all rat runs.
use anyhow::Result;
use abstutil::Timer;
use map_model::RoadID;
use widgetry::{Choice, EventCtx};
@ -41,7 +43,7 @@ impl Heuristic {
app: &mut App,
neighborhood: &Neighborhood,
timer: &mut Timer,
) {
) -> Result<()> {
if neighborhood
.cells
.iter()
@ -49,10 +51,7 @@ impl Heuristic {
.count()
!= 0
{
warn!(
"Not automatically changing this neighborhood; it already has a disconnected cell"
);
return;
bail!("This neighborhood has a disconnected cell; fix that first");
}
// TODO If we already have no rat-runs, stop
@ -66,8 +65,13 @@ impl Heuristic {
Heuristic::OnlyOneBorder => only_one_border(app, neighborhood),
}
app.session.modal_filters.cancel_empty_edit();
let empty = app.session.modal_filters.cancel_empty_edit();
after_edit(ctx, app);
if empty {
bail!("No new filters created");
} else {
Ok(())
}
}
}

View File

@ -57,16 +57,18 @@ impl ModalFilters {
}
/// If it's possible no edits were made, undo the previous call to `before_edit` and collapse
/// the redundant piece of history.
pub fn cancel_empty_edit(&mut self) {
/// the redundant piece of history. Returns true if the edit was indeed empty.
pub fn cancel_empty_edit(&mut self) -> bool {
if let Some(prev) = self.previous_version.take() {
if self.roads == prev.roads && self.intersections == prev.intersections {
self.previous_version = prev.previous_version;
return true;
} else {
// There was a real difference, keep
self.previous_version = Box::new(Some(prev));
}
}
false
}
/// Modify RoutingParams to respect these modal filters