mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -19,53 +19,50 @@
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, organisation=None):
|
||||
"""Remove an organisation
|
||||
def remove_organisation(file, organisation=None) -> None:
|
||||
"""Remove an organisation
|
||||
|
||||
All roles and addresses assigned to the organisation will also be
|
||||
removed.
|
||||
All roles and addresses assigned to the organisation will also be
|
||||
removed.
|
||||
|
||||
:param organisation: The IfcOrganization to remove
|
||||
:type organisation: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param organisation: The IfcOrganization to remove
|
||||
:type organisation: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
organisation = ifcopenshell.api.run("owner.add_organisation", model,
|
||||
identification="AWB", name="Architects Without Ballpens")
|
||||
ifcopenshell.api.run("owner.remove_organisation", model, organisation=organisation)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"organisation": organisation}
|
||||
organisation = ifcopenshell.api.run("owner.add_organisation", model,
|
||||
identification="AWB", name="Architects Without Ballpens")
|
||||
ifcopenshell.api.run("owner.remove_organisation", model, organisation=organisation)
|
||||
"""
|
||||
settings = {"organisation": organisation}
|
||||
|
||||
def execute(self):
|
||||
for role in self.settings["organisation"].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["organisation"].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["organisation"]):
|
||||
if inverse.is_a("IfcOrganizationRelationship"):
|
||||
if inverse.RelatingOrganization == self.settings["organisation"]:
|
||||
self.file.remove(inverse)
|
||||
elif inverse.RelatedOrganizations == (self.settings["organisation"],):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcDocumentInformation"):
|
||||
if inverse.Editors == (self.settings["organisation"],):
|
||||
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("root.remove_product", self.file, product=inverse)
|
||||
elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"):
|
||||
if inverse.RelatedResourceObjects == (self.settings["organisation"],):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcApplication"):
|
||||
ifcopenshell.api.run("owner.remove_application", self.file, application=inverse)
|
||||
for role in settings["organisation"].Roles or []:
|
||||
if len(file.get_inverse(role)) == 1:
|
||||
ifcopenshell.api.run("owner.remove_role", file, role=role)
|
||||
for address in settings["organisation"].Addresses or []:
|
||||
if len(file.get_inverse(address)) == 1:
|
||||
ifcopenshell.api.run("owner.remove_address", file, address=address)
|
||||
for inverse in file.get_inverse(settings["organisation"]):
|
||||
if inverse.is_a("IfcOrganizationRelationship"):
|
||||
if inverse.RelatingOrganization == settings["organisation"]:
|
||||
file.remove(inverse)
|
||||
elif inverse.RelatedOrganizations == (settings["organisation"],):
|
||||
file.remove(inverse)
|
||||
elif inverse.is_a("IfcDocumentInformation"):
|
||||
if inverse.Editors == (settings["organisation"],):
|
||||
inverse.Editors = None
|
||||
elif inverse.is_a("IfcPersonAndOrganization"):
|
||||
ifcopenshell.api.run("owner.remove_person_and_organisation", file, person_and_organisation=inverse)
|
||||
elif inverse.is_a("IfcActor"):
|
||||
ifcopenshell.api.run("root.remove_product", file, product=inverse)
|
||||
elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"):
|
||||
if inverse.RelatedResourceObjects == (settings["organisation"],):
|
||||
file.remove(inverse)
|
||||
elif inverse.is_a("IfcApplication"):
|
||||
ifcopenshell.api.run("owner.remove_application", file, application=inverse)
|
||||
|
||||
self.file.remove(self.settings["organisation"])
|
||||
file.remove(settings["organisation"])
|
||||
|
||||
Reference in New Issue
Block a user