2017-05-06 17:24:09 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2017-05-08 16:05:44 +02:00
|
|
|
from c3nav.mapdata.fields import GeometryField
|
2017-05-08 16:40:22 +02:00
|
|
|
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
2017-05-10 18:03:57 +02:00
|
|
|
from c3nav.mapdata.models.locations import SpecificLocation
|
2017-05-06 17:24:09 +02:00
|
|
|
|
2017-05-11 19:36:49 +02:00
|
|
|
SECTION_MODELS = []
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
|
2017-05-08 16:40:22 +02:00
|
|
|
class SectionGeometryMixin(GeometryMixin):
|
2017-05-09 12:50:32 +02:00
|
|
|
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2017-05-11 19:36:49 +02:00
|
|
|
def get_geojson_properties(self) -> dict:
|
2017-05-06 17:24:09 +02:00
|
|
|
result = super().get_geojson_properties()
|
2017-05-11 19:36:49 +02:00
|
|
|
result['layer'] = getattr(self, 'level', 'base')
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _serialize(self, section=True, **kwargs):
|
|
|
|
result = super()._serialize(**kwargs)
|
|
|
|
if section:
|
|
|
|
result['section'] = self.section.id
|
2017-05-06 17:24:09 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2017-05-09 13:48:55 +02:00
|
|
|
class LevelSectionGeometryMixin(SectionGeometryMixin):
|
|
|
|
LEVELS = (
|
|
|
|
('', _('normal')),
|
|
|
|
('upper', _('upper')),
|
|
|
|
('lower', _('lower')),
|
|
|
|
)
|
|
|
|
level = models.CharField(verbose_name=_('level'), choices=LEVELS, default='', max_length=16)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
2017-05-08 16:40:22 +02:00
|
|
|
class Building(SectionGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
The outline of a building on a specific level
|
|
|
|
"""
|
2017-05-08 16:05:44 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Building')
|
|
|
|
verbose_name_plural = _('Buildings')
|
|
|
|
default_related_name = 'buildings'
|
|
|
|
|
|
|
|
|
2017-05-10 18:03:57 +02:00
|
|
|
class Space(SpecificLocation, LevelSectionGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-09 13:48:55 +02:00
|
|
|
An accessible space. Shouldn't overlap with spaces on same secion and level.
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
CATEGORIES = (
|
|
|
|
('', _('normal')),
|
|
|
|
('stairs', _('stairs')),
|
|
|
|
('escalator', _('escalator')),
|
|
|
|
('elevator', _('elevator')),
|
|
|
|
)
|
2017-05-09 09:36:08 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-09 13:20:25 +02:00
|
|
|
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, default='', max_length=16)
|
2017-05-12 23:11:11 +02:00
|
|
|
outside = models.BooleanField(default=False, verbose_name=_('is outside of building'))
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
2017-05-09 13:48:55 +02:00
|
|
|
verbose_name = _('Space')
|
|
|
|
verbose_name_plural = _('Spaces')
|
|
|
|
default_related_name = 'spaces'
|
2017-05-06 17:24:09 +02:00
|
|
|
|
2017-05-11 19:36:49 +02:00
|
|
|
def _serialize(self, space=True, **kwargs):
|
|
|
|
result = super()._serialize(**kwargs)
|
|
|
|
if space:
|
|
|
|
result['category'] = self.category
|
|
|
|
result['level'] = self.level
|
|
|
|
result['public'] = self.public
|
2017-05-06 17:24:09 +02:00
|
|
|
return result
|
|
|
|
|
2017-05-13 16:39:01 +02:00
|
|
|
def get_color(self):
|
|
|
|
color = {
|
|
|
|
'stairs': '#dddddd',
|
2017-05-13 21:25:57 +02:00
|
|
|
'escalator': '#bbbbbb',
|
2017-05-13 16:39:01 +02:00
|
|
|
'elevator': '#00ffff',
|
|
|
|
}.get(self.category)
|
|
|
|
if not color:
|
|
|
|
color = super().get_color()
|
|
|
|
return color
|
|
|
|
|
2017-05-06 17:24:09 +02:00
|
|
|
|
2017-05-09 13:48:55 +02:00
|
|
|
class Door(LevelSectionGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-09 13:48:55 +02:00
|
|
|
A connection between two spaces
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-08 16:05:44 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Door')
|
|
|
|
verbose_name_plural = _('Doors')
|
|
|
|
default_related_name = 'doors'
|
|
|
|
|
|
|
|
|
2017-05-08 16:40:22 +02:00
|
|
|
class Hole(SectionGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-09 13:20:25 +02:00
|
|
|
A hole in the ground of a section (all spaces with layer "normal" and buildings), e.g. for stairs.
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-08 16:05:44 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Hole')
|
|
|
|
verbose_name_plural = _('Holes')
|
|
|
|
default_related_name = 'holes'
|