From df1c47bbfe74a70912689ba0dc489f6993ed5f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Mon, 19 Dec 2016 17:53:10 +0100 Subject: [PATCH] describe route: always state location after walking through a door --- src/c3nav/routing/point.py | 4 ++ src/c3nav/routing/route.py | 50 +++++++++++++++++-- src/c3nav/site/static/site/css/c3nav.css | 1 + .../site/templates/site/fragment_route.html | 9 ++-- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/c3nav/routing/point.py b/src/c3nav/routing/point.py index d31fb1c3..0c706e97 100644 --- a/src/c3nav/routing/point.py +++ b/src/c3nav/routing/point.py @@ -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 '' % (self.x, self.y, (id(self.room) if self.room else None)) diff --git a/src/c3nav/routing/route.py b/src/c3nav/routing/route.py index 7d76f90a..b54491ff 100644 --- a/src/c3nav/routing/route.py +++ b/src/c3nav/routing/route.py @@ -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 diff --git a/src/c3nav/site/static/site/css/c3nav.css b/src/c3nav/site/static/site/css/c3nav.css index c3680005..b70e7986 100644 --- a/src/c3nav/site/static/site/css/c3nav.css +++ b/src/c3nav/site/static/site/css/c3nav.css @@ -181,4 +181,5 @@ circle.pos { box-sizing:border-box; width:auto; vertical-align:middle; + line-height: 1.42857143; } diff --git a/src/c3nav/site/templates/site/fragment_route.html b/src/c3nav/site/templates/site/fragment_route.html index 9c944f0f..da548964 100644 --- a/src/c3nav/site/templates/site/fragment_route.html +++ b/src/c3nav/site/templates/site/fragment_route.html @@ -32,23 +32,24 @@
+ {% if forloop.first %}
-

{{ routepart.line | safe }}

+

{{ origin.title }}
{{ origin.subtitle }}

+ {% endif %} {% for line in routepart.lines %} {% if not line.ignore %}
-

{{ line.description }}

+

{% if line.title %}{{ line.title }}
{% endif %}{{ line.description }}

{% endif %} {% endfor %} {% if forloop.last %}
-

{% trans 'You have reached your destination.' %} - {% if destination_title %}
{{ destination_title }}{% endif %}

+

{{ destination.title }}
{{ destination.subtitle }}

{% endif %}