WIP minor fixes to aggregate and spatial collection handling. See #1222.

This commit is contained in:
Dion Moult
2021-01-07 21:02:46 +11:00
parent 30d9ad1fbc
commit afbdedaee8
4 changed files with 23 additions and 9 deletions
@@ -1,5 +1,4 @@
import bpy
import ifcopenshell.util.schema
import blenderbim.bim.module.aggregate.assign_object as assign_object
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.aggregate.data import Data
@@ -29,11 +28,9 @@ class AssignObject(bpy.types.Operator):
Data.load(props.ifc_definition_id)
bpy.ops.bim.disable_editing_aggregate(obj=related_object.name)
declaration = IfcStore.get_schema().declaration_by_name(product.is_a())
# TODO: we may not need this conditional if aggregates stop using collection instances
if ifcopenshell.util.schema.is_a(declaration, "IfcSpatialElement"):
related_collection = related_object.users_collection[0]
relating_collection = relating_object.users_collection[0]
related_collection = bpy.data.collections.get(related_object.name)
if related_collection:
relating_collection = bpy.data.collections.get(relating_object.name)
self.remove_collection(bpy.context.scene.collection, related_collection)
for collection in bpy.data.collections:
if collection == relating_collection:
@@ -11,7 +11,16 @@ class BIM_PT_object_psets(Panel):
@classmethod
def poll(cls, context):
return context.active_object is not None and hasattr(context.active_object, "BIMObjectProperties")
if not context.active_object:
return False
props = context.active_object.BIMObjectProperties
if not props.ifc_definition_id:
return False
if props.ifc_definition_id not in Data.products:
Data.load(props.ifc_definition_id)
if not Data.products[props.ifc_definition_id]:
return False
return True
def draw(self, context):
props = context.active_object.BIMObjectProperties
@@ -110,9 +110,14 @@ class AssignClass(bpy.types.Operator):
bpy.ops.bim.add_representation(obj=obj.name)
if ifcopenshell.util.schema.is_a(self.declaration, "IfcElementType"):
if product.is_a("IfcElementType"):
self.place_in_types_collection(obj)
elif ifcopenshell.util.schema.is_a(self.declaration, "IfcSpatialElement") or self.ifc_class == "IfcProject":
elif (
product.is_a("IfcSpatialElement")
or product.is_a("IfcSpatialStructureElement")
or product.is_a("IfcProject")
or product.is_a("IfcContext")
):
self.place_in_spatial_collection(obj)
else:
self.assign_potential_spatial_container(obj)
@@ -248,6 +248,7 @@ def refreshActiveDrawingIndex(self, context):
def getIfcProducts(self, context):
global products_enum
file = IfcStore.get_file()
if len(products_enum) < 1:
products_enum.extend(
[
@@ -263,6 +264,8 @@ def getIfcProducts(self, context):
]
]
)
if file.schema == "IFC2X3":
products_enum[2] = ("IfcSpatialStructureElement", "IfcSpatialStructureElement", "")
return products_enum