From b996b3773e2ffcbeac5f3ed87e9ba9d17a2c3f56 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 24 Jun 2019 14:48:47 -0700 Subject: [PATCH] view all routes tool in debug mode --- editor/src/common/agent.rs | 5 +-- editor/src/common/route_viewer.rs | 37 +------------------- editor/src/debug/mod.rs | 12 +++++++ editor/src/debug/routes.rs | 57 +++++++++++++++++++++++++++++++ editor/src/sandbox/mod.rs | 2 -- 5 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 editor/src/debug/routes.rs diff --git a/editor/src/common/agent.rs b/editor/src/common/agent.rs index 72ade41a9a..2a7c6ab68b 100644 --- a/editor/src/common/agent.rs +++ b/editor/src/common/agent.rs @@ -24,14 +24,11 @@ impl AgentTools { RouteViewer::Active(_, trip, _) => { txt.add_line(format!("Showing {}'s route", trip)); } - RouteViewer::DebugAllRoutes(_, _) => { - txt.add_line("Showing all routes".to_string()); - } _ => {} } } - pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, menu: &mut ModalMenu) { + pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) { if self.following.is_none() { if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) { if let Some(trip) = ui.primary.sim.agent_to_trip(agent) { diff --git a/editor/src/common/route_viewer.rs b/editor/src/common/route_viewer.rs index 1df85f4878..ff3fa0ba2e 100644 --- a/editor/src/common/route_viewer.rs +++ b/editor/src/common/route_viewer.rs @@ -9,19 +9,16 @@ pub enum RouteViewer { Inactive, Hovering(Duration, AgentID, PolyLine), Active(Duration, TripID, Option), - DebugAllRoutes(Duration, Vec), } impl RouteViewer { - pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, menu: &mut ModalMenu) { + pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) { match self { RouteViewer::Inactive => { if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) { if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) { *self = RouteViewer::Hovering(ui.primary.sim.time(), agent, trace); } - } else if menu.action("show/hide route for all agents") { - *self = debug_all_routes(ui); } } RouteViewer::Hovering(time, agent, _) => { @@ -62,13 +59,6 @@ impl RouteViewer { *self = show_route(*trip, ui); } } - RouteViewer::DebugAllRoutes(time, _) => { - if menu.action("show/hide route for all agents") { - *self = RouteViewer::Inactive; - } else if *time != ui.primary.sim.time() { - *self = debug_all_routes(ui); - } - } } } @@ -86,11 +76,6 @@ impl RouteViewer { &trace.make_polygons(LANE_THICKNESS), ); } - RouteViewer::DebugAllRoutes(_, ref traces) => { - for t in traces { - g.draw_polygon(ui.cs.get("route"), &t.make_polygons(LANE_THICKNESS)); - } - } _ => {} } } @@ -114,23 +99,3 @@ fn show_route(trip: TripID, ui: &UI) -> RouteViewer { RouteViewer::Active(time, trip, None) } } - -fn debug_all_routes(ui: &mut UI) -> RouteViewer { - let mut traces: Vec = Vec::new(); - let trips: Vec = ui - .primary - .sim - .get_trip_positions(&ui.primary.map) - .canonical_pt_per_trip - .keys() - .cloned() - .collect(); - for trip in trips { - if let Some(agent) = ui.primary.sim.trip_to_agent(trip) { - if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) { - traces.push(trace); - } - } - } - RouteViewer::DebugAllRoutes(ui.primary.sim.time(), traces) -} diff --git a/editor/src/debug/mod.rs b/editor/src/debug/mod.rs index 3e2983f702..765c6ada39 100644 --- a/editor/src/debug/mod.rs +++ b/editor/src/debug/mod.rs @@ -5,6 +5,7 @@ mod connected_roads; mod neighborhood_summary; mod objects; mod polygons; +mod routes; use crate::common::CommonState; use crate::edit::EditMode; @@ -35,6 +36,7 @@ pub struct DebugMode { layers: ShowLayers, search_results: Option<(String, HashSet)>, neighborhood_summary: neighborhood_summary::NeighborhoodSummary, + all_routes: routes::AllRoutesViewer, } impl DebugMode { @@ -60,6 +62,7 @@ impl DebugMode { (hotkey(Key::M), "clear OSM search results"), (hotkey(Key::S), "configure colors"), (hotkey(Key::N), "show/hide neighborhood summaries"), + (hotkey(Key::R), "show/hide route for all agents"), (lctrl(Key::S), "sandbox mode"), (lctrl(Key::E), "edit mode"), ], @@ -83,6 +86,7 @@ impl DebugMode { ctx.prerender, &mut Timer::new("set up DebugMode"), ), + all_routes: routes::AllRoutesViewer::Inactive, } } } @@ -123,6 +127,12 @@ impl State for DebugMode { if self.neighborhood_summary.active { txt.add_line("Showing neighborhood summaries".to_string()); } + match self.all_routes { + routes::AllRoutesViewer::Active(_, ref traces) => { + txt.add_line(format!("Showing {} routes", traces.len())); + } + _ => {} + } self.menu.handle_event(ctx, Some(txt)); ctx.canvas.handle_event(ctx.input); @@ -148,6 +158,7 @@ impl State for DebugMode { self.chokepoints = Some(chokepoints::ChokepointsFinder::new(&ui.primary.sim)); } } + self.all_routes.event(ui, &mut self.menu); if !self.show_original_roads.is_empty() { if self.menu.action("clear original roads shown") { self.show_original_roads.clear(); @@ -322,6 +333,7 @@ impl State for DebugMode { self.objects.draw(g, ui); self.neighborhood_summary.draw(g); + self.all_routes.draw(g, ui); if !g.is_screencap() { self.menu.draw(g); diff --git a/editor/src/debug/routes.rs b/editor/src/debug/routes.rs new file mode 100644 index 0000000000..eb24e2cf63 --- /dev/null +++ b/editor/src/debug/routes.rs @@ -0,0 +1,57 @@ +use crate::ui::UI; +use ezgui::{GfxCtx, ModalMenu}; +use geom::{Duration, PolyLine}; +use map_model::LANE_THICKNESS; +use sim::TripID; + +pub enum AllRoutesViewer { + Inactive, + Active(Duration, Vec), +} + +impl AllRoutesViewer { + pub fn event(&mut self, ui: &mut UI, menu: &mut ModalMenu) { + match self { + AllRoutesViewer::Inactive => { + if menu.action("show/hide route for all agents") { + *self = debug_all_routes(ui); + } + } + AllRoutesViewer::Active(time, _) => { + if menu.action("show/hide route for all agents") { + *self = AllRoutesViewer::Inactive; + } else if *time != ui.primary.sim.time() { + *self = debug_all_routes(ui); + } + } + } + } + + pub fn draw(&self, g: &mut GfxCtx, ui: &UI) { + if let AllRoutesViewer::Active(_, ref traces) = self { + for t in traces { + g.draw_polygon(ui.cs.get("route"), &t.make_polygons(LANE_THICKNESS)); + } + } + } +} + +fn debug_all_routes(ui: &mut UI) -> AllRoutesViewer { + let mut traces: Vec = Vec::new(); + let trips: Vec = ui + .primary + .sim + .get_trip_positions(&ui.primary.map) + .canonical_pt_per_trip + .keys() + .cloned() + .collect(); + for trip in trips { + if let Some(agent) = ui.primary.sim.trip_to_agent(trip) { + if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) { + traces.push(trace); + } + } + } + AllRoutesViewer::Active(ui.primary.sim.time(), traces) +} diff --git a/editor/src/sandbox/mod.rs b/editor/src/sandbox/mod.rs index 995e4bd682..e87d4ac474 100644 --- a/editor/src/sandbox/mod.rs +++ b/editor/src/sandbox/mod.rs @@ -48,8 +48,6 @@ impl SandboxMode { // TODO Strange to always have this. Really it's a case of stacked modal? (hotkey(Key::F), "stop following agent"), (hotkey(Key::R), "stop showing agent's route"), - // TODO This should probably be a debug thing instead - (hotkey(Key::L), "show/hide route for all agents"), (hotkey(Key::A), "show/hide active traffic"), (hotkey(Key::T), "start time traveling"), (hotkey(Key::Q), "scoreboard"),