diff --git a/data/synthetic_maps/ban_left_turn.json b/data/synthetic_maps/ban_left_turn.json index 89a5871786..5e25cf5af0 100644 --- a/data/synthetic_maps/ban_left_turn.json +++ b/data/synthetic_maps/ban_left_turn.json @@ -8,7 +8,8 @@ "x": 375.2584876887879, "y": 394.4733648122756 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": "west" } ], [ @@ -18,7 +19,8 @@ "x": 426.5473937988281, "y": 394.67230224609377 }, - "intersection_type": "TrafficSignal" + "intersection_type": "TrafficSignal", + "label": null } ], [ @@ -28,7 +30,8 @@ "x": 426.9548681897562, "y": 338.6898394428313 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": null } ], [ @@ -38,7 +41,8 @@ "x": 481.2515387041076, "y": 338.6877104503858 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": "east" } ], [ @@ -48,7 +52,8 @@ "x": 426.9279815253348, "y": 456.09920803179929 }, - "intersection_type": "Border" + "intersection_type": "Border", + "label": "south" } ], [ @@ -58,7 +63,8 @@ "x": 427.35826112518097, "y": 285.7304272008598 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": "north" } ] ], diff --git a/data/synthetic_maps/parking_test.json b/data/synthetic_maps/parking_test.json index be645a8b85..57bc8116e7 100644 --- a/data/synthetic_maps/parking_test.json +++ b/data/synthetic_maps/parking_test.json @@ -8,7 +8,8 @@ "x": 288.5454406738281, "y": 486.2385864257813 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": null } ], [ @@ -18,7 +19,8 @@ "x": 512.0357055664063, "y": 486.63079833984377 }, - "intersection_type": "StopSign" + "intersection_type": "StopSign", + "label": null } ] ], @@ -70,4 +72,4 @@ } ] ] -} +} \ No newline at end of file diff --git a/map_model/src/intersection.rs b/map_model/src/intersection.rs index 81ca3d23bf..0904c035fc 100644 --- a/map_model/src/intersection.rs +++ b/map_model/src/intersection.rs @@ -36,6 +36,7 @@ pub struct Intersection { pub elevation: si::Meter, pub intersection_type: IntersectionType, + pub label: Option, // Note that a lane may belong to both incoming_lanes and outgoing_lanes. // TODO narrow down when and why. is it just sidewalks in weird cases? diff --git a/map_model/src/map.rs b/map_model/src/map.rs index e5decbd6a4..ad8bc9a69a 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -109,6 +109,7 @@ impl Map { elevation: i.elevation, // Might change later intersection_type: i.intersection_type, + label: i.label.clone(), incoming_lanes: Vec::new(), outgoing_lanes: Vec::new(), roads: BTreeSet::new(), @@ -626,6 +627,15 @@ impl Map { } // TODO reconsider names, or put somewhere else? + pub fn intersection(&self, label: &str) -> IntersectionID { + for i in &self.intersections { + if i.label == Some(label.to_string()) { + return i.id; + } + } + panic!("No intersection has label {}", label); + } + pub fn bldg(&self, label: &str) -> BuildingID { for b in &self.buildings { if b.osm_tags.get("label") == Some(&label.to_string()) { diff --git a/map_model/src/raw_data.rs b/map_model/src/raw_data.rs index 4ba9b55c22..848e3ecfbd 100644 --- a/map_model/src/raw_data.rs +++ b/map_model/src/raw_data.rs @@ -88,6 +88,7 @@ pub struct Intersection { pub elevation: si::Meter, // A raw Intersection can be forced into being a Border. pub intersection_type: IntersectionType, + pub label: Option, } #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] diff --git a/sim/src/intersections.rs b/sim/src/intersections.rs index 46c211bfa3..5ab383941e 100644 --- a/sim/src/intersections.rs +++ b/sim/src/intersections.rs @@ -152,9 +152,7 @@ impl IntersectionSimState { p.debug = true; println!("{}", abstutil::to_json(map.get_traffic_signal(id))); } - IntersectionPolicy::Border => { - println!("{} has no IntersectionPolicy since it's a border", id); - } + IntersectionPolicy::Border => {} }; } } diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index cb469147ea..b91effbdd1 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -20,6 +20,7 @@ enum State { MovingBuilding(BuildingID), LabelingBuilding(BuildingID, Wizard), LabelingRoad((RoadID, Direction), Wizard), + LabelingIntersection(IntersectionID, Wizard), CreatingRoad(IntersectionID), EditingRoad(RoadID, Wizard), SavingModel(Wizard), @@ -80,6 +81,17 @@ impl GUI for UI { self.state = State::Viewing; } } + State::LabelingIntersection(id, ref mut wizard) => { + if let Some(label) = wizard.wrap(&mut input).input_string_prefilled( + "Label the intersection", + self.model.get_i_label(id).unwrap_or_else(String::new), + ) { + self.model.set_i_label(id, label); + self.state = State::Viewing; + } else if wizard.aborted() { + self.state = State::Viewing; + } + } State::CreatingRoad(i1) => { if input.key_pressed(Key::Escape, "stop defining road") { self.state = State::Viewing; @@ -124,6 +136,8 @@ impl GUI for UI { self.model.remove_i(i); } else if input.key_pressed(Key::T, "toggle intersection type") { self.model.toggle_i_type(i); + } else if input.key_pressed(Key::L, "label intersection") { + self.state = State::LabelingIntersection(i, Wizard::new()); } } else if let Some(b) = self.model.mouseover_building(cursor) { if input.key_pressed(Key::LCtrl, "move building") { @@ -185,6 +199,7 @@ impl GUI for UI { } State::LabelingBuilding(_, ref wizard) | State::LabelingRoad(_, ref wizard) + | State::LabelingIntersection(_, ref wizard) | State::EditingRoad(_, ref wizard) | State::SavingModel(ref wizard) => { wizard.draw(g, &self.canvas); diff --git a/synthetic/src/model.rs b/synthetic/src/model.rs index 8f33ad5f98..50f82d6530 100644 --- a/synthetic/src/model.rs +++ b/synthetic/src/model.rs @@ -45,6 +45,7 @@ pub struct Model { pub struct Intersection { center: Pt2D, intersection_type: IntersectionType, + label: Option, } impl Intersection { @@ -200,6 +201,12 @@ impl Model { } }; g.draw_circle(color, &i.circle()); + + if let Some(ref label) = i.label { + let mut txt = Text::new(); + txt.add_line(label.to_string()); + canvas.draw_text_at(g, txt, i.center); + } } for (id, b) in &self.buildings { @@ -261,6 +268,7 @@ impl Model { point: pt(i.center), elevation: 0.0 * si::M, intersection_type: i.intersection_type, + label: i.label.clone(), }); } @@ -294,6 +302,7 @@ impl Model { Intersection { center, intersection_type: IntersectionType::StopSign, + label: None, }, ); } @@ -302,6 +311,14 @@ impl Model { self.intersections.get_mut(&id).unwrap().center = center; } + pub fn set_i_label(&mut self, id: IntersectionID, label: String) { + self.intersections.get_mut(&id).unwrap().label = Some(label); + } + + pub fn get_i_label(&self, id: IntersectionID) -> Option { + self.intersections[&id].label.clone() + } + pub fn toggle_i_type(&mut self, id: IntersectionID) { let i = self.intersections.get_mut(&id).unwrap(); i.intersection_type = match i.intersection_type {