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
#![allow(clippy::type_complexity)]
use structopt::StructOpt;
use abstutil::Timer;
use widgetry::{EventCtx, GfxCtx, Settings};
pub use browse::BrowseNeighborhoods;
use filters::Toggle3Zoomed;
pub use filters::{DiagonalFilter, ModalFilters};
pub use neighborhood::{Cell, DistanceInterval, Neighborhood};
pub use partition::{NeighborhoodID, Partitioning};
#[macro_use]
extern crate anyhow;
#[macro_use]
extern crate log;
mod browse;
mod colors;
mod common;
mod connectivity;
mod draw_cells;
mod export;
mod filters;
mod impact;
mod neighborhood;
mod partition;
mod per_neighborhood;
mod route_planner;
mod save;
mod select_boundary;
mod shortcut_viewer;
mod shortcuts;
type App = map_gui::SimpleApp<Session>;
type Transition = widgetry::Transition<App>;
pub fn main() {
let settings = Settings::new("Low traffic neighborhoods");
run(settings);
}
#[derive(StructOpt)]
struct Args {
#[structopt(long)]
proposal: Option<String>,
#[structopt(flatten)]
app_args: map_gui::SimpleAppArgs,
}
fn run(mut settings: Settings) {
let mut opts = map_gui::options::Options::load_or_default();
opts.color_scheme = map_gui::colors::ColorSchemeChoice::LTN;
let args = Args::from_iter(abstutil::cli_args());
args.app_args.override_options(&mut opts);
settings = args
.app_args
.update_widgetry_settings(settings)
.canvas_settings(opts.canvas_settings.clone());
widgetry::run(settings, move |ctx| {
let session = Session {
proposal_name: None,
partitioning: Partitioning::empty(),
modal_filters: ModalFilters::default(),
alt_proposals: save::AltProposals::new(),
draw_all_filters: Toggle3Zoomed::empty(ctx),
impact: impact::Impact::empty(ctx),
highlight_boundary_roads: false,
draw_neighborhood_style: browse::Style::SimpleColoring,
draw_cells_as_areas: true,
heuristic: filters::auto::Heuristic::SplitCells,
main_road_penalty: 1.0,
current_trip_name: None,
};
map_gui::SimpleApp::new(
ctx,
opts,
args.app_args.map_name(),
args.app_args.cam,
session,
move |ctx, app| {
let popup_state = args
.proposal
.as_ref()
.and_then(|name| crate::save::Proposal::load(ctx, app, name));
let mut states = vec![
map_gui::tools::TitleScreen::new_state(
ctx,
app,
map_gui::tools::Executable::LTN,
Box::new(|ctx, app, _| BrowseNeighborhoods::new_state(ctx, app)),
),
BrowseNeighborhoods::new_state(ctx, app),
];
if let Some(state) = popup_state {
states.push(state);
}
states
},
)
});
}
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(js_name = "run")]
pub fn run_wasm(root_dom_id: String, assets_base_url: String, assets_are_gzipped: bool) {
let settings = Settings::new("Low traffic neighborhoods")
.root_dom_element_id(root_dom_id)
.assets_base_url(assets_base_url)
.assets_are_gzipped(assets_are_gzipped);
run(settings);
}
pub struct Session {
pub proposal_name: Option<String>,
pub partitioning: Partitioning,
pub modal_filters: ModalFilters,
pub alt_proposals: save::AltProposals,
pub draw_all_filters: Toggle3Zoomed,
pub impact: impact::Impact,
pub highlight_boundary_roads: bool,
pub draw_neighborhood_style: browse::Style,
pub draw_cells_as_areas: bool,
pub heuristic: filters::auto::Heuristic,
pub main_road_penalty: f64,
current_trip_name: Option<String>,
}
fn draw_with_layering<F: Fn(&mut GfxCtx)>(g: &mut GfxCtx, app: &App, custom: F) {
g.clear(app.cs.void_background);
g.redraw(&app.draw_map.boundary_polygon);
g.redraw(&app.draw_map.draw_all_areas);
custom(g);
if g.canvas.is_unzoomed() {
g.redraw(&app.draw_map.draw_all_unzoomed_parking_lots);
g.redraw(&app.draw_map.draw_all_unzoomed_roads_and_intersections);
g.redraw(&app.draw_map.draw_all_buildings);
g.redraw(&app.draw_map.draw_all_building_outlines);
} else {
let options = map_gui::render::DrawOptions::new();
let objects = app
.draw_map
.get_renderables_back_to_front(g.get_screen_bounds(), &app.map);
let mut drawn_all_buildings = false;
for obj in objects {
obj.draw(g, app, &options);
if matches!(obj.get_id(), map_gui::ID::Building(_)) && !drawn_all_buildings {
g.redraw(&app.draw_map.draw_all_buildings);
g.redraw(&app.draw_map.draw_all_building_outlines);
drawn_all_buildings = true;
}
}
}
}
pub fn after_edit(ctx: &EventCtx, app: &mut App) {
app.session.draw_all_filters = app.session.modal_filters.draw(ctx, &app.map);
}
pub fn clear_current_proposal(ctx: &EventCtx, app: &mut App, timer: &mut Timer) {
app.session.proposal_name = None;
app.session.modal_filters = ModalFilters::default();
crate::filters::transform_existing_filters(ctx, app, timer);
app.session.partitioning = Partitioning::seed_using_heuristics(app, timer);
app.session.draw_all_filters = app.session.modal_filters.draw(ctx, &app.map);
}