rename get_elements_using_pset -> get_elements_by_pset for consistency

To be consistent with other get_elements_by_xxx methods.
This commit is contained in:
Andrej730
2024-09-05 17:38:22 +05:00
parent a03c55d15f
commit a867e72fd3
9 changed files with 16 additions and 16 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ class Data:
) )
for name, data in sorted(psetqtos.items()): for name, data in sorted(psetqtos.items()):
pset = ifc_file.by_id(data["id"]) pset = ifc_file.by_id(data["id"])
pset_uses = ifcopenshell.util.element.get_elements_using_pset(pset) pset_uses = ifcopenshell.util.element.get_elements_by_pset(pset)
results.append( results.append(
{ {
"id": data["id"], "id": data["id"],
@@ -44,19 +44,19 @@ def assign_pset(
element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
ifcopenshell.api.pset.assign_pset(model, [element], pset) ifcopenshell.api.pset.assign_pset(model, [element], pset)
# Pset is now assigned. # Pset is now assigned.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element}
element1 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") element1 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall") element2 = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
ifcopenshell.api.pset.assign_pset(model, [element1, element2], pset) ifcopenshell.api.pset.assign_pset(model, [element1, element2], pset)
# Pset is now shared by multiple elements. # Pset is now shared by multiple elements.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element, element1, element2} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element, element1, element2}
# Same for element types. # Same for element types.
element_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType") element_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
ifcopenshell.api.pset.assign_pset(model, [element_type], type_pset) ifcopenshell.api.pset.assign_pset(model, [element_type], type_pset)
# Pset is now assigned to the type. # Pset is now assigned to the type.
assert ifcopenshell.util.element.get_elements_using_pset(type_pset) == {element_type} assert ifcopenshell.util.element.get_elements_by_pset(type_pset) == {element_type}
""" """
is_ifc2x3 = file.schema == "IFC2X3" is_ifc2x3 = file.schema == "IFC2X3"
@@ -41,11 +41,11 @@ def unassign_pset(
ifcopenshell.api.pset.assign_pset(self.file, [element1, element2], pset) ifcopenshell.api.pset.assign_pset(self.file, [element1, element2], pset)
# Pset is now shared by 2 elements. # Pset is now shared by 2 elements.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1, element2} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element1, element2}
ifcopenshell.api.pset.unassign_pset(self.file, [element2], pset) ifcopenshell.api.pset.unassign_pset(self.file, [element2], pset)
# Pset was unassigned from element2. # Pset was unassigned from element2.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element1}
""" """
is_ifc2x3 = file.schema == "IFC2X3" is_ifc2x3 = file.schema == "IFC2X3"
@@ -45,17 +45,17 @@ def unshare_pset(
ifcopenshell.api.pset.assign_pset(self.file, [element1, element2], pset) ifcopenshell.api.pset.assign_pset(self.file, [element1, element2], pset)
# Pset is now shared by 2 elements. # Pset is now shared by 2 elements.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1, element2} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element1, element2}
new_psets = ifcopenshell.api.pset.unshare_pset(self.file, [element2], pset) new_psets = ifcopenshell.api.pset.unshare_pset(self.file, [element2], pset)
# element2 was unassigned from the original pset. # element2 was unassigned from the original pset.
assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1} assert ifcopenshell.util.element.get_elements_by_pset(pset) == {element1}
new_pset = new_psets[0] new_pset = new_psets[0]
# New pset was created and was assigned to element2. # New pset was created and was assigned to element2.
assert new_pset != pset assert new_pset != pset
assert ifcopenshell.util.element.get_elements_using_pset(new_pset) == {element2} assert ifcopenshell.util.element.get_elements_by_pset(new_pset) == {element2}
""" """
products_occurrences: set[ifcopenshell.entity_instance] = set() products_occurrences: set[ifcopenshell.entity_instance] = set()
products_types: set[ifcopenshell.entity_instance] = set() products_types: set[ifcopenshell.entity_instance] = set()
@@ -441,7 +441,7 @@ def get_properties(
return results return results
def get_elements_using_pset(pset: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]: def get_elements_by_pset(pset: ifcopenshell.entity_instance) -> set[ifcopenshell.entity_instance]:
"""Retrieve the elements (or element types) that are using the provided property set.""" """Retrieve the elements (or element types) that are using the provided property set."""
is_ifc2x3 = pset.file.schema == "IFC2X3" is_ifc2x3 = pset.file.schema == "IFC2X3"
elements = set() elements = set()
@@ -41,7 +41,7 @@ class TestUnsharePset(test.bootstrap.IFC4):
used_elements = set() used_elements = set()
for pset in psets: for pset in psets:
pset_elements = ifcopenshell.util.element.get_elements_using_pset(pset) pset_elements = ifcopenshell.util.element.get_elements_by_pset(pset)
assert len(pset_elements) == 1 assert len(pset_elements) == 1
used_elements.update(pset_elements) used_elements.update(pset_elements)
@@ -266,7 +266,7 @@ class TestGetElementsUsingPset(test.bootstrap.IFC4):
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType") element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
pset = self.file.create_entity("IfcPropertySet") pset = self.file.create_entity("IfcPropertySet")
ifcopenshell.api.pset.assign_pset(self.file, [element, element_type], pset) ifcopenshell.api.pset.assign_pset(self.file, [element, element_type], pset)
assert subject.get_elements_using_pset(pset) == {element, element_type} assert subject.get_elements_by_pset(pset) == {element, element_type}
class TestGetElementsUsingPsetIFC2X3(test.bootstrap.IFC2X3, TestGetElementsUsingPset): ... class TestGetElementsUsingPsetIFC2X3(test.bootstrap.IFC2X3, TestGetElementsUsingPset): ...
@@ -65,7 +65,7 @@ class Patcher:
all_psets = self.file.by_type("IfcPropertySetDefinition") all_psets = self.file.by_type("IfcPropertySetDefinition")
psets: dict[ifcopenshell.entity_instance, set[ifcopenshell.entity_instance]] = {} psets: dict[ifcopenshell.entity_instance, set[ifcopenshell.entity_instance]] = {}
for pset in all_psets: for pset in all_psets:
elements = ifcopenshell.util.element.get_elements_using_pset(pset) elements = ifcopenshell.util.element.get_elements_by_pset(pset)
# Skip non shared psets. # Skip non shared psets.
if len(elements) < 2: if len(elements) < 2:
continue continue
+3 -3
View File
@@ -38,7 +38,7 @@ class TestUnsharePsets(test.bootstrap.IFC4):
used_elements = set() used_elements = set()
for pset in psets: for pset in psets:
pset_elements = ifcopenshell.util.element.get_elements_using_pset(pset) pset_elements = ifcopenshell.util.element.get_elements_by_pset(pset)
assert len(pset_elements) == 1 assert len(pset_elements) == 1
used_elements.update(pset_elements) used_elements.update(pset_elements)
@@ -81,13 +81,13 @@ class TestUnsharePsets(test.bootstrap.IFC4):
psets.remove(shared_pset) psets.remove(shared_pset)
used_elements = set() used_elements = set()
for pset in psets: for pset in psets:
pset_elements = ifcopenshell.util.element.get_elements_using_pset(pset) pset_elements = ifcopenshell.util.element.get_elements_by_pset(pset)
assert len(pset_elements) == 1 assert len(pset_elements) == 1
used_elements.update(pset_elements) used_elements.update(pset_elements)
assert used_elements == set(elements) assert used_elements == set(elements)
# Leave shared pset untouched as it's not part of the provided query. # Leave shared pset untouched as it's not part of the provided query.
assert ifcopenshell.util.element.get_elements_using_pset(shared_pset) == set(shared_pset_elements) assert ifcopenshell.util.element.get_elements_by_pset(shared_pset) == set(shared_pset_elements)
class TestUnsharePsetsIFC2X3(test.bootstrap.IFC2X3, TestUnsharePsets): class TestUnsharePsetsIFC2X3(test.bootstrap.IFC2X3, TestUnsharePsets):