This commit is contained in:
Andrej730
2025-03-14 10:43:47 +05:00
parent 10ecac33b8
commit 0e8810c1f5
118 changed files with 869 additions and 1203 deletions
@@ -49,11 +49,8 @@ def add_actor(
IfcPerson if it is a sole individual, or an IfcPersonAndOrganization
if a specific person is liable within an organisation and must be
legally nominated.
:type actor: ifcopenshell.entity_instance
:param ifc_class: Either "IfcActor" or "IfcOccupant".
:type ifc_class: str, optional
:return: The newly created IfcActor or IfcOccupant
:rtype: ifcopenshell.entity_instance
Example:
@@ -67,8 +64,7 @@ def add_actor(
# Assign that organisation to a newly created actor
actor = ifcopenshell.api.owner.add_actor(model, actor=organisation)
"""
settings = {"actor": actor, "ifc_class": ifc_class or "IfcActor"}
actor = ifcopenshell.api.root.create_entity(file, ifc_class=settings["ifc_class"])
actor.TheActor = settings["actor"]
return actor
ifc_class = ifc_class or "IfcActor"
actor_ = ifcopenshell.api.root.create_entity(file, ifc_class=ifc_class)
actor_.TheActor = actor
return actor_
@@ -39,12 +39,9 @@ def add_address(
:param assigned_object: The IfcOrganization or IfcPerson the contact
address belongs to.
:type assigned_object: ifcopenshell.entity_instance
:param ifc_class: Either IfcPostalAddress or IfcTelecomAddress. Defaults
to IfcPostalAddress.
:type ifc_class: str, optional
:return: The new IfcPostalAddress or IfcTelecomAddress
:rtype: ifcopenshell.entity_instance
Example:
@@ -67,10 +64,8 @@ def add_address(
"ElectronicMailAddresses": ["bobthebuilder@example.com"],
"WWWHomePageURL": "https://thinkmoult.com"})
"""
settings = {"assigned_object": assigned_object, "ifc_class": ifc_class}
address = file.create_entity(settings["ifc_class"], "OFFICE")
addresses = list(settings["assigned_object"].Addresses) if settings["assigned_object"].Addresses else []
address = file.create_entity(ifc_class, "OFFICE")
addresses = list(assigned_object.Addresses) if assigned_object.Addresses else []
addresses.append(address)
settings["assigned_object"].Addresses = addresses
assigned_object.Addresses = addresses
return address
@@ -31,11 +31,8 @@ def add_organisation(
Sometimes used in drawing naming schemes. Otherise used as a
canonicalised way of computers to identify the organisation. Like
their stock name.
:type identification: str, optional
:param name: The legal name of the organisation
:type name: str, optional
:return: The newly created IfcOrganization
:rtype: ifcopenshell.entity_instance
Example:
@@ -44,11 +41,9 @@ def add_organisation(
organisation = ifcopenshell.api.owner.add_organisation(model,
identification="AWB", name="Architects Without Ballpens")
"""
settings = {"identification": identification, "name": name}
data = {"Name": settings["name"]}
data = {"Name": name}
if file.schema == "IFC2X3":
data["Id"] = settings["identification"]
data["Id"] = identification
else:
data["Identification"] = settings["identification"]
data["Identification"] = identification
return file.create_entity("IfcOrganization", **data)
@@ -31,13 +31,9 @@ def add_person(
:param identification: The computer readable unique identification of
the person. For example, their username in a CDE or alias.
:type identification: str, optional
:param family_name: The family name
:type family_name: str, optional
:param given_name: The given name
:type given_name: str, optional
:return: The newly created IfcPerson
:rtype: ifcopenshell.entity_instance
Example:
@@ -46,15 +42,9 @@ def add_person(
ifcopenshell.api.owner.add_person(model,
identification="bobthebuilder", family_name="Thebuilder", given_name="Bob")
"""
settings = {
"identification": identification,
"family_name": family_name,
"given_name": given_name,
}
data = {"FamilyName": settings["family_name"], "GivenName": settings["given_name"]}
data = {"FamilyName": family_name, "GivenName": given_name}
if file.schema == "IFC2X3":
data["Id"] = settings["identification"]
data["Id"] = identification
else:
data["Identification"] = settings["identification"]
data["Identification"] = identification
return file.create_entity("IfcPerson", **data)
@@ -30,11 +30,8 @@ def add_person_and_organisation(
:param person: The IfcPerson being the representative of the
organisation.
:type person: ifcopenshell.entity_instance
:param organisation: The IfcOrganization it
:type organisation: ifcopenshell.entity_instance
:return: The newly created IfcPersonAndOrganization
:rtype: ifcopenshell.entity_instance
Example:
@@ -48,6 +45,4 @@ def add_person_and_organisation(
ifcopenshell.api.owner.add_person_and_organisation(model,
person=person, organisation=organisation)
"""
settings = {"person": person, "organisation": organisation}
return file.createIfcPersonAndOrganization(settings["person"], settings["organisation"])
return file.create_entity("IfcPersonAndOrganization", person, organisation)
@@ -43,11 +43,8 @@ def assign_actor(
ifcopenshell.api.resource.assign_resource.
:param relating_actor: The IfcActor who is responsible for the object.
:type relating_actor: ifcopenshell.entity_instance
:param related_object: The object the actor is responsible for.
:type related_object: ifcopenshell.entity_instance
:return: The newly created IfcRelAssignsToActor relationship.
:rtype: ifcopenshell.entity_instance
Example:
@@ -74,24 +71,19 @@ def assign_actor(
ifcopenshell.api.owner.assign_actor(model,
relating_actor=manufacturer, related_object=pump_type)
"""
settings = {
"relating_actor": relating_actor,
"related_object": related_object,
}
if settings["related_object"].HasAssignments:
for rel in settings["related_object"].HasAssignments:
if rel.is_a("IfcRelAssignsToActor") and rel.RelatingActor == settings["relating_actor"]:
if related_object.HasAssignments:
for rel in related_object.HasAssignments:
if rel.is_a("IfcRelAssignsToActor") and rel.RelatingActor == relating_actor:
return rel
rel = None
if settings["relating_actor"].IsActingUpon:
rel = settings["relating_actor"].IsActingUpon[0]
if relating_actor.IsActingUpon:
rel = relating_actor.IsActingUpon[0]
if rel:
related_objects = list(rel.RelatedObjects)
related_objects.append(settings["related_object"])
related_objects.append(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
else:
@@ -100,8 +92,8 @@ def assign_actor(
**{
"GlobalId": ifcopenshell.guid.new(),
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
"RelatedObjects": [settings["related_object"]],
"RelatingActor": settings["relating_actor"],
"RelatedObjects": [related_object],
"RelatingActor": relating_actor,
}
)
return rel
@@ -24,9 +24,7 @@ def remove_actor(file: ifcopenshell.file, actor: ifcopenshell.entity_instance) -
"""Removes an actor
:param actor: The IfcActor to remove.
:type actor: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -44,9 +42,7 @@ def remove_actor(file: ifcopenshell.file, actor: ifcopenshell.entity_instance) -
# Actually we need ballpens on this project
ifcopenshell.api.owner.remove_actor(model, actor=actor)
"""
settings = {"actor": actor}
history = settings["actor"].OwnerHistory
file.remove(settings["actor"])
history = actor.OwnerHistory
file.remove(actor)
if history:
ifcopenshell.util.element.remove_deep2(file, history)
@@ -25,9 +25,7 @@ def remove_address(file: ifcopenshell.file, address: ifcopenshell.entity_instanc
relationship removed.
:param address: The IfcAddress to remove.
:type address: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -40,10 +38,8 @@ def remove_address(file: ifcopenshell.file, address: ifcopenshell.entity_instanc
# Change our mind and delete it
ifcopenshell.api.owner.remove_address(model, address=address)
"""
settings = {"address": address}
for inverse in file.get_inverse(settings["address"]):
for inverse in file.get_inverse(address):
if inverse.is_a() in ("IfcOrganization", "IfcPerson"):
if inverse.Addresses == (settings["address"],):
if inverse.Addresses == (address,):
inverse.Addresses = None
file.remove(settings["address"])
file.remove(address)
@@ -25,9 +25,7 @@ def remove_application(file: ifcopenshell.file, application: ifcopenshell.entity
Check whether or not the application is used anywhere prior to removal.
:param address: The IfcApplication to remove.
:type address: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -36,6 +34,4 @@ def remove_application(file: ifcopenshell.file, application: ifcopenshell.entity
application = ifcopenshell.api.owner.add_application(model)
ifcopenshell.api.owner.remove_address(model, application=application)
"""
settings = {"application": application}
file.remove(settings["application"])
file.remove(application)
@@ -28,9 +28,7 @@ def remove_person_and_organisation(
the "person and organisation" group.
:param person_and_organisation: The IfcPersonAndOrganization to remove.
:type person_and_organisation: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -46,17 +44,15 @@ def remove_person_and_organisation(
ifcopenshell.api.owner.remove_person_and_organisation(model, person_and_organisation=user)
"""
settings = {"person_and_organisation": person_and_organisation}
for inverse in file.get_inverse(settings["person_and_organisation"]):
for inverse in file.get_inverse(person_and_organisation):
if inverse.is_a("IfcDocumentInformation"):
if inverse.Editors == (settings["person_and_organisation"],):
if inverse.Editors == (person_and_organisation,):
inverse.Editors = None
elif inverse.is_a("IfcActor"):
ifcopenshell.api.root.remove_product(file, product=inverse)
elif inverse.is_a("IfcResourceLevelRelationship"):
if inverse.RelatedResourceObjects == (settings["person_and_organisation"],):
if inverse.RelatedResourceObjects == (person_and_organisation,):
file.remove(inverse)
elif inverse.is_a("IfcOwnerHistory"):
file.remove(inverse)
file.remove(settings["person_and_organisation"])
file.remove(person_and_organisation)
@@ -25,9 +25,7 @@ def remove_role(file: ifcopenshell.file, role: ifcopenshell.entity_instance) ->
leave some of them without roles.
:param role: The IfcActorRole to remove.
:type role: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -40,13 +38,11 @@ def remove_role(file: ifcopenshell.file, role: ifcopenshell.entity_instance) ->
# After running this, the organisation will have no role again
ifcopenshell.api.owner.remove_role(model, role=role)
"""
settings = {"role": role}
for inverse in file.get_inverse(settings["role"]):
for inverse in file.get_inverse(role):
if inverse.is_a() in ("IfcOrganization", "IfcPerson", "IfcPersonAndOrganization"):
if inverse.Roles == (settings["role"],):
if inverse.Roles == (role,):
inverse.Roles = None
elif inverse.is_a("IfcResourceLevelRelationship") and not inverse.is_a("IfcOrganizationRelationship"):
if inverse.RelatedResourceObjects == (settings["organisation"],):
if inverse.RelatedResourceObjects == (organisation,):
file.remove(inverse)
file.remove(settings["role"])
file.remove(role)
@@ -29,11 +29,8 @@ def unassign_actor(
This means that the actor is no longer responsible for the object.
:param relating_actor: The IfcActor who is responsible for the object.
:type relating_actor: ifcopenshell.entity_instance
:param related_object: The object the actor is responsible for.
:type related_object: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -55,13 +52,8 @@ def unassign_actor(
ifcopenshell.api.owner.unassign_actor(model,
relating_actor=manufacturer, related_object=pump_type)
"""
settings = {
"relating_actor": relating_actor,
"related_object": related_object,
}
for rel in settings["related_object"].HasAssignments or []:
if not rel.is_a("IfcRelAssignsToActor") or rel.RelatingActor != settings["relating_actor"]:
for rel in related_object.HasAssignments or []:
if not rel.is_a("IfcRelAssignsToActor") or rel.RelatingActor != relating_actor:
continue
if len(rel.RelatedObjects) == 1:
history = rel.OwnerHistory
@@ -70,6 +62,6 @@ def unassign_actor(
ifcopenshell.util.element.remove_deep2(file, history)
return
related_objects = list(rel.RelatedObjects)
related_objects.remove(settings["related_object"])
related_objects.remove(related_object)
rel.RelatedObjects = related_objects
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
@@ -59,9 +59,6 @@ def update_owner_history(
# API calls either.
ifcopenshell.api.attribute.edit_attributes(model, product=space, attributes={"Name": "Lobby"})
"""
settings = {"element": element}
element = settings["element"]
if not element.is_a("IfcRoot"):
return
user = ifcopenshell.api.owner.settings.get_user(file)