From 551f3b0d8d03923d1a6866573e7b798c66418aba Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 20 Feb 2024 12:34:05 +0500 Subject: [PATCH] Fix issues editing work time in ifc4x3 #4295 --- .../blenderbim/bim/module/sequence/data.py | 8 +- .../api/sequence/edit_work_time.py | 4 +- .../ifcopenshell/util/attribute_4x3_to_4.json | 4 + .../test/api/sequence/test_edit_work_time.py | 82 +++++++++++++++++++ 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 src/ifcopenshell-python/test/api/sequence/test_edit_work_time.py diff --git a/src/blenderbim/blenderbim/bim/module/sequence/data.py b/src/blenderbim/blenderbim/bim/module/sequence/data.py index e261801fcc..239c99bf9d 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/data.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/data.py @@ -128,8 +128,12 @@ class SequenceData: cls.data["work_times"] = {} for work_time in tool.Ifc.get().by_type("IfcWorkTime"): data = work_time.get_info() - data["Start"] = ifcopenshell.util.date.ifc2datetime(data["Start"]) if data["Start"] else None - data["Finish"] = ifcopenshell.util.date.ifc2datetime(data["Finish"]) if data["Finish"] else None + if tool.Ifc.get_schema() == "IFC4X3": + start_date, finish_date = data["StartDate"], data["FinishDate"] + else: + start_date, finish_date = data["Start"], data["Finish"] + data["Start"] = ifcopenshell.util.date.ifc2datetime(start_date) if start_date else None + data["Finish"] = ifcopenshell.util.date.ifc2datetime(finish_date) if finish_date else None data["RecurrencePattern"] = work_time.RecurrencePattern.id() if work_time.RecurrencePattern else None cls.data["work_times"][work_time.id()] = data diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_work_time.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_work_time.py index 4938a35504..6d867155b0 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_work_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_work_time.py @@ -55,8 +55,8 @@ class Usecase: def execute(self): for name, value in self.settings["attributes"].items(): - if value and name in ["Start", "Finish"]: + if value and name in ("Start", "Finish", "StartDate", "FinishDate"): value = ifcopenshell.util.date.datetime2ifc(value, "IfcDate") - if self.file.schema == "IFC4X3": + if self.file.schema == "IFC4X3" and name in ("Start", "Finish"): name += "Date" setattr(self.settings["work_time"], name, value) diff --git a/src/ifcopenshell-python/ifcopenshell/util/attribute_4x3_to_4.json b/src/ifcopenshell-python/ifcopenshell/util/attribute_4x3_to_4.json index cdc9944ac7..8511849371 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/attribute_4x3_to_4.json +++ b/src/ifcopenshell-python/ifcopenshell/util/attribute_4x3_to_4.json @@ -19,5 +19,9 @@ }, "IfcComplexProperty": { "Specification": "Description" + }, + "IfcWorkTime": { + "StartDate": "Start", + "FinishDate": "Finish" } } diff --git a/src/ifcopenshell-python/test/api/sequence/test_edit_work_time.py b/src/ifcopenshell-python/test/api/sequence/test_edit_work_time.py new file mode 100644 index 0000000000..4ce8d3389b --- /dev/null +++ b/src/ifcopenshell-python/test/api/sequence/test_edit_work_time.py @@ -0,0 +1,82 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import datetime +import test.bootstrap +import ifcopenshell.api + + +class TestEditWorkTime(test.bootstrap.IFC4): + def test_run(self): + work_time = self.file.createIfcWorkTime() + recurrence_pattern = self.file.createIfcRecurrencePattern() + attributes = { + "Name": "Test", + "DataOrigin": "USERDEFINED", + "UserDefinedDataOrigin": "Custom", + "RecurrencePattern": recurrence_pattern, + "Start": datetime.datetime(2020, 1, 1), + "Finish": datetime.datetime(2020, 2, 1), + } + ifcopenshell.api.run("sequence.edit_work_time", self.file, work_time=work_time, attributes=attributes) + assert work_time.Name == attributes["Name"] + assert work_time.DataOrigin == attributes["DataOrigin"] + assert work_time.UserDefinedDataOrigin == attributes["UserDefinedDataOrigin"] + assert work_time.RecurrencePattern == attributes["RecurrencePattern"] + assert work_time.Start == "2020-01-01" + assert work_time.Finish == "2020-02-01" + + +class TestEditWorkTimeIFC4X3(test.bootstrap.IFC4X3): + def test_run(self): + work_time = self.file.createIfcWorkTime() + recurrence_pattern = self.file.createIfcRecurrencePattern() + attributes = { + "Name": "Test", + "DataOrigin": "USERDEFINED", + "UserDefinedDataOrigin": "Custom", + "RecurrencePattern": recurrence_pattern, + "StartDate": datetime.datetime(2020, 1, 1), + "FinishDate": datetime.datetime(2020, 2, 1), + } + ifcopenshell.api.run("sequence.edit_work_time", self.file, work_time=work_time, attributes=attributes) + assert work_time.Name == attributes["Name"] + assert work_time.DataOrigin == attributes["DataOrigin"] + assert work_time.UserDefinedDataOrigin == attributes["UserDefinedDataOrigin"] + assert work_time.RecurrencePattern == attributes["RecurrencePattern"] + assert work_time.StartDate == "2020-01-01" + assert work_time.FinishDate == "2020-02-01" + + def test_ifc4_code_to_work_in_ifc4x3(self): + work_time = self.file.createIfcWorkTime() + recurrence_pattern = self.file.createIfcRecurrencePattern() + attributes = { + "Name": "Test", + "DataOrigin": "USERDEFINED", + "UserDefinedDataOrigin": "Custom", + "RecurrencePattern": recurrence_pattern, + "Start": datetime.datetime(2020, 1, 1), + "Finish": datetime.datetime(2020, 2, 1), + } + ifcopenshell.api.run("sequence.edit_work_time", self.file, work_time=work_time, attributes=attributes) + assert work_time.Name == attributes["Name"] + assert work_time.DataOrigin == attributes["DataOrigin"] + assert work_time.UserDefinedDataOrigin == attributes["UserDefinedDataOrigin"] + assert work_time.RecurrencePattern == attributes["RecurrencePattern"] + assert work_time.StartDate == "2020-01-01" + assert work_time.FinishDate == "2020-02-01"