Cleaning up the map_model transit representation a bit. #372

This commit is contained in:
Dustin Carlino 2021-12-02 13:29:42 +00:00
parent 6e11c386ac
commit fc674df9ac
7 changed files with 19 additions and 33 deletions

View File

@ -202,15 +202,6 @@ fn route_body(ctx: &mut EventCtx, app: &App, details: &mut Details, id: TransitR
.into_widget(ctx),
);
if app.opts.dev {
rows.push(
ctx.style()
.btn_outline
.text("Open OSM relation")
.build_widget(ctx, format!("open {}", route.osm_rel_id)),
);
}
let buses = app.primary.sim.status_of_buses(id, map);
let mut bus_locations = Vec::new();
if buses.is_empty() {
@ -330,7 +321,7 @@ fn route_body(ctx: &mut EventCtx, app: &App, details: &mut Details, id: TransitR
// Draw the route, label stops, and show location of buses
{
let mut colorer = ColorNetwork::new(app);
for req in route.all_steps(map) {
for req in route.all_path_requests(map) {
for step in map.pathfind(req).unwrap().get_steps() {
if let PathStep::Lane(l) = step {
colorer.add_l(*l, app.cs.unzoomed_bus);

View File

@ -87,7 +87,7 @@ impl TransitNetwork {
if !show_trains && tr.route_type == PathConstraints::Train {
continue;
}
for req in tr.all_steps(map) {
for req in tr.all_path_requests(map) {
if let Ok(path) = map.pathfind(req) {
for step in path.get_steps() {
if let PathStep::Lane(l) = step {

View File

@ -58,7 +58,7 @@ pub enum PermanentEditCmd {
old: PermanentEditIntersection,
},
ChangeRouteSchedule {
osm_rel_id: osm::RelationID,
gtfs_id: String,
old: Vec<Time>,
new: Vec<Time>,
},
@ -79,7 +79,7 @@ impl EditCmd {
},
EditCmd::ChangeRouteSchedule { id, old, new } => {
PermanentEditCmd::ChangeRouteSchedule {
osm_rel_id: map.get_tr(*id).osm_rel_id,
gtfs_id: map.get_tr(*id).gtfs_id.clone(),
old: old.clone(),
new: new.clone(),
}
@ -118,14 +118,10 @@ impl PermanentEditCmd {
.with_context(|| format!("old ChangeIntersection of {} invalid", i))?,
})
}
PermanentEditCmd::ChangeRouteSchedule {
osm_rel_id,
old,
new,
} => {
PermanentEditCmd::ChangeRouteSchedule { gtfs_id, old, new } => {
let id = map
.find_tr(osm_rel_id)
.ok_or_else(|| anyhow!("can't find {}", osm_rel_id))?;
.find_tr_by_gtfs(&gtfs_id)
.ok_or_else(|| anyhow!("can't find {}", gtfs_id))?;
Ok(EditCmd::ChangeRouteSchedule { id, old, new })
}
}

View File

@ -664,9 +664,9 @@ impl Map {
None
}
pub fn find_tr(&self, id: osm::RelationID) -> Option<TransitRouteID> {
pub fn find_tr_by_gtfs(&self, gtfs_id: &str) -> Option<TransitRouteID> {
for tr in self.all_transit_routes() {
if tr.osm_rel_id == id {
if tr.gtfs_id == gtfs_id {
return Some(tr.id);
}
}

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use abstutil::{deserialize_usize, serialize_usize};
use geom::Time;
use crate::{osm, LaneID, Map, PathConstraints, PathRequest, Position};
use crate::{LaneID, Map, PathConstraints, PathRequest, Position};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct TransitStopID {
@ -54,11 +54,12 @@ pub struct TransitRoute {
pub id: TransitRouteID,
pub long_name: String,
pub short_name: String,
pub gtfs_trip_marker: Option<String>,
pub osm_rel_id: osm::RelationID,
pub gtfs_id: String,
pub stops: Vec<TransitStopID>,
/// May be a border or not. If not, is long enough for buses to spawn fully.
/// A transit vehicle spawns at the beginning of this lane. This lane may be at a border or the
/// first stop. For the non-border case, the lane must be long enough for the vehicle to spawn.
pub start: LaneID,
/// A transit vehicle either vanishes at its last stop or exits the map through this border.
pub end_border: Option<LaneID>,
pub route_type: PathConstraints,
/// Non-empty, times in order for one day when a vehicle should begin at start.
@ -69,7 +70,7 @@ pub struct TransitRoute {
}
impl TransitRoute {
pub fn all_steps(&self, map: &Map) -> Vec<PathRequest> {
pub fn all_path_requests(&self, map: &Map) -> Vec<PathRequest> {
let mut steps = vec![PathRequest::vehicle(
Position::start(self.start),
map.get_ts(self.stops[0]).driving_pos,

View File

@ -93,7 +93,9 @@ impl TripPhaseType {
TripPhaseType::WaitingForBus(r, _) => {
format!("Waiting for transit route {}", map.get_tr(r).long_name)
}
TripPhaseType::RidingBus(r, _, _) => format!("Riding route {}", map.get_tr(r).long_name),
TripPhaseType::RidingBus(r, _, _) => {
format!("Riding route {}", map.get_tr(r).long_name)
}
TripPhaseType::Cancelled => "Trip was cancelled due to some bug".to_string(),
TripPhaseType::Finished => "Trip finished".to_string(),
TripPhaseType::DelayedStart => "Delayed by a previous trip taking too long".to_string(),

View File

@ -127,11 +127,7 @@ fn dump_route_goldenfile(map: &map_model::Map) -> Result<()> {
));
let mut f = File::create(path)?;
for tr in map.all_transit_routes() {
writeln!(
f,
"{} from {} to {:?}",
tr.osm_rel_id, tr.start, tr.end_border
)?;
writeln!(f, "{} from {} to {:?}", tr.gtfs_id, tr.start, tr.end_border)?;
for ts in &tr.stops {
let ts = map.get_ts(*ts);
writeln!(