mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
label synthetic intersections
This commit is contained in:
parent
dbfd410b0a
commit
e76dede109
@ -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"
|
||||
}
|
||||
]
|
||||
],
|
||||
|
@ -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 @@
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ pub struct Intersection {
|
||||
pub elevation: si::Meter<f64>,
|
||||
|
||||
pub intersection_type: IntersectionType,
|
||||
pub label: Option<String>,
|
||||
|
||||
// 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?
|
||||
|
@ -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()) {
|
||||
|
@ -88,6 +88,7 @@ pub struct Intersection {
|
||||
pub elevation: si::Meter<f64>,
|
||||
// A raw Intersection can be forced into being a Border.
|
||||
pub intersection_type: IntersectionType,
|
||||
pub label: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
|
||||
|
@ -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 => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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<Text> 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<Text> 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<Text> 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);
|
||||
|
@ -45,6 +45,7 @@ pub struct Model {
|
||||
pub struct Intersection {
|
||||
center: Pt2D,
|
||||
intersection_type: IntersectionType,
|
||||
label: Option<String>,
|
||||
}
|
||||
|
||||
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<String> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user