cant delete roads involving turn restrictions

This commit is contained in:
Dustin Carlino 2019-09-25 10:50:06 -07:00
parent ffc8050623
commit cfa21d4cc3
3 changed files with 27 additions and 3 deletions

View File

@ -400,5 +400,5 @@ impl GUI for UI {
}
fn main() {
ezgui::run("Synthetic map editor", 1024.0, 768.0, |ctx| UI::new(ctx));
ezgui::run("Synthetic map editor", 1800.0, 800.0, |ctx| UI::new(ctx));
}

View File

@ -455,8 +455,15 @@ impl Model {
pub fn delete_r(&mut self, id: StableRoadID) {
assert!(self.showing_pts != Some(id));
self.road_deleted(id);
self.map.delete_road(id, &mut self.fixes);
if self.map.can_delete_road(id) {
self.road_deleted(id);
self.map.delete_road(id, &mut self.fixes);
} else {
println!(
"Can't delete {}, it must have turn restriction from/to it",
id
);
}
}
pub fn get_road_spec(&self, id: StableRoadID) -> String {

View File

@ -225,7 +225,24 @@ impl RawMap {
// Mutations
impl RawMap {
pub fn can_delete_road(&self, r: StableRoadID) -> bool {
if !self.get_turn_restrictions(r).is_empty() {
return false;
}
// Brute force search the other direction
let osm_id = self.roads[&r].orig_id.osm_way_id;
for restrictions in self.turn_restrictions.values() {
for (_, to) in restrictions {
if *to == osm_id {
return false;
}
}
}
true
}
pub fn delete_road(&mut self, r: StableRoadID, fixes: &mut MapFixes) {
assert!(self.can_delete_road(r));
let road = self.roads.remove(&r).unwrap();
if !road.synthetic() {
fixes.delete_roads.push(road.orig_id);