turn abstract models into mixins
This commit is contained in:
parent
9e79ca74ae
commit
963694395e
8 changed files with 33 additions and 87 deletions
|
@ -0,0 +1 @@
|
|||
from c3nav.mapdata.models.geometry.section import Space # noqa
|
|
@ -1,25 +1,16 @@
|
|||
from collections import OrderedDict
|
||||
from shapely.geometry import Point, mapping
|
||||
|
||||
from c3nav.mapdata.models.base import Feature, FeatureBase
|
||||
from c3nav.mapdata.models.base import EditorFormMixin
|
||||
from c3nav.mapdata.utils.json import format_geojson
|
||||
|
||||
GEOMETRY_FEATURE_TYPES = OrderedDict()
|
||||
|
||||
|
||||
class GeometryFeatureBase(FeatureBase):
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
cls = super().__new__(mcs, name, bases, attrs)
|
||||
if not cls._meta.abstract:
|
||||
GEOMETRY_FEATURE_TYPES[name.lower()] = cls
|
||||
return cls
|
||||
|
||||
|
||||
class GeometryFeature(Feature, metaclass=GeometryFeatureBase):
|
||||
class GeometryMixin(EditorFormMixin):
|
||||
"""
|
||||
A map feature with a geometry
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
|
|
@ -1,41 +1,25 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from c3nav.mapdata.fields import GeometryField
|
||||
from c3nav.mapdata.models.geometry.base import GeometryFeature, GeometryFeatureBase
|
||||
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
||||
|
||||
LEVEL_FEATURE_TYPES = OrderedDict()
|
||||
|
||||
|
||||
class SectionFeatureBase(GeometryFeatureBase):
|
||||
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
|
||||
|
||||
|
||||
class SectionFeature(GeometryFeature, metaclass=SectionFeatureBase):
|
||||
"""
|
||||
a map feature that has a geometry and belongs to a section
|
||||
"""
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class SectionGeometryMixin(GeometryMixin):
|
||||
def get_geojson_properties(self):
|
||||
result = super().get_geojson_properties()
|
||||
result['section'] = self.section.id
|
||||
return result
|
||||
|
||||
|
||||
class Building(SectionFeature):
|
||||
class Building(SectionGeometryMixin, models.Model):
|
||||
"""
|
||||
The outline of a building on a specific level
|
||||
"""
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
|
@ -44,10 +28,11 @@ class Building(SectionFeature):
|
|||
default_related_name = 'buildings'
|
||||
|
||||
|
||||
class Space(SectionFeature):
|
||||
class Space(SectionGeometryMixin, models.Model):
|
||||
"""
|
||||
An accessible space. Shouldn't overlap.
|
||||
"""
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
CATEGORIES = (
|
||||
|
@ -79,10 +64,11 @@ class Space(SectionFeature):
|
|||
return result
|
||||
|
||||
|
||||
class Door(SectionFeature):
|
||||
class Door(SectionGeometryMixin, models.Model):
|
||||
"""
|
||||
A connection between two rooms
|
||||
"""
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
|
@ -91,10 +77,11 @@ class Door(SectionFeature):
|
|||
default_related_name = 'doors'
|
||||
|
||||
|
||||
class Hole(SectionFeature):
|
||||
class Hole(SectionGeometryMixin, models.Model):
|
||||
"""
|
||||
A hole in the ground of a room, e.g. for stairs.
|
||||
"""
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -1,43 +1,27 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from shapely.geometry import CAP_STYLE, JOIN_STYLE, mapping
|
||||
|
||||
from c3nav.mapdata.fields import GeometryField
|
||||
from c3nav.mapdata.models.geometry.base import GeometryFeature, GeometryFeatureBase
|
||||
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
||||
from c3nav.mapdata.utils.json import format_geojson
|
||||
|
||||
SPACE_FEATURE_TYPES = OrderedDict()
|
||||
|
||||
|
||||
class SpaceFeatureBase(GeometryFeatureBase):
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
cls = super().__new__(mcs, name, bases, attrs)
|
||||
if not cls._meta.abstract:
|
||||
SPACE_FEATURE_TYPES[name.lower()] = cls
|
||||
return cls
|
||||
|
||||
|
||||
class SpaceFeature(GeometryFeature, metaclass=SpaceFeatureBase):
|
||||
"""
|
||||
a map feature that has a geometry and belongs to a space
|
||||
"""
|
||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class SpaceGeometryMixin(GeometryMixin):
|
||||
def get_geojson_properties(self):
|
||||
result = super().get_geojson_properties()
|
||||
result['space'] = self.space.id
|
||||
return result
|
||||
|
||||
|
||||
class StuffedArea(SpaceFeature):
|
||||
class StuffedArea(SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
A slow area with many tables or similar. Avoid it from routing by slowing it a bit down
|
||||
"""
|
||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
|
@ -46,10 +30,11 @@ class StuffedArea(SpaceFeature):
|
|||
default_related_name = 'stuffedareas'
|
||||
|
||||
|
||||
class Stair(SpaceFeature):
|
||||
class Stair(SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
A stair
|
||||
"""
|
||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||
geometry = GeometryField('polyline')
|
||||
|
||||
class Meta:
|
||||
|
@ -80,10 +65,11 @@ class Stair(SpaceFeature):
|
|||
))
|
||||
|
||||
|
||||
class Obstacle(SpaceFeature):
|
||||
class Obstacle(SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
An obstacle
|
||||
"""
|
||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||
geometry = GeometryField('polygon')
|
||||
|
||||
class Meta:
|
||||
|
@ -92,10 +78,11 @@ class Obstacle(SpaceFeature):
|
|||
default_related_name = 'obstacles'
|
||||
|
||||
|
||||
class LineObstacle(SpaceFeature):
|
||||
class LineObstacle(SpaceGeometryMixin, models.Model):
|
||||
"""
|
||||
An obstacle that is a line with a specific width
|
||||
"""
|
||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||
geometry = GeometryField('polyline')
|
||||
width = models.DecimalField(_('obstacle width'), max_digits=4, decimal_places=2, default=0.15)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue