/
building.rs
234 lines (203 loc) · 7.18 KB
/
building.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
use crate::app::App;
use crate::helpers::ID;
use crate::info::{header_btns, make_table, make_tabs, Details, Tab};
use crate::render::DrawPedestrian;
use ezgui::{Btn, Color, EventCtx, Line, Text, TextExt, Widget};
use geom::{Angle, Circle, Time};
use map_model::{BuildingID, LaneID, Traversable, SIDEWALK_THICKNESS};
use sim::{DrawPedestrianInput, PedestrianID, PersonID, TripMode, TripResult};
pub fn info(ctx: &mut EventCtx, app: &App, details: &mut Details, id: BuildingID) -> Vec<Widget> {
let mut rows = header(ctx, app, details, id, Tab::BldgInfo(id));
let b = app.primary.map.get_b(id);
let mut kv = Vec::new();
kv.push(("Address", b.just_address(&app.primary.map)));
if let Some(name) = b.just_name() {
kv.push(("Name", name.to_string()));
}
if let Some(ref p) = b.parking {
kv.push(("Parking", format!("{} spots via {}", p.num_stalls, p.name)));
} else {
kv.push(("Parking", "None".to_string()));
}
rows.extend(make_table(ctx, kv));
let mut txt = Text::new();
if !b.amenities.is_empty() {
txt.add(Line(""));
if b.amenities.len() > 1 {
txt.add(Line(format!("{} amenities:", b.amenities.len())));
}
for (name, amenity) in &b.amenities {
txt.add(Line(format!("- {} (a {})", name, amenity)));
}
}
let cars = app.primary.sim.get_parked_cars_by_owner(id);
if !cars.is_empty() {
txt.add(Line(""));
txt.add(Line(format!(
"{} parked cars owned by this building",
cars.len()
)));
// TODO Jump to it or see status
for p in cars {
txt.add(Line(format!("- {}", p.vehicle.id)));
}
}
if !txt.is_empty() {
rows.push(txt.draw(ctx))
}
rows
}
pub fn debug(ctx: &mut EventCtx, app: &App, details: &mut Details, id: BuildingID) -> Vec<Widget> {
let mut rows = header(ctx, app, details, id, Tab::BldgDebug(id));
let b = app.primary.map.get_b(id);
rows.extend(make_table(
ctx,
vec![(
"Dist along sidewalk",
b.front_path.sidewalk.dist_along().to_string(),
)],
));
rows.push("Raw OpenStreetMap data".draw_text(ctx));
rows.extend(make_table(ctx, b.osm_tags.clone().into_iter().collect()));
rows
}
pub fn people(ctx: &mut EventCtx, app: &App, details: &mut Details, id: BuildingID) -> Vec<Widget> {
let mut rows = header(ctx, app, details, id, Tab::BldgPeople(id));
// TODO Sort/group better
// Show minimal info: ID, next departure time, type of that trip
for p in app.primary.sim.bldg_to_people(id) {
let person = app.primary.sim.get_person(p);
let mut next_trip: Option<(Time, TripMode)> = None;
for t in &person.trips {
match app.primary.sim.trip_to_agent(*t) {
TripResult::TripNotStarted => {
let (start_time, _, _, mode) = app.primary.sim.trip_info(*t);
next_trip = Some((start_time, mode));
break;
}
TripResult::Ok(_) | TripResult::ModeChange => {
// TODO What to do here? This is meant for building callers right now
break;
}
TripResult::TripDone => {}
TripResult::TripDoesntExist => unreachable!(),
}
}
let label = format!("Person #{}", p.0);
details
.hyperlinks
.insert(label.clone(), Tab::PersonTrips(p));
rows.push(Widget::col(vec![
Btn::text_bg1(label).build_def(ctx, None),
if let Some((t, mode)) = next_trip {
format!("Leaving in {} to {}", t - app.primary.sim.time(), mode).draw_text(ctx)
} else {
"Staying inside".draw_text(ctx)
},
]));
}
rows
}
fn header(
ctx: &EventCtx,
app: &App,
details: &mut Details,
id: BuildingID,
tab: Tab,
) -> Vec<Widget> {
let mut rows = vec![];
rows.push(Widget::row(vec![
Line(format!("Building #{}", id.0))
.small_heading()
.draw(ctx),
header_btns(ctx),
]));
rows.push(make_tabs(
ctx,
&mut details.hyperlinks,
tab,
vec![
("Info", Tab::BldgInfo(id)),
("Debug", Tab::BldgDebug(id)),
("People", Tab::BldgPeople(id)),
],
));
// TODO On every tab?
for p in app.primary.sim.get_parked_cars_by_owner(id) {
// The car might be parked inside!
if let Some(shape) = app
.primary
.draw_map
.get_obj(
ID::Car(p.vehicle.id),
app,
&mut app.primary.draw_map.agents.borrow_mut(),
ctx.prerender,
)
.map(|obj| obj.get_outline(&app.primary.map))
{
details.unzoomed.push(
app.cs.get("something associated with something else"),
shape.clone(),
);
details.zoomed.push(
app.cs.get("something associated with something else"),
shape,
);
}
}
draw_occupants(details, app, id, None);
// TODO Draw cars parked inside?
rows
}
pub fn draw_occupants(details: &mut Details, app: &App, id: BuildingID, focus: Option<PersonID>) {
// TODO Lots of fun ideas here. Have a deterministic simulation based on building ID and time
// to have people "realistically" move around. Draw little floor plans.
let mut ppl = app.primary.sim.bldg_to_people(id);
let num_rows_cols = (ppl.len() as f64).sqrt().ceil() as usize;
let ped_len = SIDEWALK_THICKNESS.inner_meters() / 2.0;
let separation = ped_len * 1.5;
let total_width_height = (num_rows_cols as f64) * (ped_len + separation);
let top_left = app
.primary
.map
.get_b(id)
.label_center
.offset(-total_width_height / 2.0, -total_width_height / 2.0);
// TODO Current thing is inefficient and can easily wind up outside the building.
'OUTER: for x in 0..num_rows_cols {
for y in 0..num_rows_cols {
let person = if let Some(p) = ppl.pop() {
p
} else {
break 'OUTER;
};
let pos = top_left.offset(
(x as f64) * (ped_len + separation),
(y as f64) * (ped_len + separation),
);
if Some(person) == focus {
details.zoomed.push(
Color::YELLOW.alpha(0.8),
Circle::new(pos, SIDEWALK_THICKNESS).to_polygon(),
);
}
DrawPedestrian::geometry(
&mut details.zoomed,
&app.cs,
&DrawPedestrianInput {
// Lies
id: PedestrianID(person.0),
pos,
facing: Angle::new_degs(90.0),
waiting_for_turn: None,
preparing_bike: false,
// Both hands and feet!
waiting_for_bus: true,
on: Traversable::Lane(LaneID(0)),
},
0,
);
}
}
}