Rename function to get relating object

This commit is contained in:
Gorgious
2022-01-30 17:33:21 +01:00
parent 7054f44cc9
commit 5248627a41
12 changed files with 18 additions and 16 deletions
+3 -3
View File
@@ -314,7 +314,7 @@ class IfcImporter:
for spatial_element in leaf_spatial_elements:
while True:
results.add(spatial_element)
spatial_element = ifcopenshell.util.element.get_aggregate(spatial_element)
spatial_element = ifcopenshell.util.element.get_relating_object(spatial_element)
if not spatial_element or spatial_element.is_a("IfcContext"):
break
return results
@@ -1190,7 +1190,7 @@ class IfcImporter:
self.collections[element.GlobalId] = collection
for global_id, aggregate in aggregates.items():
parent = ifcopenshell.util.element.get_aggregate(aggregate["element"])
parent = ifcopenshell.util.element.get_relating_object(aggregate["element"])
if parent:
self.collections[parent.GlobalId].children.link(aggregate["collection"])
continue
@@ -1278,7 +1278,7 @@ class IfcImporter:
collection.name = obj.name
return collection.objects.link(obj)
elif getattr(element, "Decomposes", None):
aggregate = ifcopenshell.util.element.get_aggregate(element)
aggregate = ifcopenshell.util.element.get_relating_object(element)
return self.collections[aggregate.GlobalId].objects.link(obj)
else:
return self.place_object_in_spatial_decomposition_collection(element, obj)
@@ -111,7 +111,7 @@ class BIM_OT_add_aggregate(bpy.types.Operator):
aggregate = self.create_aggregate(context)
tool.Collector.sync(obj)
current_aggregate = ifcopenshell.util.element.get_aggregate(element)
current_aggregate = ifcopenshell.util.element.get_relating_object(element)
current_container = ifcopenshell.util.element.get_container(element)
if current_aggregate:
core.assign_object(
@@ -65,7 +65,9 @@ class CreateProject(bpy.types.Operator):
if self.file.schema == "IFC2X3":
person = blenderbim.core.owner.add_person(tool.Ifc)
organisation = blenderbim.core.owner.add_organisation(tool.Ifc)
user = blenderbim.core.owner.add_person_and_organisation(tool.Ifc, person=person, organisation=organisation)
user = blenderbim.core.owner.add_person_and_organisation(
tool.Ifc, person=person, organisation=organisation
)
blenderbim.core.owner.set_user(tool.Owner, user=user)
project = bpy.data.objects.new(self.get_name("IfcProject", "My Project"), None)
@@ -624,7 +626,7 @@ class LoadProjectElements(bpy.types.Operator):
container = self.file.by_id(filter_category.ifc_definition_id)
while container:
containers.add(container)
container = ifcopenshell.util.element.get_aggregate(container)
container = ifcopenshell.util.element.get_relating_object(container)
if self.file.schema == "IFC2X3" and container.is_a("IfcProject"):
container = None
elif self.file.schema != "IFC2X3" and container.is_a("IfcContext"):
+1 -1
View File
@@ -157,7 +157,7 @@ class Collector(blenderbim.core.tool.Collector):
if grid_obj:
return bpy.data.collections.get(grid_obj.name)
aggregate = ifcopenshell.util.element.get_aggregate(element)
aggregate = ifcopenshell.util.element.get_relating_object(element)
if aggregate:
aggregate_obj = tool.Ifc.get_object(aggregate)
if aggregate_obj:
+1 -1
View File
@@ -41,7 +41,7 @@ class Misc(blenderbim.core.tool.Misc):
@classmethod
def get_storey_height_in_si(cls, storey, total_storeys):
building = ifcopenshell.util.element.get_aggregate(storey)
building = ifcopenshell.util.element.get_relating_object(storey)
related_objects = []
for rel in building.IsDecomposedBy:
if rel.is_a("IfcRelAggregates"):
+1 -1
View File
@@ -235,4 +235,4 @@ class TestSync(NewFile):
bpy.data.collections.get("IfcBuilding/My Building").children.link(col)
col.objects.link(obj)
subject.sync(obj)
assert ifcopenshell.util.element.get_aggregate(element).is_a("IfcBuilding")
assert ifcopenshell.util.element.get_relating_object(element).is_a("IfcBuilding")
@@ -38,7 +38,7 @@ class Usecase:
if contains_elements and contained_in_structure and contained_in_structure[0] == contains_elements[0]:
return
aggregate = ifcopenshell.util.element.get_aggregate(self.settings["product"])
aggregate = ifcopenshell.util.element.get_relating_object(self.settings["product"])
if aggregate:
ifcopenshell.api.run(
"aggregate.unassign_object", self.file, relating_object=aggregate, product=self.settings["product"]
@@ -157,7 +157,7 @@ def get_container(element, should_get_direct=False):
if hasattr(element, "ContainedInStructure") and element.ContainedInStructure:
return element.ContainedInStructure[0].RelatingStructure
else:
aggregate = get_aggregate(element)
aggregate = get_relating_object(element)
if aggregate:
return get_container(aggregate, should_get_direct)
if hasattr(element, "ContainedInStructure") and element.ContainedInStructure:
@@ -178,7 +178,7 @@ def get_decomposition(element):
return results
def get_aggregate(element):
def get_relating_object(element):
if hasattr(element, "Decomposes") and element.Decomposes:
return element.Decomposes[0].RelatingObject
@@ -29,7 +29,7 @@ class TestAssignObject(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
assert ifcopenshell.util.element.get_aggregate(subelement) == element
assert ifcopenshell.util.element.get_relating_object(subelement) == element
assert rel.is_a("IfcRelAggregates")
def test_doing_nothing_if_the_aggregate_is_already_assigned(self):
@@ -28,7 +28,7 @@ class TestUnassignObject(test.bootstrap.IFC4):
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
assert ifcopenshell.util.element.get_aggregate(subelement) is None
assert ifcopenshell.util.element.get_relating_object(subelement) is None
def test_the_rel_is_kept_if_there_are_more_decomposed_elements(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
@@ -118,4 +118,4 @@ class TestAssignContainer(test.bootstrap.IFC4):
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=aggregate)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
assert not ifcopenshell.util.element.get_aggregate(subelement)
assert not ifcopenshell.util.element.get_relating_object(subelement)
@@ -365,7 +365,7 @@ class TestGetAggregateIFC4(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCovering")
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
assert subject.get_aggregate(subelement) == element
assert subject.get_relating_object(subelement) == element
class TestReplaceAttributeIFC4(test.bootstrap.IFC4):