diff --git a/editor/src/debug/objects.rs b/editor/src/debug/objects.rs index c81281eb33..9d82d7fadf 100644 --- a/editor/src/debug/objects.rs +++ b/editor/src/debug/objects.rs @@ -1,6 +1,12 @@ use crate::helpers::ID; +use crate::render::DrawMap; +use crate::ui::PerMapUI; use crate::ui::UI; -use ezgui::{EventCtx, GfxCtx, Key, Text}; +use ezgui::{Color, EventCtx, GfxCtx, Key, Text}; +use map_model::raw_data::StableRoadID; +use map_model::Map; +use sim::{CarID, Sim}; +use std::collections::BTreeMap; pub struct ObjectDebugger { tooltip_key_held: bool, @@ -38,7 +44,7 @@ impl ObjectDebugger { if let Some(id) = self.selected { if ctx.input.contextual_action(Key::D, "debug") { - id.debug(&ui.primary.map, &ui.primary.sim, &ui.primary.draw_map); + dump_debug(id, &ui.primary.map, &ui.primary.sim, &ui.primary.draw_map); } } } @@ -46,7 +52,7 @@ impl ObjectDebugger { pub fn draw(&self, g: &mut GfxCtx, ui: &UI) { if self.tooltip_key_held { if let Some(id) = self.selected { - let txt = id.tooltip_lines(g, &ui.primary); + let txt = tooltip_lines(id, g, &ui.primary); g.draw_mouse_tooltip(&txt); } } @@ -64,3 +70,158 @@ impl ObjectDebugger { } } } + +fn dump_debug(id: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) { + match id { + ID::Road(id) => { + map.get_r(id).dump_debug(); + } + ID::Lane(id) => { + map.get_l(id).dump_debug(); + } + ID::Intersection(id) => { + map.get_i(id).dump_debug(); + sim.debug_intersection(id, map); + } + ID::Turn(id) => { + map.get_t(id).dump_debug(); + } + ID::Building(id) => { + map.get_b(id).dump_debug(); + let parked_cars = sim.get_parked_cars_by_owner(id); + println!( + "{} parked cars are owned by {}: {:?}", + parked_cars.len(), + id, + parked_cars + .iter() + .map(|p| p.vehicle.id) + .collect::>() + ); + } + ID::Car(id) => { + sim.debug_car(id); + } + ID::Pedestrian(id) => { + sim.debug_ped(id); + } + ID::ExtraShape(id) => { + let es = draw_map.get_es(id); + for (k, v) in &es.attributes { + println!("{} = {}", k, v); + } + println!("associated road: {:?}", es.road); + } + ID::BusStop(id) => { + map.get_bs(id).dump_debug(); + } + ID::Area(id) => { + map.get_a(id).dump_debug(); + } + ID::Trip(id) => { + sim.debug_trip(id); + } + } +} + +fn tooltip_lines(id: ID, g: &mut GfxCtx, ctx: &PerMapUI) -> Text { + let (map, sim, draw_map) = (&ctx.map, &ctx.sim, &ctx.draw_map); + let mut txt = Text::new(); + match id { + ID::Road(id) => { + let r = map.get_r(id); + txt.add_line(format!("{} (originally {}) is ", r.id, r.stable_id)); + txt.append(r.get_name(), Some(Color::CYAN)); + txt.add_line(format!("From OSM way {}", r.osm_way_id)); + } + ID::Lane(id) => { + let l = map.get_l(id); + let r = map.get_r(l.parent); + + txt.add_line(format!("{} is ", l.id)); + txt.append(r.get_name(), Some(Color::CYAN)); + txt.add_line(format!("From OSM way {}", r.osm_way_id)); + txt.add_line(format!( + "Parent {} (originally {}) points to {}", + r.id, r.stable_id, r.dst_i + )); + txt.add_line(format!( + "Lane is {} long, parent {} is {} long", + l.length(), + r.id, + r.center_pts.length() + )); + styled_kv(&mut txt, &r.osm_tags); + if l.is_parking() { + txt.add_line(format!("Has {} parking spots", l.number_parking_spots())); + } + if let Some(types) = l.get_turn_restrictions(r) { + txt.add_line(format!("Turn restriction for this lane: {:?}", types)); + } + } + ID::Intersection(id) => { + txt.add_line(id.to_string()); + let i = map.get_i(id); + txt.add_line(format!("Roads: {:?}", i.roads)); + txt.add_line(format!( + "Orig roads: {:?}", + i.roads + .iter() + .map(|r| map.get_r(*r).stable_id) + .collect::>() + )); + txt.add_line(format!("Originally {}", i.stable_id)); + } + ID::Turn(id) => { + let t = map.get_t(id); + txt.add_line(format!("{}", id)); + txt.add_line(format!("{:?}", t.turn_type)); + } + ID::Building(id) => { + let b = map.get_b(id); + txt.add_line(format!( + "Building #{:?} (from OSM way {})", + id, b.osm_way_id + )); + txt.add_line(format!( + "Dist along sidewalk: {}", + b.front_path.sidewalk.dist_along() + )); + styled_kv(&mut txt, &b.osm_tags); + } + ID::Car(id) => { + for line in sim.car_tooltip(id) { + txt.add_wrapped_line(&g.canvas, line); + } + } + ID::Pedestrian(id) => { + for line in sim.ped_tooltip(id) { + txt.add_wrapped_line(&g.canvas, line); + } + } + ID::ExtraShape(id) => { + styled_kv(&mut txt, &draw_map.get_es(id).attributes); + } + ID::BusStop(id) => { + txt.add_line(id.to_string()); + for r in map.get_all_bus_routes() { + if r.stops.contains(&id) { + txt.add_line(format!("- Route {}", r.name)); + } + } + } + ID::Area(id) => { + let a = map.get_a(id); + txt.add_line(format!("{} (from OSM {})", id, a.osm_id)); + styled_kv(&mut txt, &a.osm_tags); + } + ID::Trip(_) => {} + }; + txt +} + +fn styled_kv(txt: &mut Text, tags: &BTreeMap) { + for (k, v) in tags { + txt.push(format!("[red:{}] = [cyan:{}]", k, v)); + } +} diff --git a/editor/src/helpers.rs b/editor/src/helpers.rs index 96c6e04723..b2890691b3 100644 --- a/editor/src/helpers.rs +++ b/editor/src/helpers.rs @@ -1,12 +1,11 @@ -use crate::render::{DrawMap, ExtraShapeID}; +use crate::render::ExtraShapeID; use crate::ui::PerMapUI; use abstutil; -use ezgui::{Color, GfxCtx, Text}; +use ezgui::Color; use geom::Pt2D; -use map_model::raw_data::StableRoadID; -use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, Map, RoadID, TurnID}; +use map_model::{AreaID, BuildingID, BusStopID, IntersectionID, LaneID, RoadID, TurnID}; use serde_derive::{Deserialize, Serialize}; -use sim::{AgentID, CarID, GetDrawAgents, PedestrianID, Sim, TripID}; +use sim::{AgentID, CarID, GetDrawAgents, PedestrianID, TripID}; use std::collections::{BTreeMap, HashMap}; use std::io::Error; @@ -41,155 +40,6 @@ impl ID { } } - pub fn debug(&self, map: &Map, sim: &Sim, draw_map: &DrawMap) { - match *self { - ID::Road(id) => { - map.get_r(id).dump_debug(); - } - ID::Lane(id) => { - map.get_l(id).dump_debug(); - } - ID::Intersection(id) => { - map.get_i(id).dump_debug(); - sim.debug_intersection(id, map); - } - ID::Turn(id) => { - map.get_t(id).dump_debug(); - } - ID::Building(id) => { - map.get_b(id).dump_debug(); - let parked_cars = sim.get_parked_cars_by_owner(id); - println!( - "{} parked cars are owned by {}: {:?}", - parked_cars.len(), - id, - parked_cars - .iter() - .map(|p| p.vehicle.id) - .collect::>() - ); - } - ID::Car(id) => { - sim.debug_car(id); - } - ID::Pedestrian(id) => { - sim.debug_ped(id); - } - ID::ExtraShape(id) => { - let es = draw_map.get_es(id); - for (k, v) in &es.attributes { - println!("{} = {}", k, v); - } - println!("associated road: {:?}", es.road); - } - ID::BusStop(id) => { - map.get_bs(id).dump_debug(); - } - ID::Area(id) => { - map.get_a(id).dump_debug(); - } - ID::Trip(id) => { - sim.debug_trip(id); - } - } - } - - pub fn tooltip_lines(&self, g: &mut GfxCtx, ctx: &PerMapUI) -> Text { - let (map, sim, draw_map) = (&ctx.map, &ctx.sim, &ctx.draw_map); - let mut txt = Text::new(); - match *self { - ID::Road(id) => { - let r = map.get_r(id); - txt.add_line(format!("{} (originally {}) is ", r.id, r.stable_id)); - txt.append(r.get_name(), Some(Color::CYAN)); - txt.add_line(format!("From OSM way {}", r.osm_way_id)); - } - ID::Lane(id) => { - let l = map.get_l(id); - let r = map.get_r(l.parent); - - txt.add_line(format!("{} is ", l.id)); - txt.append(r.get_name(), Some(Color::CYAN)); - txt.add_line(format!("From OSM way {}", r.osm_way_id)); - txt.add_line(format!( - "Parent {} (originally {}) points to {}", - r.id, r.stable_id, r.dst_i - )); - txt.add_line(format!( - "Lane is {} long, parent {} is {} long", - l.length(), - r.id, - r.center_pts.length() - )); - styled_kv(&mut txt, &r.osm_tags); - if l.is_parking() { - txt.add_line(format!("Has {} parking spots", l.number_parking_spots())); - } - if let Some(types) = l.get_turn_restrictions(r) { - txt.add_line(format!("Turn restriction for this lane: {:?}", types)); - } - } - ID::Intersection(id) => { - txt.add_line(id.to_string()); - let i = map.get_i(id); - txt.add_line(format!("Roads: {:?}", i.roads)); - txt.add_line(format!( - "Orig roads: {:?}", - i.roads - .iter() - .map(|r| map.get_r(*r).stable_id) - .collect::>() - )); - txt.add_line(format!("Originally {}", i.stable_id)); - } - ID::Turn(id) => { - let t = map.get_t(id); - txt.add_line(format!("{}", id)); - txt.add_line(format!("{:?}", t.turn_type)); - } - ID::Building(id) => { - let b = map.get_b(id); - txt.add_line(format!( - "Building #{:?} (from OSM way {})", - id, b.osm_way_id - )); - txt.add_line(format!( - "Dist along sidewalk: {}", - b.front_path.sidewalk.dist_along() - )); - styled_kv(&mut txt, &b.osm_tags); - } - ID::Car(id) => { - for line in sim.car_tooltip(id) { - txt.add_wrapped_line(&g.canvas, line); - } - } - ID::Pedestrian(id) => { - for line in sim.ped_tooltip(id) { - txt.add_wrapped_line(&g.canvas, line); - } - } - ID::ExtraShape(id) => { - styled_kv(&mut txt, &draw_map.get_es(id).attributes); - } - ID::BusStop(id) => { - txt.add_line(id.to_string()); - for r in map.get_all_bus_routes() { - if r.stops.contains(&id) { - txt.add_line(format!("- Route {}", r.name)); - } - } - } - ID::Area(id) => { - let a = map.get_a(id); - txt.add_line(format!("{} (from OSM {})", id, a.osm_id)); - styled_kv(&mut txt, &a.osm_tags); - } - ID::Trip(_) => {} - }; - txt - } - pub fn canonical_point(&self, primary: &PerMapUI) -> Option { match *self { ID::Road(id) => primary.map.maybe_get_r(id).map(|r| r.center_pts.first_pt()), @@ -217,12 +67,6 @@ impl ID { } } -fn styled_kv(txt: &mut Text, tags: &BTreeMap) { - for (k, v) in tags { - txt.push(format!("[red:{}] = [cyan:{}]", k, v)); - } -} - pub struct ColorScheme { map: HashMap,