2017-05-06 17:24:09 +02:00
|
|
|
from collections import OrderedDict
|
2017-05-07 12:06:13 +02:00
|
|
|
|
2017-05-06 17:24:09 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from c3nav.mapdata.models.geometry.base import GeometryFeature, GeometryFeatureBase
|
|
|
|
|
|
|
|
LEVEL_FEATURE_TYPES = OrderedDict()
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class SectionFeatureBase(GeometryFeatureBase):
|
2017-05-06 17:24:09 +02:00
|
|
|
def __new__(mcs, name, bases, attrs):
|
|
|
|
cls = super().__new__(mcs, name, bases, attrs)
|
|
|
|
if not cls._meta.abstract:
|
|
|
|
LEVEL_FEATURE_TYPES[name.lower()] = cls
|
|
|
|
return cls
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class SectionFeature(GeometryFeature, metaclass=SectionFeatureBase):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-07 12:06:13 +02:00
|
|
|
a map feature that has a geometry and belongs to a section
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-07 12:06:13 +02:00
|
|
|
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
def get_geojson_properties(self):
|
|
|
|
result = super().get_geojson_properties()
|
2017-05-07 12:06:13 +02:00
|
|
|
result['section'] = self.section.id
|
2017-05-06 17:24:09 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class Building(SectionFeature):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
The outline of a building on a specific level
|
|
|
|
"""
|
|
|
|
geomtype = 'polygon'
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Building')
|
|
|
|
verbose_name_plural = _('Buildings')
|
|
|
|
default_related_name = 'buildings'
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class Space(SectionFeature):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-06 17:40:06 +02:00
|
|
|
An accessible space. Shouldn't overlap.
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
geomtype = 'polygon'
|
|
|
|
|
|
|
|
CATEGORIES = (
|
|
|
|
('', _('normal')),
|
|
|
|
('stairs', _('stairs')),
|
|
|
|
('escalator', _('escalator')),
|
|
|
|
('elevator', _('elevator')),
|
|
|
|
)
|
|
|
|
LAYERS = (
|
|
|
|
('', _('normal')),
|
|
|
|
('upper', _('upper')),
|
|
|
|
('lowerr', _('lower')),
|
|
|
|
)
|
|
|
|
|
2017-05-06 17:50:55 +02:00
|
|
|
public = models.BooleanField(verbose_name=_('public'), default=True)
|
2017-05-06 17:24:09 +02:00
|
|
|
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, max_length=16)
|
|
|
|
layer = models.CharField(verbose_name=_('layer'), choices=LAYERS, max_length=16)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Area')
|
|
|
|
verbose_name_plural = _('Areas')
|
|
|
|
default_related_name = 'areas'
|
|
|
|
|
|
|
|
def get_geojson_properties(self):
|
|
|
|
result = super().get_geojson_properties()
|
|
|
|
result['category'] = self.category
|
|
|
|
result['layer'] = self.layer
|
|
|
|
result['public'] = self.public
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class Door(SectionFeature):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
A connection between two rooms
|
|
|
|
"""
|
|
|
|
geomtype = 'polygon'
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Door')
|
|
|
|
verbose_name_plural = _('Doors')
|
|
|
|
default_related_name = 'doors'
|
|
|
|
|
|
|
|
|
2017-05-07 12:06:13 +02:00
|
|
|
class Hole(SectionFeature):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
A hole in the ground of a room, e.g. for stairs.
|
|
|
|
"""
|
|
|
|
geomtype = 'polygon'
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Hole')
|
|
|
|
verbose_name_plural = _('Holes')
|
|
|
|
default_related_name = 'holes'
|