describe route: always state location after walking through a door
This commit is contained in:
parent
af2c05a13c
commit
df1c47bbfe
4 changed files with 55 additions and 9 deletions
|
@ -38,5 +38,9 @@ class GraphPoint():
|
|||
self.connections[other_point] = connection
|
||||
other_point.connections_in[self] = connection
|
||||
|
||||
@cached_property
|
||||
def arealocations(self):
|
||||
return tuple(name for name, points_i in self.level.arealocation_points.items() if self.i in points_i)
|
||||
|
||||
def __repr__(self):
|
||||
return '<GraphPoint x=%f y=%f room=%s>' % (self.x, self.y, (id(self.room) if self.room else None))
|
||||
|
|
|
@ -3,6 +3,7 @@ import copy
|
|||
import numpy as np
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from c3nav.mapdata.models import AreaLocation
|
||||
from c3nav.mapdata.utils.misc import get_dimensions
|
||||
|
||||
|
||||
|
@ -50,6 +51,20 @@ class Route:
|
|||
|
||||
self.routeparts = routeparts
|
||||
|
||||
@staticmethod
|
||||
def describe_point(point):
|
||||
print(point.arealocations)
|
||||
locations = sorted(AreaLocation.objects.filter(location_type__in=('room', 'level', 'area'),
|
||||
name__in=point.arealocations),
|
||||
key=AreaLocation.get_sort_key)
|
||||
|
||||
if not locations:
|
||||
return _('Unknown Location'), _('Unknown Location')
|
||||
elif locations[0].location_type == 'level':
|
||||
return _('Unknown Location'), locations[0].title
|
||||
else:
|
||||
return locations[0].title, locations[0].subtitle
|
||||
|
||||
def describe(self, routeparts):
|
||||
for i, routepart in enumerate(routeparts):
|
||||
for j, line in enumerate(routepart.lines):
|
||||
|
@ -75,13 +90,19 @@ class Route:
|
|||
|
||||
line.icon = line.ctype or line.turning
|
||||
|
||||
if from_room is None:
|
||||
line.ignore = True
|
||||
line.arrow = True
|
||||
|
||||
distance = line.distance
|
||||
|
||||
if line.ctype_main in ('stairs', 'escalator', 'elevator'):
|
||||
if from_room is None:
|
||||
line.arrow = True
|
||||
if j+1 < len(routepart.lines) and routepart.lines[j+1].ctype_main == 'elevator':
|
||||
line.ignore = True
|
||||
elif j > 0 and (routepart.lines[j-1].ignore or routepart.lines[j-1].ctype_main == 'elevator'):
|
||||
line.ignore = True
|
||||
else:
|
||||
line.icon = 'location'
|
||||
line.title, line.description = self.describe_point(line.to_point)
|
||||
|
||||
elif line.ctype_main in ('stairs', 'escalator', 'elevator'):
|
||||
line.description = {
|
||||
'stairs_up': _('Go up the stairs.'),
|
||||
'stairs_down': _('Go down the stairs.'),
|
||||
|
@ -103,6 +124,7 @@ class Route:
|
|||
if j > 0:
|
||||
if routepart.lines[j-1].ctype_main == 'elevator':
|
||||
line.arrow = False
|
||||
line.ignore = True
|
||||
|
||||
if j+1 < len(routepart.lines):
|
||||
if routepart.lines[j+1].to_point.room.level.level.intermediate:
|
||||
|
@ -156,6 +178,7 @@ class Route:
|
|||
|
||||
line.desc_distance = distance
|
||||
|
||||
# line.ignore = False
|
||||
if line.ignore:
|
||||
line.icon = None
|
||||
line.description = None
|
||||
|
@ -169,6 +192,22 @@ class Route:
|
|||
if len(last_lines) > 1:
|
||||
last_lines[-1].arrow = True
|
||||
|
||||
unignored_lines = [i for i, line in enumerate(routepart.lines) if line.description]
|
||||
if unignored_lines:
|
||||
first_unignored_i = unignored_lines[0]
|
||||
if first_unignored_i > 0:
|
||||
first_unignored = routepart.lines[first_unignored_i]
|
||||
point = first_unignored.from_point if first_unignored.from_point.room else first_unignored.to_point
|
||||
|
||||
line = routepart.lines[first_unignored_i-1]
|
||||
line.ignore = False
|
||||
line.icon = 'location'
|
||||
line.title, line.description = self.describe_point(point)
|
||||
|
||||
last_line = routeparts[-1].lines[-1]
|
||||
if last_line.icon == 'location':
|
||||
last_line.ignore = True
|
||||
|
||||
|
||||
class RoutePart:
|
||||
def __init__(self, graphlevel, lines):
|
||||
|
@ -229,6 +268,7 @@ class RouteLine:
|
|||
self.can_merge_to_next = False
|
||||
|
||||
self.icon = None
|
||||
self.title = None
|
||||
self.description = None
|
||||
|
||||
|
||||
|
|
|
@ -181,4 +181,5 @@ circle.pos {
|
|||
box-sizing:border-box;
|
||||
width:auto;
|
||||
vertical-align:middle;
|
||||
line-height: 1.42857143;
|
||||
}
|
||||
|
|
|
@ -32,23 +32,24 @@
|
|||
</svg>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
{% if forloop.first %}
|
||||
<div class="desc">
|
||||
<div class="icon location"></div>
|
||||
<p>{{ routepart.line | safe }}</p>
|
||||
<p><strong>{{ origin.title }}</strong><br>{{ origin.subtitle }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for line in routepart.lines %}
|
||||
{% if not line.ignore %}
|
||||
<div class="desc">
|
||||
<div class="icon {{ line.icon }}"></div>
|
||||
<p>{{ line.description }}</p>
|
||||
<p>{% if line.title %}<strong>{{ line.title }}</strong><br>{% endif %}{{ line.description }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if forloop.last %}
|
||||
<div class="desc">
|
||||
<div class="icon destination"></div>
|
||||
<p>{% trans 'You have reached your destination.' %}
|
||||
{% if destination_title %}<br><strong>{{ destination_title }}</strong>{% endif %}</p>
|
||||
<p><strong>{{ destination.title }}</strong><br>{{ destination.subtitle }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue