Fix breaking spatial containers UI when spatial container is deleted

E.g. if you had some container selected in `active_container_id` and then it got deleted UI would break and won't allow to reload the spatial manger until you reload .ifc completely
This commit is contained in:
Andrej730
2024-01-08 15:53:10 +05:00
parent 48c2b43a58
commit c156100be2
2 changed files with 6 additions and 5 deletions
@@ -32,7 +32,7 @@ class SpatialData:
@classmethod
def load(cls):
cls.data = {
"parent_container_id": cls.get_parent_container_id(),
"parent_container_id": cls.parent_container_id(),
"is_directly_contained": cls.is_directly_contained(),
"label": cls.label(),
"references": cls.references(),
@@ -55,12 +55,12 @@ class SpatialData:
return results
@classmethod
def get_parent_container_id(cls):
def parent_container_id(cls):
container_id = bpy.context.scene.BIMSpatialProperties.active_container_id
if not container_id:
return
container = tool.Ifc.get().by_id(container_id)
if container.is_a("IfcProject"):
container = tool.Ifc.get_entity_by_id(container_id)
if not container or container.is_a("IfcProject"):
return
return container.Decomposes[0].RelatingObject.id()
@@ -121,7 +121,8 @@ class BIM_PT_SpatialManager(Panel):
row = self.layout.row()
row.alignment = "RIGHT"
row.operator("bim.select_decomposed_elements", icon="RESTRICT_SELECT_OFF", text="Select Children")
if SpatialData.data["containers"][ifc_definition_id]["type"] in ["IfcBuildingStorey", "IfcBuilding"]:
spatial_data = SpatialData.data["containers"].get(ifc_definition_id, None)
if spatial_data and spatial_data["type"] in ["IfcBuildingStorey", "IfcBuilding"]:
row.operator("bim.add_building_storey", icon="ADD", text="Add storey").part_class = "IfcBuildingStorey"
row.operator("bim.delete_container", icon="X", text="Delete").container = ifc_definition_id
self.layout.template_list(