mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
specialize tooltip_lines to one plugin. solves the problem of not being able to look up objects in DrawMap
This commit is contained in:
parent
37c5a1ddb5
commit
7705289a62
@ -59,9 +59,9 @@ impl ID {
|
||||
ID::Pedestrian(id) => {
|
||||
sim.debug_ped(id);
|
||||
}
|
||||
ID::ExtraShape(_) => {
|
||||
for line in draw_map.get_obj(*self).tooltip_lines(map, sim).into_iter() {
|
||||
println!("{}", line);
|
||||
ID::ExtraShape(id) => {
|
||||
for (k, v) in &draw_map.get_es(id).attributes {
|
||||
println!("{} = {}", k, v);
|
||||
}
|
||||
}
|
||||
ID::Parcel(id) => {
|
||||
|
@ -1,7 +1,10 @@
|
||||
use ezgui::{GfxCtx, Text};
|
||||
use ezgui::{Color, GfxCtx, Text, TEXT_FG_COLOR};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use piston::input::Key;
|
||||
use plugins::{Plugin, PluginCtx};
|
||||
use render::DrawMap;
|
||||
use sim::Sim;
|
||||
|
||||
pub enum DebugObjectsState {
|
||||
Empty,
|
||||
@ -69,12 +72,93 @@ impl Plugin for DebugObjectsState {
|
||||
DebugObjectsState::Empty => {}
|
||||
DebugObjectsState::Selected(_) => {}
|
||||
DebugObjectsState::Tooltip(id) => {
|
||||
let mut txt = Text::new();
|
||||
for line in ctx.draw_map.get_obj(id).tooltip_lines(ctx.map, ctx.sim) {
|
||||
txt.add_line(line);
|
||||
}
|
||||
ctx.canvas.draw_mouse_tooltip(g, txt);
|
||||
ctx.canvas
|
||||
.draw_mouse_tooltip(g, tooltip_lines(id, ctx.map, ctx.sim, ctx.draw_map));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tooltip_lines(obj: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Text {
|
||||
let mut txt = Text::new();
|
||||
match obj {
|
||||
ID::Lane(id) => {
|
||||
let l = map.get_l(id);
|
||||
let r = map.get_r(l.parent);
|
||||
let i1 = map.get_source_intersection(id);
|
||||
let i2 = map.get_destination_intersection(id);
|
||||
|
||||
txt.add_line(format!(
|
||||
"{} is {}",
|
||||
l.id,
|
||||
r.osm_tags.get("name").unwrap_or(&"???".to_string())
|
||||
));
|
||||
txt.add_line(format!("From OSM way {}", r.osm_way_id));
|
||||
txt.add_line(format!("Parent {} points to {}", r.id, r.dst_i));
|
||||
txt.add_line(format!(
|
||||
"Lane goes from {} to {}",
|
||||
i1.elevation, i2.elevation
|
||||
));
|
||||
txt.add_line(format!("Lane is {} long", l.length()));
|
||||
for (k, v) in &r.osm_tags {
|
||||
txt.add_line(format!("{} = {}", k, v));
|
||||
}
|
||||
}
|
||||
ID::Intersection(id) => {
|
||||
txt.add_line(id.to_string());
|
||||
txt.add_line(format!("Roads: {:?}", map.get_i(id).roads));
|
||||
}
|
||||
ID::Turn(id) => {
|
||||
txt.add_line(format!("{}", id));
|
||||
txt.add_line(format!("Angle {}", map.get_t(id).turn_angle(map)));
|
||||
}
|
||||
ID::Building(id) => {
|
||||
let b = map.get_b(id);
|
||||
txt.add_line(format!(
|
||||
"Building #{:?} (from OSM way {})",
|
||||
id, b.osm_way_id
|
||||
));
|
||||
for (k, v) in &b.osm_tags {
|
||||
txt.add_styled_line(k.to_string(), Color::RED, None);
|
||||
txt.append(" = ".to_string(), TEXT_FG_COLOR, None);
|
||||
txt.append(v.to_string(), Color::BLUE, None);
|
||||
}
|
||||
}
|
||||
ID::Car(id) => {
|
||||
for line in sim.car_tooltip(id) {
|
||||
txt.add_line(line);
|
||||
}
|
||||
}
|
||||
ID::Pedestrian(id) => {
|
||||
for line in sim.ped_tooltip(id) {
|
||||
txt.add_line(line);
|
||||
}
|
||||
}
|
||||
ID::ExtraShape(id) => {
|
||||
for (k, v) in &draw_map.get_es(id).attributes {
|
||||
// Make interesting atributes easier to spot
|
||||
if k == "TEXT" {
|
||||
// TODO Using color
|
||||
txt.add_line(format!("*** {} = {}", k, v));
|
||||
} else {
|
||||
txt.add_line(format!("{} = {}", k, v));
|
||||
}
|
||||
}
|
||||
}
|
||||
ID::Parcel(id) => {
|
||||
txt.add_line(id.to_string());
|
||||
}
|
||||
ID::BusStop(id) => {
|
||||
txt.add_line(id.to_string());
|
||||
}
|
||||
ID::Area(id) => {
|
||||
let a = map.get_a(id);
|
||||
txt.add_line(format!("{} (from OSM way {})", id, a.osm_way_id));
|
||||
for (k, v) in &a.osm_tags {
|
||||
txt.add_line(format!("{} = {}", k, v));
|
||||
}
|
||||
}
|
||||
ID::Trip(_) => {}
|
||||
};
|
||||
txt
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Bounds, Polygon, Pt2D};
|
||||
use map_model::{Area, AreaID, AreaType, Map};
|
||||
use map_model::{Area, AreaID, AreaType};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::Sim;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrawArea {
|
||||
@ -43,13 +42,4 @@ impl Renderable for DrawArea {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.fill_polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
let a = map.get_a(self.id);
|
||||
let mut lines = vec![format!("{} (from OSM way {})", self.id, a.osm_way_id)];
|
||||
for (k, v) in &a.osm_tags {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Angle, Bounds, PolyLine, Polygon, Pt2D};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::{CarID, CarState, DrawCarInput, Sim};
|
||||
use sim::{CarID, CarState, DrawCarInput};
|
||||
|
||||
const BIKE_WIDTH: f64 = 0.8;
|
||||
|
||||
@ -73,10 +72,6 @@ impl Renderable for DrawBike {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, sim: &Sim) -> Vec<String> {
|
||||
sim.car_tooltip(self.id)
|
||||
}
|
||||
}
|
||||
|
||||
fn thick_line_from_angle(thickness: f64, line_length: f64, pt: Pt2D, angle: Angle) -> Polygon {
|
||||
|
@ -3,10 +3,9 @@
|
||||
use dimensioned::si;
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Bounds, Line, Polygon, Pt2D};
|
||||
use map_model::{Building, BuildingID, Map, LANE_THICKNESS};
|
||||
use map_model::{Building, BuildingID, LANE_THICKNESS};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::Sim;
|
||||
|
||||
pub struct DrawBuilding {
|
||||
pub id: BuildingID,
|
||||
@ -64,16 +63,4 @@ impl Renderable for DrawBuilding {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.fill_polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
let b = map.get_b(self.id);
|
||||
let mut lines = vec![format!(
|
||||
"Building #{:?} (from OSM way {})",
|
||||
self.id, b.osm_way_id
|
||||
)];
|
||||
for (k, v) in &b.osm_tags {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ use geom::{Bounds, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{BusStop, BusStopID, Map, LANE_THICKNESS};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::Sim;
|
||||
|
||||
pub struct DrawBusStop {
|
||||
pub id: BusStopID,
|
||||
@ -57,8 +56,4 @@ impl Renderable for DrawBusStop {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
vec![self.id.to_string()]
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use geom::{Angle, Bounds, Line, PolyLine, Polygon, Pt2D};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::{CarID, CarState, DrawCarInput, Sim};
|
||||
use sim::{CarID, CarState, DrawCarInput};
|
||||
|
||||
const CAR_WIDTH: f64 = 2.0;
|
||||
|
||||
@ -130,10 +130,6 @@ impl Renderable for DrawCar {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.body_polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, sim: &Sim) -> Vec<String> {
|
||||
sim.car_tooltip(self.id)
|
||||
}
|
||||
}
|
||||
|
||||
fn thick_line_from_angle(thickness: f64, line_length: f64, pt: Pt2D, angle: Angle) -> Polygon {
|
||||
|
@ -2,10 +2,8 @@ use dimensioned::si;
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Bounds, Circle, Polygon, Pt2D};
|
||||
use kml::{ExtraShape, ExtraShapeGeom, ExtraShapeID};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_SHAPE_THICKNESS};
|
||||
use sim::Sim;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -18,7 +16,7 @@ enum Shape {
|
||||
pub struct DrawExtraShape {
|
||||
pub id: ExtraShapeID,
|
||||
shape: Shape,
|
||||
attributes: BTreeMap<String, String>,
|
||||
pub attributes: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl DrawExtraShape {
|
||||
@ -74,19 +72,6 @@ impl Renderable for DrawExtraShape {
|
||||
Shape::Circle(ref c) => c.contains_pt(pt),
|
||||
}
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
let mut lines = Vec::new();
|
||||
for (k, v) in &self.attributes {
|
||||
// Make interesting atributes easier to spot
|
||||
if k == "TEXT" {
|
||||
lines.push(format!("*** {} = {}", k, v));
|
||||
} else {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
}
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
||||
// See https://www.seattle.gov/Documents/Departments/SDOT/GIS/Sidewalks_OD.pdf
|
||||
|
@ -6,7 +6,6 @@ use geom::{Angle, Bounds, Circle, Line, Polygon, Pt2D};
|
||||
use map_model::{Intersection, IntersectionID, IntersectionType, Map, TurnType, LANE_THICKNESS};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::Sim;
|
||||
use std::f64;
|
||||
|
||||
const CROSSWALK_LINE_THICKNESS: f64 = 0.25;
|
||||
@ -129,13 +128,6 @@ impl Renderable for DrawIntersection {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
vec![
|
||||
self.id.to_string(),
|
||||
format!("Roads: {:?}", map.get_i(self.id).roads),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_crosswalks(i: IntersectionID, map: &Map) -> Vec<Vec<Line>> {
|
||||
|
@ -10,7 +10,6 @@ use map_model::{
|
||||
};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable, BIG_ARROW_THICKNESS, PARCEL_BOUNDARY_THICKNESS};
|
||||
use sim::Sim;
|
||||
|
||||
const MIN_ZOOM_FOR_LANE_MARKERS: f64 = 5.0;
|
||||
|
||||
@ -156,29 +155,6 @@ impl Renderable for DrawLane {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
let l = map.get_l(self.id);
|
||||
let r = map.get_r(l.parent);
|
||||
let i1 = map.get_source_intersection(self.id);
|
||||
let i2 = map.get_destination_intersection(self.id);
|
||||
|
||||
let mut lines = vec![
|
||||
format!(
|
||||
"{} is {}",
|
||||
l.id,
|
||||
r.osm_tags.get("name").unwrap_or(&"???".to_string())
|
||||
),
|
||||
format!("From OSM way {}", r.osm_way_id),
|
||||
format!("Parent {} points to {}", r.id, r.dst_i),
|
||||
format!("Lane goes from {} to {}", i1.elevation, i2.elevation),
|
||||
format!("Lane is {} long", l.length()),
|
||||
];
|
||||
for (k, v) in &r.osm_tags {
|
||||
lines.push(format!("{} = {}", k, v));
|
||||
}
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this always does it at pt1
|
||||
|
@ -174,22 +174,6 @@ impl DrawMap {
|
||||
self.turns.insert(id, draw_turn);
|
||||
}
|
||||
|
||||
pub fn get_obj(&self, id: ID) -> Box<&Renderable> {
|
||||
match id {
|
||||
ID::Lane(id) => Box::new(self.get_l(id)),
|
||||
ID::Building(id) => Box::new(self.get_b(id)),
|
||||
ID::Intersection(id) => Box::new(self.get_i(id)),
|
||||
ID::Turn(id) => Box::new(self.get_t(id)),
|
||||
ID::ExtraShape(id) => Box::new(self.get_es(id)),
|
||||
ID::BusStop(id) => Box::new(self.get_bs(id)),
|
||||
ID::Parcel(id) => Box::new(self.get_p(id)),
|
||||
ID::Area(id) => Box::new(self.get_a(id)),
|
||||
ID::Car(_) | ID::Pedestrian(_) | ID::Trip(_) => {
|
||||
panic!("get_obj doesn't work for dynamic {:?}", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The alt to these is implementing std::ops::Index, but that's way more verbose!
|
||||
pub fn get_l(&self, id: LaneID) -> &DrawLane {
|
||||
&self.lanes[id.0]
|
||||
|
@ -24,7 +24,7 @@ pub use render::lane::DrawLane;
|
||||
pub use render::map::DrawMap;
|
||||
pub use render::pedestrian::DrawPedestrian;
|
||||
pub use render::turn::DrawTurn;
|
||||
use sim::{DrawCarInput, Sim, VehicleType};
|
||||
use sim::{DrawCarInput, VehicleType};
|
||||
use std::f64;
|
||||
|
||||
// These are all in meters
|
||||
@ -39,13 +39,12 @@ const TURN_ICON_ARROW_TIP_LENGTH: f64 = BIG_ARROW_TIP_LENGTH * 0.8;
|
||||
const TURN_ICON_ARROW_LENGTH: f64 = 2.0;
|
||||
|
||||
// Does something belong here or as a method on ID? If it ONLY applies to renderable things, then
|
||||
// here. For example, trips aren't drawn, so they don't need tooltip_lines.
|
||||
// here. For example, trips aren't drawn, so it's meaningless to ask what their bounding box is.
|
||||
pub trait Renderable {
|
||||
fn get_id(&self) -> ID;
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx);
|
||||
fn get_bounds(&self) -> Bounds;
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool;
|
||||
fn tooltip_lines(&self, map: &Map, sim: &Sim) -> Vec<String>;
|
||||
}
|
||||
|
||||
pub struct RenderOptions {
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use geom::{Bounds, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{Map, Parcel, ParcelID};
|
||||
use map_model::{Parcel, ParcelID};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
use sim::Sim;
|
||||
|
||||
const COLORS: [Color; 14] = [
|
||||
// TODO these are awful choices
|
||||
@ -70,8 +69,4 @@ impl Renderable for DrawParcel {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.fill_polygon.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
vec![self.id.to_string()]
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use geom::{Bounds, Circle, Line, Pt2D};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::{DrawPedestrianInput, PedestrianID, Sim};
|
||||
use sim::{DrawPedestrianInput, PedestrianID};
|
||||
|
||||
const RADIUS: f64 = 1.0;
|
||||
|
||||
@ -71,8 +71,4 @@ impl Renderable for DrawPedestrian {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.circle.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, _map: &Map, sim: &Sim) -> Vec<String> {
|
||||
sim.ped_tooltip(self.id)
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use render::{
|
||||
RenderOptions, Renderable, BIG_ARROW_THICKNESS, BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH,
|
||||
TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH,
|
||||
};
|
||||
use sim::Sim;
|
||||
use std::f64;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -78,11 +77,4 @@ impl Renderable for DrawTurn {
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
self.icon_circle.contains_pt(pt)
|
||||
}
|
||||
|
||||
fn tooltip_lines(&self, map: &Map, _sim: &Sim) -> Vec<String> {
|
||||
vec![
|
||||
format!("{}", self.id),
|
||||
format!("Angle {}", map.get_t(self.id).turn_angle(map)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ use opengl_graphics::{GlGraphics, Texture};
|
||||
use piston::input::Key;
|
||||
pub use runner::{run, GUI};
|
||||
use std::fmt;
|
||||
pub use text::Text;
|
||||
pub use text::{Text, TEXT_FG_COLOR};
|
||||
pub use text_box::TextBox;
|
||||
pub use wizard::{Wizard, WrappedWizard};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user