mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Fix issues editing work time in ifc4x3 #4295
This commit is contained in:
@@ -128,8 +128,12 @@ class SequenceData:
|
|||||||
cls.data["work_times"] = {}
|
cls.data["work_times"] = {}
|
||||||
for work_time in tool.Ifc.get().by_type("IfcWorkTime"):
|
for work_time in tool.Ifc.get().by_type("IfcWorkTime"):
|
||||||
data = work_time.get_info()
|
data = work_time.get_info()
|
||||||
data["Start"] = ifcopenshell.util.date.ifc2datetime(data["Start"]) if data["Start"] else None
|
if tool.Ifc.get_schema() == "IFC4X3":
|
||||||
data["Finish"] = ifcopenshell.util.date.ifc2datetime(data["Finish"]) if data["Finish"] else None
|
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
|
data["RecurrencePattern"] = work_time.RecurrencePattern.id() if work_time.RecurrencePattern else None
|
||||||
cls.data["work_times"][work_time.id()] = data
|
cls.data["work_times"][work_time.id()] = data
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ class Usecase:
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
for name, value in self.settings["attributes"].items():
|
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")
|
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDate")
|
||||||
if self.file.schema == "IFC4X3":
|
if self.file.schema == "IFC4X3" and name in ("Start", "Finish"):
|
||||||
name += "Date"
|
name += "Date"
|
||||||
setattr(self.settings["work_time"], name, value)
|
setattr(self.settings["work_time"], name, value)
|
||||||
|
|||||||
@@ -19,5 +19,9 @@
|
|||||||
},
|
},
|
||||||
"IfcComplexProperty": {
|
"IfcComplexProperty": {
|
||||||
"Specification": "Description"
|
"Specification": "Description"
|
||||||
|
},
|
||||||
|
"IfcWorkTime": {
|
||||||
|
"StartDate": "Start",
|
||||||
|
"FinishDate": "Finish"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
# IfcOpenShell - IFC toolkit and geometry engine
|
||||||
|
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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"
|
||||||
Reference in New Issue
Block a user