mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix bug where removing addresses and roles could leave other elements in invalid states, "IfcPersonAndOrganization"
This commit is contained in:
@@ -6,4 +6,8 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
for inverse in self.file.get_inverse(self.settings["address"]):
|
||||||
|
if inverse.is_a() in ("IfcOrganization", "IfcPerson"):
|
||||||
|
if inverse.Addresses == (self.settings["address"],):
|
||||||
|
inverse.Addresses = None
|
||||||
self.file.remove(self.settings["address"])
|
self.file.remove(self.settings["address"])
|
||||||
|
|||||||
@@ -6,4 +6,11 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
for inverse in self.file.get_inverse(self.settings["role"]):
|
||||||
|
if inverse.is_a() in ("IfcOrganization", "IfcPerson", "IfcPersonAndOrganization"):
|
||||||
|
if inverse.Roles == (self.settings["role"],):
|
||||||
|
inverse.Roles = None
|
||||||
|
elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"):
|
||||||
|
if inverse.RelatedResourceObjects == (self.settings["organisation"],):
|
||||||
|
self.file.remove(inverse)
|
||||||
self.file.remove(self.settings["role"])
|
self.file.remove(self.settings["role"])
|
||||||
|
|||||||
@@ -9,3 +9,17 @@ class TestRemoveAddress(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("owner.remove_address", self.file, address=postal)
|
ifcopenshell.api.run("owner.remove_address", self.file, address=postal)
|
||||||
ifcopenshell.api.run("owner.remove_address", self.file, address=telecom)
|
ifcopenshell.api.run("owner.remove_address", self.file, address=telecom)
|
||||||
assert len(self.file.by_type("IfcAddress")) == 0
|
assert len(self.file.by_type("IfcAddress")) == 0
|
||||||
|
|
||||||
|
def test_ensuring_organisation_cardinality_is_valid(self):
|
||||||
|
address = self.file.createIfcPostalAddress()
|
||||||
|
organisation = self.file.createIfcOrganization()
|
||||||
|
organisation.Addresses = [address]
|
||||||
|
ifcopenshell.api.run("owner.remove_address", self.file, address=address)
|
||||||
|
assert organisation.Addresses is None
|
||||||
|
|
||||||
|
def test_ensuring_person_cardinality_is_valid(self):
|
||||||
|
address = self.file.createIfcPostalAddress()
|
||||||
|
person = self.file.createIfcPerson()
|
||||||
|
person.Addresses = [address]
|
||||||
|
ifcopenshell.api.run("owner.remove_address", self.file, address=address)
|
||||||
|
assert person.Addresses is None
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
|
||||||
|
class TestRemoveRole(test.bootstrap.IFC4):
|
||||||
|
def test_removing_a_role(self):
|
||||||
|
role = self.file.createIfcActorRole()
|
||||||
|
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||||
|
assert len(self.file.by_type("IfcActorRole")) == 0
|
||||||
|
|
||||||
|
def test_ensuring_organisation_cardinality_is_valid(self):
|
||||||
|
role = self.file.createIfcActorRole()
|
||||||
|
organisation = self.file.createIfcOrganization()
|
||||||
|
organisation.Roles = [role]
|
||||||
|
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||||
|
assert organisation.Roles is None
|
||||||
|
|
||||||
|
def test_ensuring_person_cardinality_is_valid(self):
|
||||||
|
role = self.file.createIfcActorRole()
|
||||||
|
person = self.file.createIfcPerson()
|
||||||
|
person.Roles = [role]
|
||||||
|
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||||
|
assert person.Roles is None
|
||||||
|
|
||||||
|
def test_ensuring_person_and_organisation_cardinality_is_valid(self):
|
||||||
|
role = self.file.createIfcActorRole()
|
||||||
|
person_and_organisation = self.file.createIfcPersonAndOrganization()
|
||||||
|
person_and_organisation.Roles = [role]
|
||||||
|
ifcopenshell.api.run("owner.remove_role", self.file, role=role)
|
||||||
|
assert person_and_organisation.Roles is None
|
||||||
|
|
||||||
|
def test_deleting_resource_approval_relationships(self):
|
||||||
|
organisation = self.file.createIfcOrganization()
|
||||||
|
self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[organisation])
|
||||||
|
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||||
|
assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0
|
||||||
|
|
||||||
|
def test_deleting_resource_constraint_relationships(self):
|
||||||
|
organisation = self.file.createIfcOrganization()
|
||||||
|
self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[organisation])
|
||||||
|
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||||
|
assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0
|
||||||
|
|
||||||
|
def test_deleting_external_reference_relationships(self):
|
||||||
|
organisation = self.file.createIfcOrganization()
|
||||||
|
self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[organisation])
|
||||||
|
ifcopenshell.api.run("owner.remove_organisation", self.file, organisation=organisation)
|
||||||
|
assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0
|
||||||
Reference in New Issue
Block a user