diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_actor.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_actor.py new file mode 100644 index 0000000000..9dc134ef0c --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_actor.py @@ -0,0 +1,9 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"actor": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + self.file.remove(self.settings["actor"]) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py index 66a88d783f..8a5fb6d245 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py @@ -1,3 +1,6 @@ +import ifcopenshell.api + + class Usecase: def __init__(self, file, **settings): self.file = file @@ -6,4 +9,27 @@ class Usecase: self.settings[key] = value def execute(self): + for role in self.settings["person"].Roles or []: + if len(self.file.get_inverse(role)) == 1: + ifcopenshell.api.run("owner.remove_role", self.file, role=role) + for address in self.settings["person"].Addresses or []: + if len(self.file.get_inverse(address)) == 1: + ifcopenshell.api.run("owner.remove_address", self.file, address=address) + for inverse in self.file.get_inverse(self.settings["person"]): + if inverse.is_a("IfcWorkControl"): + if inverse.Creators == (self.settings["person"],): + inverse.Creators = None + elif inverse.is_a("IfcInventory"): + if inverse.ResponsiblePersons == (self.settings["person"],): + inverse.ResponsiblePersons = None + elif inverse.is_a("IfcDocumentInformation"): + if inverse.Editors == (self.settings["person"],): + inverse.Editors = None + elif inverse.is_a("IfcPersonAndOrganization"): + ifcopenshell.api.run("owner.remove_person_and_organisation", self.file, person_and_organisation=inverse) + elif inverse.is_a("IfcActor"): + ifcopenshell.api.run("owner.remove_actor", self.file, actor=inverse) + elif inverse.is_a("IfcResourceLevelRelationship"): + if inverse.RelatedResourceObjects == (self.settings["person"],): + self.file.remove(inverse) self.file.remove(self.settings["person"]) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person_and_organisation.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person_and_organisation.py new file mode 100644 index 0000000000..b2b86b24d7 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person_and_organisation.py @@ -0,0 +1,9 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"person_and_organisation": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + self.file.remove(self.settings["person_and_organisation"]) diff --git a/src/ifcopenshell-python/test/api/owner/test_edit_address.py b/src/ifcopenshell-python/test/api/owner/test_edit_address.py new file mode 100644 index 0000000000..6b288f74b2 --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_edit_address.py @@ -0,0 +1,52 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestEditAddress(test.bootstrap.IFC4): + def test_editing_a_postal_address(self): + address = self.file.createIfcPostalAddress() + ifcopenshell.api.run("owner.edit_address", self.file, address=address, attributes={ + "Purpose": "OFFICE", + "Description": "Description", + "UserDefinedPurpose": "UserDefinedPurpose", + "InternalLocation": "InternalLocation", + "AddressLines": ["Address", "Lines"], + "PostalBox": "PostalBox", + "Town": "Town", + "Region": "Region", + "PostalCode": "PostalCode", + "Country": "Country", + }) + assert address.Purpose == "OFFICE" + assert address.Description == "Description" + assert address.UserDefinedPurpose == "UserDefinedPurpose" + assert address.InternalLocation == "InternalLocation" + assert address.AddressLines == ("Address", "Lines") + assert address.PostalBox == "PostalBox" + assert address.Town == "Town" + assert address.Region == "Region" + assert address.PostalCode == "PostalCode" + assert address.Country == "Country" + + def test_editing_a_telecom_address(self): + address = self.file.createIfcTelecomAddress() + ifcopenshell.api.run("owner.edit_address", self.file, address=address, attributes={ + "Purpose": "OFFICE", + "Description": "Description", + "UserDefinedPurpose": "UserDefinedPurpose", + "TelephoneNumbers": ["Telephone", "Numbers"], + "FacsimileNumbers": ["Facsimile", "Numbers"], + "PagerNumber": "PagerNumber", + "ElectronicMailAddresses": ["Electronic", "Mail", "Addresses"], + "WWWHomePageURL": "WWWHomePageURL", + "MessagingIDs": ["Messaging", "IDs"], + }) + assert address.Purpose == "OFFICE" + assert address.Description == "Description" + assert address.UserDefinedPurpose == "UserDefinedPurpose" + assert address.TelephoneNumbers == ("Telephone", "Numbers") + assert address.FacsimileNumbers == ("Facsimile", "Numbers") + assert address.PagerNumber == "PagerNumber" + assert address.ElectronicMailAddresses == ("Electronic", "Mail", "Addresses") + assert address.WWWHomePageURL == "WWWHomePageURL" + assert address.MessagingIDs == ("Messaging", "IDs") diff --git a/src/ifcopenshell-python/test/api/owner/test_edit_organisation.py b/src/ifcopenshell-python/test/api/owner/test_edit_organisation.py new file mode 100644 index 0000000000..94c6783210 --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_edit_organisation.py @@ -0,0 +1,15 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestEditOrganisation(test.bootstrap.IFC4): + def test_editing_a_organisation(self): + organisation = self.file.createIfcOrganization() + ifcopenshell.api.run("owner.edit_organisation", self.file, organisation=organisation, attributes={ + "Identification": "Identification", + "Name": "Name", + "Description": "Description", + }) + assert organisation.Identification == "Identification" + assert organisation.Name == "Name" + assert organisation.Description == "Description" diff --git a/src/ifcopenshell-python/test/api/owner/test_edit_person.py b/src/ifcopenshell-python/test/api/owner/test_edit_person.py new file mode 100644 index 0000000000..57ed922f9c --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_edit_person.py @@ -0,0 +1,21 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestEditPerson(test.bootstrap.IFC4): + def test_editing_a_person(self): + person = self.file.createIfcPerson() + ifcopenshell.api.run("owner.edit_person", self.file, person=person, attributes={ + "Identification": "Identification", + "FamilyName": "FamilyName", + "GivenName": "GivenName", + "MiddleNames": ["Middle", "Names"], + "PrefixTitles": ["Prefix", "Titles"], + "SuffixTitles": ["Suffix", "Titles"], + }) + assert person.Identification == "Identification" + assert person.FamilyName == "FamilyName" + assert person.GivenName == "GivenName" + assert person.MiddleNames == ("Middle", "Names") + assert person.PrefixTitles == ("Prefix", "Titles") + assert person.SuffixTitles == ("Suffix", "Titles") diff --git a/src/ifcopenshell-python/test/api/owner/test_edit_role.py b/src/ifcopenshell-python/test/api/owner/test_edit_role.py new file mode 100644 index 0000000000..9f2fb675a1 --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_edit_role.py @@ -0,0 +1,15 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestEditRole(test.bootstrap.IFC4): + def test_editing_a_role(self): + role = self.file.createIfcActorRole() + ifcopenshell.api.run("owner.edit_role", self.file, role=role, attributes={ + "Role": "ARCHITECT", + "UserDefinedRole": "UserDefinedRole", + "Description": "Description" + }) + assert role.Role == "ARCHITECT" + assert role.UserDefinedRole == "UserDefinedRole" + assert role.Description == "Description" diff --git a/src/ifcopenshell-python/test/api/owner/test_remove_address.py b/src/ifcopenshell-python/test/api/owner/test_remove_address.py new file mode 100644 index 0000000000..ec21b0d6bf --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_remove_address.py @@ -0,0 +1,11 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestRemoveAddress(test.bootstrap.IFC4): + def test_removing_an_address(self): + postal = self.file.createIfcPostalAddress() + telecom = self.file.createIfcTelecomAddress() + ifcopenshell.api.run("owner.remove_address", self.file, address=postal) + ifcopenshell.api.run("owner.remove_address", self.file, address=telecom) + assert len(self.file.by_type("IfcAddress")) == 0 diff --git a/src/ifcopenshell-python/test/api/owner/test_remove_person.py b/src/ifcopenshell-python/test/api/owner/test_remove_person.py new file mode 100644 index 0000000000..55075eb17b --- /dev/null +++ b/src/ifcopenshell-python/test/api/owner/test_remove_person.py @@ -0,0 +1,82 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestRemovePerson(test.bootstrap.IFC4): + def test_removing_a_person(self): + person = self.file.createIfcPerson() + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcPerson")) == 0 + + def test_removing_roles_and_addresses_only_used_by_the_person(self): + role = self.file.createIfcActorRole() + address = self.file.createIfcPostalAddress() + person = self.file.createIfcPerson() + person.Roles = [role] + person.Addresses = [address] + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcPerson")) == 0 + assert len(self.file.by_type("IfcActorRole")) == 0 + assert len(self.file.by_type("IfcPostalAddress")) == 0 + + def test_not_removing_roles_and_addresses_used_elsewhere(self): + role = self.file.createIfcActorRole() + address = self.file.createIfcPostalAddress() + person = self.file.createIfcPerson() + person2 = self.file.createIfcPerson() + person.Roles = [role] + person.Addresses = [address] + person2.Roles = [role] + person2.Addresses = [address] + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcPerson")) == 1 + assert len(self.file.by_type("IfcActorRole")) == 1 + assert len(self.file.by_type("IfcPostalAddress")) == 1 + + def test_ensuring_work_controls_should_not_be_left_in_an_invalid_set_cardinality(self): + person = self.file.createIfcPerson() + work_control = self.file.createIfcWorkControl(Creators=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert work_control.Creators is None + + def test_ensuring_inventory_should_not_be_left_in_an_invalid_set_cardinality(self): + person = self.file.createIfcPerson() + inventory = self.file.createIfcInventory(ResponsiblePersons=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert inventory.ResponsiblePersons is None + + def test_deleting_person_and_organisations(self): + person = self.file.createIfcPerson() + self.file.createIfcPersonAndOrganization(ThePerson=person) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcPersonAndOrganization")) == 0 + + def test_deleting_actors(self): + person = self.file.createIfcPerson() + self.file.createIfcActor(GlobalId=ifcopenshell.guid.new(), TheActor=person) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcActor")) == 0 + + def test_ensuring_document_information_should_not_be_left_in_an_invalid_set_cardinality(self): + person = self.file.createIfcPerson() + document_information = self.file.createIfcDocumentInformation(Editors=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert document_information.Editors is None + + def test_deleting_resource_approval_relationships(self): + person = self.file.createIfcPerson() + self.file.createIfcResourceApprovalRelationship(RelatedResourceObjects=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcResourceApprovalRelationship")) == 0 + + def test_deleting_resource_constraint_relationships(self): + person = self.file.createIfcPerson() + self.file.createIfcResourceConstraintRelationship(RelatedResourceObjects=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcResourceConstraintRelationship")) == 0 + + def test_deleting_external_reference_relationships(self): + person = self.file.createIfcPerson() + self.file.createIfcExternalReferenceRelationship(RelatedResourceObjects=[person]) + ifcopenshell.api.run("owner.remove_person", self.file, person=person) + assert len(self.file.by_type("IfcExternalReferenceRelationship")) == 0