2019-04-29 19:56:01 +03:00
|
|
|
use crate::helpers::ID;
|
2019-07-04 01:18:32 +03:00
|
|
|
use crate::render::DrawMap;
|
2019-04-26 02:40:26 +03:00
|
|
|
use crate::ui::UI;
|
2019-10-14 23:42:22 +03:00
|
|
|
use ezgui::{EventCtx, GfxCtx, Key, Line, Text};
|
2019-12-13 03:09:01 +03:00
|
|
|
use map_model::{Map, PathConstraints};
|
2019-11-30 00:15:10 +03:00
|
|
|
use sim::{AgentID, CarID, Sim};
|
2018-09-13 19:59:49 +03:00
|
|
|
|
2019-04-26 02:40:26 +03:00
|
|
|
pub struct ObjectDebugger {
|
2019-02-19 02:21:43 +03:00
|
|
|
debug_tooltip_key_held: bool,
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 02:40:26 +03:00
|
|
|
impl ObjectDebugger {
|
|
|
|
pub fn new() -> ObjectDebugger {
|
|
|
|
ObjectDebugger {
|
2019-02-19 02:21:43 +03:00
|
|
|
debug_tooltip_key_held: false,
|
2018-12-06 07:00:58 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
2018-10-22 06:28:51 +03:00
|
|
|
|
2019-04-26 02:40:26 +03:00
|
|
|
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI) {
|
2019-02-19 02:21:43 +03:00
|
|
|
if self.debug_tooltip_key_held {
|
|
|
|
self.debug_tooltip_key_held = !ctx.input.key_released(Key::RightControl);
|
|
|
|
} else {
|
|
|
|
self.debug_tooltip_key_held = ctx
|
|
|
|
.input
|
|
|
|
.unimportant_key_pressed(Key::RightControl, "hold to show debug tooltips");
|
2018-12-06 07:00:58 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
|
2019-10-14 23:42:22 +03:00
|
|
|
if let Some(ref id) = ui.primary.current_selection {
|
2019-12-12 02:04:32 +03:00
|
|
|
if ui.per_obj.action(ctx, Key::D, "debug") {
|
2019-08-15 01:09:54 +03:00
|
|
|
dump_debug(
|
|
|
|
id.clone(),
|
|
|
|
&ui.primary.map,
|
|
|
|
&ui.primary.sim,
|
|
|
|
&ui.primary.draw_map,
|
|
|
|
);
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 19:43:48 +03:00
|
|
|
|
2019-04-26 02:40:26 +03:00
|
|
|
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
2019-02-19 02:21:43 +03:00
|
|
|
if self.debug_tooltip_key_held {
|
|
|
|
if let Some(pt) = g.canvas.get_cursor_in_map_space() {
|
2019-04-29 19:27:43 +03:00
|
|
|
if let Some(gps) = pt.to_gps(ui.primary.map.get_gps_bounds()) {
|
2019-12-14 02:45:23 +03:00
|
|
|
let mut txt = Text::new().with_bg();
|
2019-09-06 23:58:04 +03:00
|
|
|
txt.add(Line(pt.to_string()));
|
|
|
|
txt.add(Line(gps.to_string()));
|
2019-10-30 02:36:19 +03:00
|
|
|
txt.add(Line(format!("{:?}", g.canvas.get_cursor_in_screen_space())));
|
2019-09-06 23:58:04 +03:00
|
|
|
txt.add(Line(format!("zoom: {}", g.canvas.cam_zoom)));
|
2019-04-22 23:19:36 +03:00
|
|
|
g.draw_mouse_tooltip(&txt);
|
2019-02-19 02:21:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-22 19:43:48 +03:00
|
|
|
}
|
2018-09-13 19:59:49 +03:00
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
|
|
|
|
fn dump_debug(id: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) {
|
|
|
|
match id {
|
|
|
|
ID::Road(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
println!("{}", abstutil::to_json(map.get_r(id)));
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Lane(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
let l = map.get_l(id);
|
|
|
|
println!("{}", abstutil::to_json(l));
|
|
|
|
|
2019-08-12 22:51:22 +03:00
|
|
|
sim.debug_lane(id);
|
2019-12-13 03:09:01 +03:00
|
|
|
|
|
|
|
let r = map.get_parent(id);
|
|
|
|
println!("Parent {} ({}) points to {}", r.id, r.orig_id, r.dst_i);
|
|
|
|
|
|
|
|
if l.lane_type.is_for_moving_vehicles() {
|
|
|
|
for constraint in vec![
|
|
|
|
PathConstraints::Car,
|
|
|
|
PathConstraints::Bike,
|
|
|
|
PathConstraints::Bus,
|
|
|
|
] {
|
|
|
|
if constraint.can_use(l, map) {
|
|
|
|
println!(
|
|
|
|
"Cost for {:?}: {}",
|
|
|
|
constraint,
|
|
|
|
l.get_max_cost(constraint, map)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Intersection(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
let i = map.get_i(id);
|
|
|
|
println!("{}", abstutil::to_json(i));
|
|
|
|
|
2019-07-04 01:18:32 +03:00
|
|
|
sim.debug_intersection(id, map);
|
2019-12-13 03:09:01 +03:00
|
|
|
|
|
|
|
println!("{} connecting:", i.orig_id);
|
|
|
|
for r in &i.roads {
|
|
|
|
let road = map.get_r(*r);
|
|
|
|
println!("- {} = {}", road.id, road.orig_id);
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Turn(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
println!("{}", abstutil::to_json(map.get_t(id)));
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Building(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
println!("{}", abstutil::to_json(map.get_b(id)));
|
2019-09-02 07:25:31 +03:00
|
|
|
for (cars, descr) in vec![
|
|
|
|
(
|
|
|
|
sim.get_parked_cars_by_owner(id),
|
|
|
|
format!("currently parked cars are owned by {}", id),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
sim.get_offstreet_parked_cars(id),
|
|
|
|
format!("cars are parked inside {}", id),
|
|
|
|
),
|
|
|
|
] {
|
|
|
|
println!(
|
|
|
|
"{} {}: {:?}",
|
|
|
|
cars.len(),
|
|
|
|
descr,
|
|
|
|
cars.iter().map(|p| p.vehicle.id).collect::<Vec<CarID>>()
|
|
|
|
);
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Car(id) => {
|
|
|
|
sim.debug_car(id);
|
2019-11-30 00:15:10 +03:00
|
|
|
if let Some(t) = sim.agent_to_trip(AgentID::Car(id)) {
|
|
|
|
println!("Trip log for {}", t);
|
2019-12-02 23:15:38 +03:00
|
|
|
for p in sim.get_analytics().get_trip_phases(t, map) {
|
|
|
|
println!("- {}", p.describe(sim.time()));
|
2019-11-30 00:15:10 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Pedestrian(id) => {
|
|
|
|
sim.debug_ped(id);
|
2019-11-30 00:15:10 +03:00
|
|
|
if let Some(t) = sim.agent_to_trip(AgentID::Pedestrian(id)) {
|
|
|
|
println!("Trip log for {}", t);
|
2019-12-02 23:15:38 +03:00
|
|
|
for p in sim.get_analytics().get_trip_phases(t, map) {
|
|
|
|
println!("- {}", p.describe(sim.time()));
|
2019-11-30 00:15:10 +03:00
|
|
|
}
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
2019-08-15 01:29:02 +03:00
|
|
|
ID::PedCrowd(members) => {
|
|
|
|
println!("Crowd with {} members", members.len());
|
|
|
|
for p in members {
|
|
|
|
sim.debug_ped(p);
|
|
|
|
}
|
|
|
|
}
|
2019-07-04 01:18:32 +03:00
|
|
|
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) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
println!("{}", abstutil::to_json(map.get_bs(id)));
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
ID::Area(id) => {
|
2019-12-13 03:09:01 +03:00
|
|
|
println!("{}", abstutil::to_json(map.get_a(id)));
|
2019-07-04 01:18:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|