naming synthetic buildings

This commit is contained in:
Dustin Carlino 2018-11-26 08:48:19 -08:00
parent d0b90b9243
commit c46489ca83
4 changed files with 54 additions and 9 deletions

View File

@ -50,15 +50,17 @@
[
0,
{
"label": "north",
"center": {
"x": 346.904667528168,
"y": 448.922516369675
"x": 351.30378272601708,
"y": 450.3966017603446
}
}
],
[
1,
{
"label": "south",
"center": {
"x": 439.6870726625188,
"y": 515.314383299414

View File

@ -103,6 +103,9 @@ fn tooltip_lines(obj: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Text {
for (k, v) in &r.osm_tags {
txt.add_line(format!("{} = {}", k, v));
}
if l.is_parking() {
txt.add_line(format!("Has {} parking spots", l.number_parking_spots()));
}
}
ID::Intersection(id) => {
txt.add_line(id.to_string());

View File

@ -27,6 +27,7 @@ enum State {
Viewing,
MovingIntersection(IntersectionID),
MovingBuilding(BuildingID),
LabelingBuilding(BuildingID, Wizard),
CreatingRoad(IntersectionID),
EditingRoad(RoadID, Wizard),
SavingModel(Wizard),
@ -69,6 +70,17 @@ impl GUI for UI {
self.state = State::Viewing;
}
}
State::LabelingBuilding(id, ref mut wizard) => {
if let Some(label) = wizard.wrap(&mut input).input_string_prefilled(
"Label the building",
self.model.get_b_label(id).unwrap_or("".to_string()),
) {
self.model.set_b_label(id, label);
new_state = Some(State::Viewing);
} else if wizard.aborted() {
new_state = Some(State::Viewing);
}
}
State::CreatingRoad(i1) => {
if input.key_pressed(Key::Escape, "stop defining road") {
self.state = State::Viewing;
@ -121,6 +133,8 @@ impl GUI for UI {
self.state = State::MovingBuilding(b);
} else if input.key_pressed(Key::Backspace, "delete building") {
self.model.remove_b(b);
} else if input.key_pressed(Key::L, "label building") {
self.state = State::LabelingBuilding(b, Wizard::new());
}
} else if let Some(r) = self.model.mouseover_road(cursor) {
if input.key_pressed(Key::Backspace, "delete road") {
@ -161,7 +175,7 @@ impl GUI for UI {
}
fn draw(&self, g: &mut GfxCtx, osd: Text) {
self.model.draw(g);
self.model.draw(g, &self.canvas);
match self.state {
State::CreatingRoad(i1) => {
@ -174,7 +188,9 @@ impl GUI for UI {
),
);
}
State::EditingRoad(_, ref wizard) | State::SavingModel(ref wizard) => {
State::LabelingBuilding(_, ref wizard)
| State::EditingRoad(_, ref wizard)
| State::SavingModel(ref wizard) => {
wizard.draw(g, &self.canvas);
}
_ => {}

View File

@ -1,6 +1,6 @@
use abstutil::{deserialize_btreemap, serialize_btreemap, write_json};
use dimensioned::si;
use ezgui::{Color, GfxCtx};
use ezgui::{Canvas, Color, GfxCtx, Text};
use geom::{Circle, LonLat, PolyLine, Polygon, Pt2D};
use map_model::{raw_data, LaneType, RoadSpec, LANE_THICKNESS};
use std::collections::BTreeMap;
@ -107,6 +107,7 @@ impl Road {
#[derive(Serialize, Deserialize)]
pub struct Building {
label: Option<String>,
center: Pt2D,
}
@ -126,7 +127,7 @@ impl Model {
}
}
pub fn draw(&self, g: &mut GfxCtx) {
pub fn draw(&self, g: &mut GfxCtx, canvas: &Canvas) {
g.clear(Color::WHITE);
for r in self.roads.values() {
@ -146,6 +147,11 @@ impl Model {
for b in self.buildings.values() {
g.draw_polygon(Color::BLUE, &b.polygon());
if let Some(ref label) = b.label {
let mut txt = Text::new();
txt.add_line(label.to_string());
canvas.draw_text_at(g, txt, b.center);
}
}
}
@ -190,10 +196,14 @@ impl Model {
}
for (idx, b) in self.buildings.values().enumerate() {
let mut osm_tags = BTreeMap::new();
if let Some(ref label) = b.label {
osm_tags.insert("label".to_string(), label.to_string());
}
map.buildings.push(raw_data::Building {
// TODO Duplicate points :(
points: b.polygon().points().into_iter().map(|p| pt(p)).collect(),
osm_tags: BTreeMap::new(),
osm_tags,
osm_way_id: idx as i64,
});
}
@ -306,13 +316,27 @@ impl Model {
impl Model {
pub fn create_b(&mut self, center: Pt2D) {
let id = self.buildings.len();
self.buildings.insert(id, Building { center });
self.buildings.insert(
id,
Building {
center,
label: None,
},
);
}
pub fn move_b(&mut self, id: IntersectionID, center: Pt2D) {
pub fn move_b(&mut self, id: BuildingID, center: Pt2D) {
self.buildings.get_mut(&id).unwrap().center = center;
}
pub fn set_b_label(&mut self, id: BuildingID, label: String) {
self.buildings.get_mut(&id).unwrap().label = Some(label);
}
pub fn get_b_label(&self, id: BuildingID) -> Option<String> {
self.buildings[&id].label.clone()
}
pub fn remove_b(&mut self, id: BuildingID) {
self.buildings.remove(&id);
}