store name in raw map; simplifies some plumbing elsewhere

This commit is contained in:
Dustin Carlino 2019-09-17 10:27:32 -07:00
parent 18baf7ae49
commit 0e406afe0f
6 changed files with 25 additions and 17 deletions

View File

@ -77,8 +77,7 @@ pub fn convert(flags: &Flags, timer: &mut abstutil::Timer) -> raw_data::Map {
if !flags.neighborhoods.is_empty() { if !flags.neighborhoods.is_empty() {
timer.start("convert neighborhood polygons"); timer.start("convert neighborhood polygons");
let map_name = abstutil::basename(&flags.output); neighborhoods::convert(&flags.neighborhoods, map.name.clone(), &map.gps_bounds);
neighborhoods::convert(&flags.neighborhoods, map_name, &map.gps_bounds);
timer.stop("convert neighborhood polygons"); timer.stop("convert neighborhood polygons");
} }

View File

@ -28,7 +28,7 @@ pub fn extract_osm(
done(timer); done(timer);
let mut map = if maybe_clip_path.is_empty() { let mut map = if maybe_clip_path.is_empty() {
let mut m = raw_data::Map::blank(); let mut m = raw_data::Map::blank(abstutil::basename(osm_path));
for node in doc.nodes.values() { for node in doc.nodes.values() {
m.gps_bounds.update(LonLat::new(node.lon, node.lat)); m.gps_bounds.update(LonLat::new(node.lon, node.lat));
} }
@ -344,7 +344,7 @@ fn read_osmosis_polygon(path: &str) -> raw_data::Map {
gps_bounds.update(pt); gps_bounds.update(pt);
} }
let mut map = raw_data::Map::blank(); let mut map = raw_data::Map::blank(abstutil::basename(path));
map.boundary_polygon = Polygon::new(&gps_bounds.must_convert(&pts)); map.boundary_polygon = Polygon::new(&gps_bounds.must_convert(&pts));
map.gps_bounds = gps_bounds; map.gps_bounds = gps_bounds;
map map

View File

@ -50,8 +50,12 @@ impl UI {
fn new(filename: &str, ctx: &mut EventCtx) -> UI { fn new(filename: &str, ctx: &mut EventCtx) -> UI {
ctx.loading_screen(&format!("load {}", filename), |ctx, mut timer| { ctx.loading_screen(&format!("load {}", filename), |ctx, mut timer| {
let raw: Map = abstutil::read_binary(filename, &mut timer).unwrap(); let raw: Map = abstutil::read_binary(filename, &mut timer).unwrap();
let map_name = abstutil::basename(filename); let mut data = InitialMap::new(
let mut data = InitialMap::new(map_name, &raw, &raw.gps_bounds.to_bounds(), &mut timer); raw.name.clone(),
&raw,
&raw.gps_bounds.to_bounds(),
&mut timer,
);
let hints = Hints::load(); let hints = Hints::load();
data.apply_hints(&hints, &raw, &mut timer); data.apply_hints(&hints, &raw, &mut timer);
@ -121,7 +125,10 @@ impl GUI for UI {
let r2_tags = &self.raw.roads[iter.next().unwrap()].osm_tags; let r2_tags = &self.raw.roads[iter.next().unwrap()].osm_tags;
for (k, v1) in r1_tags { for (k, v1) in r1_tags {
let v2 = r2_tags.get(k).cloned().unwrap_or("MISSING".to_string()); let v2 = r2_tags
.get(k)
.cloned()
.unwrap_or_else(|| "MISSING".to_string());
if *v1 != v2 { if *v1 != v2 {
txt.add_appended(vec![ txt.add_appended(vec![
Line(k).fg(Color::RED), Line(k).fg(Color::RED),

View File

@ -55,7 +55,7 @@ impl Map {
data.apply_fixes(&raw_data::MapFixes::load(), timer); data.apply_fixes(&raw_data::MapFixes::load(), timer);
// Do this after applying fixes, which might split off pieces of the map. // Do this after applying fixes, which might split off pieces of the map.
make::remove_disconnected_roads(&mut data, timer); make::remove_disconnected_roads(&mut data, timer);
Ok(Map::create_from_raw(abstutil::basename(path), data, timer)) Ok(Map::create_from_raw(data, timer))
} }
// Just for temporary std::mem::replace tricks. // Just for temporary std::mem::replace tricks.
@ -86,11 +86,11 @@ impl Map {
} }
} }
pub fn create_from_raw(name: String, data: raw_data::Map, timer: &mut Timer) -> Map { fn create_from_raw(data: raw_data::Map, timer: &mut Timer) -> Map {
timer.start("raw_map to InitialMap"); timer.start("raw_map to InitialMap");
let gps_bounds = data.gps_bounds.clone(); let gps_bounds = data.gps_bounds.clone();
let bounds = gps_bounds.to_bounds(); let bounds = gps_bounds.to_bounds();
let mut initial_map = make::InitialMap::new(name.clone(), &data, &bounds, timer); let mut initial_map = make::InitialMap::new(data.name.clone(), &data, &bounds, timer);
let hints = raw_data::Hints::load(); let hints = raw_data::Hints::load();
initial_map.apply_hints(&hints, &data, timer); initial_map.apply_hints(&hints, &data, timer);
timer.stop("raw_map to InitialMap"); timer.stop("raw_map to InitialMap");
@ -117,8 +117,8 @@ impl Map {
turn_lookup: half_map.turn_lookup, turn_lookup: half_map.turn_lookup,
pathfinder: None, pathfinder: None,
pathfinder_dirty: false, pathfinder_dirty: false,
name: name.clone(), name: data.name.clone(),
edits: MapEdits::new(name), edits: MapEdits::new(data.name),
}; };
// Extra setup that's annoying to do as HalfMap, since we want to pass around a Map. // Extra setup that's annoying to do as HalfMap, since we want to pass around a Map.

View File

@ -27,6 +27,7 @@ impl fmt::Display for StableIntersectionID {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Map { pub struct Map {
pub name: String,
pub roads: BTreeMap<StableRoadID, Road>, pub roads: BTreeMap<StableRoadID, Road>,
pub intersections: BTreeMap<StableIntersectionID, Intersection>, pub intersections: BTreeMap<StableIntersectionID, Intersection>,
pub buildings: Vec<Building>, pub buildings: Vec<Building>,
@ -40,8 +41,9 @@ pub struct Map {
} }
impl Map { impl Map {
pub fn blank() -> Map { pub fn blank(name: String) -> Map {
Map { Map {
name,
roads: BTreeMap::new(), roads: BTreeMap::new(),
intersections: BTreeMap::new(), intersections: BTreeMap::new(),
buildings: Vec::new(), buildings: Vec::new(),

View File

@ -210,7 +210,7 @@ impl Model {
// Returns path to raw map // Returns path to raw map
pub fn export(&self) -> String { pub fn export(&self) -> String {
let mut map = raw_data::Map::blank(); let mut map = raw_data::Map::blank(self.name.clone().expect("Model hasn't been named yet"));
for (id, r) in &self.roads { for (id, r) in &self.roads {
let mut osm_tags = BTreeMap::new(); let mut osm_tags = BTreeMap::new();
@ -267,7 +267,7 @@ impl Model {
map.gps_bounds = self.gps_bounds.clone(); map.gps_bounds = self.gps_bounds.clone();
map.boundary_polygon = self.compute_bounds().get_rectangle(); map.boundary_polygon = self.compute_bounds().get_rectangle();
let path = abstutil::path_raw_map(self.name.as_ref().expect("Model hasn't been named yet")); let path = abstutil::path_raw_map(&map.name);
abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path)); abstutil::write_binary(&path, &map).expect(&format!("Saving {} failed", path));
println!("Exported {}", path); println!("Exported {}", path);
path path
@ -286,7 +286,7 @@ impl Model {
let mut data: raw_data::Map = read_binary(path, &mut timer).unwrap(); let mut data: raw_data::Map = read_binary(path, &mut timer).unwrap();
data.apply_fixes(&m.fixes, &mut timer); data.apply_fixes(&m.fixes, &mut timer);
m.name = Some(abstutil::basename(path)); m.name = Some(data.name.clone());
m.gps_bounds = data.gps_bounds.clone(); m.gps_bounds = data.gps_bounds.clone();
for (id, raw_i) in &data.intersections { for (id, raw_i) in &data.intersections {
@ -315,7 +315,7 @@ impl Model {
.osm_tags .osm_tags
.get(k) .get(k)
.cloned() .cloned()
.unwrap_or("MISSING".to_string()); .unwrap_or_else(|| "MISSING".to_string());
println!(" {} = {} / {}", k, v1, v2); println!(" {} = {} / {}", k, v1, v2);
} }
for (k, v2) in &other.osm_tags { for (k, v2) in &other.osm_tags {