Structural items in the collection hierarchy are now auto synced.

This commit is contained in:
Dion Moult
2022-01-30 10:11:19 +11:00
parent 7ee589cfc2
commit bf9d46b506
2 changed files with 41 additions and 18 deletions
+21 -18
View File
@@ -128,26 +128,22 @@ class Collector(blenderbim.core.tool.Collector):
name = "IfcGroup/" + rel.RelatingGroup.Name
return bpy.data.collections.get(name, bpy.data.collections.new(name))
if element.is_a("IfcStructuralMember"):
return bpy.data.collections.get("Members", bpy.data.collections.new("Members"))
if element.is_a("IfcStructuralConnection"):
return bpy.data.collections.get("Connections", bpy.data.collections.new("Connections"))
if getattr(element, "IsDecomposedBy", None):
return bpy.data.collections.get(obj.name, bpy.data.collections.new(obj.name))
@classmethod
def _get_collection(cls, element, obj):
if element.is_a("IfcTypeObject"):
collection = bpy.data.collections.get("Types")
if not collection:
collection = bpy.data.collections.new("Types")
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
project_obj.users_collection[0].children.link(collection)
return collection
return cls._create_project_child_collection("Types")
if element.is_a("IfcOpeningElement"):
collection = bpy.data.collections.get("IfcOpeningElements")
if not collection:
collection = bpy.data.collections.new("IfcOpeningElements")
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
project_obj.users_collection[0].children.link(collection)
return collection
return cls._create_project_child_collection("IfcOpeningElements")
if element.is_a("IfcGridAxis"):
if element.PartOfU:
@@ -164,12 +160,10 @@ class Collector(blenderbim.core.tool.Collector):
return bpy.data.collections.get(grid_obj.name)
if element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING":
collection = bpy.data.collections.get("Views")
if not collection:
collection = bpy.data.collections.new("Views")
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
project_obj.users_collection[0].children.link(collection)
return collection
return cls._create_project_child_collection("Views")
if element.is_a("IfcStructuralItem"):
return cls._create_project_child_collection("StructuralItems")
aggregate = ifcopenshell.util.element.get_aggregate(element)
if aggregate:
@@ -194,3 +188,12 @@ class Collector(blenderbim.core.tool.Collector):
collection = bpy.data.collections.get(project_obj.name)
if collection:
return collection
@classmethod
def _create_project_child_collection(cls, name):
collection = bpy.data.collections.get(name)
if not collection:
collection = bpy.data.collections.new(name)
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
project_obj.users_collection[0].children.link(collection)
return collection
@@ -227,6 +227,26 @@ class TestAssign(NewFile):
assert bpy.data.collections.get("Views").children.get("IfcGroup/Unnamed")
assert bpy.data.collections.get("IfcProject/My Project").children.get("Views")
def test_in_decomposition_mode_structural_members_are_placed_in_a_members_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcStructuralCurveMember/Name", None)
element = tool.Ifc.get().createIfcStructuralCurveMember()
tool.Ifc.link(element, element_obj)
subject.assign(element_obj)
assert element_obj.users_collection[0].name == "Members"
assert bpy.data.collections.get("StructuralItems").children.get("Members")
assert bpy.data.collections.get("IfcProject/My Project").children.get("StructuralItems")
def test_in_decomposition_mode_structural_connections_are_placed_in_a_connections_collection(self):
bpy.ops.bim.create_project()
element_obj = bpy.data.objects.new("IfcStructuralCurveConnection/Name", None)
element = tool.Ifc.get().createIfcStructuralCurveConnection()
tool.Ifc.link(element, element_obj)
subject.assign(element_obj)
assert element_obj.users_collection[0].name == "Connections"
assert bpy.data.collections.get("StructuralItems").children.get("Connections")
assert bpy.data.collections.get("IfcProject/My Project").children.get("StructuralItems")
class TestSync(NewFile):
def test_in_decomposition_mode_elements_can_be_in_spatial_containers(self):