hide spaces in rendering if access to them is restricted
This commit is contained in:
parent
4acee03ca3
commit
2a64262e90
2 changed files with 38 additions and 2 deletions
|
@ -22,6 +22,8 @@ class LevelGeometries:
|
|||
self.doors = None
|
||||
self.holes = None
|
||||
self.access_restriction_affected = None
|
||||
self.restricted_spaces_indoors = None
|
||||
self.restricted_spaces_outdoors = None
|
||||
|
||||
@staticmethod
|
||||
def crop(self, geometry, crop_to):
|
||||
|
@ -37,6 +39,7 @@ class LevelGeometries:
|
|||
geoms = LevelGeometries()
|
||||
buildings_geom = unary_union([b.geometry for b in level.buildings.all()])
|
||||
|
||||
# remove columns and holes from space areas
|
||||
for space in level.spaces.all():
|
||||
if space.outside:
|
||||
space.geometry = space.geometry.difference(buildings_geom)
|
||||
|
@ -52,14 +55,33 @@ class LevelGeometries:
|
|||
if level.on_top_of_id is None:
|
||||
geoms.holes = spaces_geom.difference(walkable_geom)
|
||||
|
||||
# keep track which areas are affected by access restrictions
|
||||
access_restriction_affected = {}
|
||||
|
||||
# keep track wich spaces to hide
|
||||
restricted_spaces_indoors = {}
|
||||
restricted_spaces_outdoors = {}
|
||||
|
||||
# ground colors
|
||||
colors = {}
|
||||
|
||||
# go through spaces and their areas for access control and ground colors
|
||||
for space in level.spaces.all():
|
||||
access_restriction = space.access_restriction_id
|
||||
if access_restriction is not None:
|
||||
access_restriction_affected.setdefault(access_restriction, []).append(space.geometry)
|
||||
buffered = space.geometry.buffer(0.01)
|
||||
if buffered.intersects(buildings_geom):
|
||||
restricted_spaces_indoors.setdefault(access_restriction, []).append(
|
||||
buffered.intersection(buildings_geom)
|
||||
)
|
||||
if not buffered.within(buildings_geom):
|
||||
restricted_spaces_outdoors.setdefault(access_restriction, []).append(
|
||||
buffered.difference(buildings_geom)
|
||||
)
|
||||
|
||||
colors.setdefault(space.get_color(), {}).setdefault(access_restriction, []).append(space.geometry)
|
||||
|
||||
for area in space.areas.all():
|
||||
access_restriction = area.access_restriction_id or space.access_restriction_id
|
||||
if access_restriction is not None:
|
||||
|
@ -67,10 +89,12 @@ class LevelGeometries:
|
|||
colors.setdefault(area.get_color(), {}).setdefault(access_restriction, []).append(area.geometry)
|
||||
colors.pop(None, None)
|
||||
|
||||
# merge ground colors
|
||||
for color, color_group in colors.items():
|
||||
for access_restriction, areas in tuple(color_group.items()):
|
||||
color_group[access_restriction] = unary_union(areas)
|
||||
|
||||
# add altitudegroup geometries and split ground colors into them
|
||||
for altitudearea in level.altitudeareas.all():
|
||||
altitudearea_colors = {color: {access_restriction: area.intersection(altitudearea.geometry)
|
||||
for access_restriction, area in areas.items()
|
||||
|
@ -79,8 +103,13 @@ class LevelGeometries:
|
|||
altitudearea_colors = {color: areas for color, areas in altitudearea_colors.items() if areas}
|
||||
geoms.altitudeareas.append(AltitudeAreaGeometries(altitudearea, altitudearea_colors))
|
||||
|
||||
# merge access restrictions
|
||||
geoms.access_restriction_affected = {access_restriction: unary_union(areas)
|
||||
for access_restriction, areas in access_restriction_affected.items()}
|
||||
geoms.restricted_spaces_indoors = {access_restriction: unary_union(spaces)
|
||||
for access_restriction, spaces in restricted_spaces_indoors.items()}
|
||||
geoms.restricted_spaces_outdoors = {access_restriction: unary_union(spaces)
|
||||
for access_restriction, spaces in restricted_spaces_outdoors.items()}
|
||||
|
||||
geoms.walls = buildings_geom.difference(spaces_geom).difference(doors_geom)
|
||||
level.geoms_cache = pickle.dumps(geoms)
|
||||
|
|
|
@ -70,8 +70,15 @@ class SVGRenderer:
|
|||
if geoms.crop_to is not None:
|
||||
crop_to = crop_to.intersection(geoms.crop_to)
|
||||
|
||||
add_walls = unary_union(tuple(area for access_restriction, area in geoms.restricted_spaces_indoors.items()
|
||||
if access_restriction not in unlocked_access_restrictions))
|
||||
crop_areas = unary_union(
|
||||
tuple(area for access_restriction, area in geoms.restricted_spaces_outdoors.items()
|
||||
if access_restriction not in unlocked_access_restrictions)
|
||||
).union(add_walls)
|
||||
|
||||
for altitudearea in geoms.altitudeareas:
|
||||
svg.add_geometry(crop_to.intersection(altitudearea.geometry),
|
||||
svg.add_geometry(crop_to.intersection(altitudearea.geometry.difference(crop_areas)),
|
||||
fill_color='#eeeeee', altitude=altitudearea.altitude)
|
||||
|
||||
for color, areas in altitudearea.colors.items():
|
||||
|
@ -80,7 +87,7 @@ class SVGRenderer:
|
|||
if areas:
|
||||
svg.add_geometry(crop_to.intersection(unary_union(areas)), fill_color=color, elevation=0)
|
||||
|
||||
svg.add_geometry(crop_to.intersection(geoms.walls),
|
||||
svg.add_geometry(crop_to.intersection(geoms.walls.union(add_walls)),
|
||||
fill_color='#aaaaaa', stroke_px=0.5, stroke_color='#aaaaaa', elevation=default_height)
|
||||
|
||||
svg.add_geometry(crop_to.intersection(geoms.doors), fill_color='#ffffff', elevation=0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue