From 15112211c1f8ff1502a5d4716b3938cda24b8fab Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 16 Jun 2025 19:52:51 +0500 Subject: [PATCH] add_application not to add deprecated IfcTelecomAddress in ifc4x3 #6806 --- .../ifcopenshell/api/owner/add_application.py | 36 +++++++++++++------ .../test/api/owner/test_add_application.py | 30 ++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/add_application.py b/src/ifcopenshell-python/ifcopenshell/api/owner/add_application.py index 5c86ab78d3..665bebc292 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/add_application.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/add_application.py @@ -17,6 +17,8 @@ # along with IfcOpenShell. If not, see . import ifcopenshell.api +import ifcopenshell.api.owner +import ifcopenshell.api.pset from typing import Optional, Any, Union @@ -90,18 +92,32 @@ class Usecase: "Roles": [ self.file.create_entity("IfcActorRole", **{"Role": "USERDEFINED", "UserDefinedRole": "CONTRIBUTOR"}) ], - "Addresses": [ - self.file.create_entity( - "IfcTelecomAddress", - **{ - "Purpose": "USERDEFINED", - "UserDefinedPurpose": "WEBPAGE", - "WWWHomePageURL": "https://ifcopenshell.org", - }, - ), - ], }, ) # 0 IfcOrganization.Identification / Id (IFC2X3). result[0] = "IfcOpenShell" + + # 4 IfcOrganization.Addresses + if self.file.schema == "IFC4X3": + # IfcTelecomAddress is deprecated in IFC4X3. + actor = ifcopenshell.api.owner.add_actor(self.file, result) + pset = ifcopenshell.api.pset.add_pset(self.file, actor, "PEnum_AddressType") + ifcopenshell.api.pset.edit_pset( + self.file, + pset, + properties={ + "Purpose": "OTHER", + "UserDefinedPurpose": "WEBPAGE", + "WWWHomePageURL": "https://ifcopenshell.org", + }, + ) + else: + result[4] = [ + self.file.create_entity( + "IfcTelecomAddress", + Purpose="USERDEFINED", + UserDefinedPurpose="WEBPAGE", + WWWHomePageURL="https://ifcopenshell.org", + ), + ] return result diff --git a/src/ifcopenshell-python/test/api/owner/test_add_application.py b/src/ifcopenshell-python/test/api/owner/test_add_application.py index 5a806160d5..77890c19cf 100644 --- a/src/ifcopenshell-python/test/api/owner/test_add_application.py +++ b/src/ifcopenshell-python/test/api/owner/test_add_application.py @@ -18,6 +18,7 @@ import test.bootstrap import ifcopenshell.api.owner +import ifcopenshell.util.element class TestAddApplication(test.bootstrap.IFC4): @@ -45,3 +46,32 @@ class TestAddApplication(test.bootstrap.IFC4): class TestAddApplicationIFC2X3(test.bootstrap.IFC2X3, TestAddApplication): pass + + +class TestAddApplicationIFC4X3(test.bootstrap.IFC4X3, TestAddApplication): + def test_adding_the_ifcopenshell_application(self): + application = ifcopenshell.api.owner.add_application(self.file) + developer = application.ApplicationDeveloper + assert application.Version == ifcopenshell.version + assert application.ApplicationFullName == "IfcOpenShell" + assert application.ApplicationIdentifier == "IfcOpenShell" + assert developer.is_a("IfcOrganization") + + # 0 IfcOrganization Identification(>IFC2X3) / Id (IFC2X3) + assert developer[0] == "IfcOpenShell" + assert developer.Name == "IfcOpenShell" + assert ( + developer.Description + == "IfcOpenShell is an open source software library that helps users and software developers to work with IFC data." + ) + assert developer.Roles[0].Role == "USERDEFINED" + assert developer.Roles[0].UserDefinedRole == "CONTRIBUTOR" + assert developer.Addresses == None + + assert (actors := self.file.by_type("IfcActor")) + actor = actors[0] + assert actor.TheActor == developer + assert (pset_data := ifcopenshell.util.element.get_pset(actor, "PEnum_AddressType")) + assert pset_data["Purpose"] == "OTHER" + assert pset_data["UserDefinedPurpose"] == "WEBPAGE" + assert pset_data["WWWHomePageURL"] == "https://ifcopenshell.org"