sequence.remove_task to remove IfcRecurrencePattern

This commit is contained in:
Andrej730
2024-06-10 14:01:52 +05:00
parent d56da70cae
commit 6552463ed9
3 changed files with 26 additions and 3 deletions
@@ -19,6 +19,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.nest import ifcopenshell.api.nest
import ifcopenshell.api.sequence
import ifcopenshell.util.element import ifcopenshell.util.element
@@ -63,8 +64,10 @@ def remove_task(file: ifcopenshell.file, task: ifcopenshell.entity_instance) ->
definitions=[settings["task"]], definitions=[settings["task"]],
relating_context=file.by_type("IfcContext")[0], relating_context=file.by_type("IfcContext")[0],
) )
if settings["task"].TaskTime: if task_time := settings["task"].TaskTime:
file.remove(settings["task"].TaskTime) if task_time.is_a("IfcTaskTimeRecurring"):
ifcopenshell.api.sequence.unassign_recurrence_pattern(file, task_time.Recurrence)
file.remove(task_time)
# Handle IfcRelNests. # Handle IfcRelNests.
if rels := settings["task"].IsNestedBy: if rels := settings["task"].IsNestedBy:
@@ -22,7 +22,10 @@ def unassign_recurrence_pattern(file: ifcopenshell.file, recurrence_pattern: ifc
"""Unassigns a recurrence pattern """Unassigns a recurrence pattern
Note that a recurring task time must have a recurrence pattern, so if Note that a recurring task time must have a recurrence pattern, so if
you remove it, be sure to clean up after your you remove it, be sure to clean up after this API call
(e.g. remove IfcTaskTimeRecurring entity
or assign a different recurrence patern to it
or replace IfcTaskTimeRecurring with IfcTaskTime).
:param recurrence_pattern: The IfcRecurrencePattern to remove. :param recurrence_pattern: The IfcRecurrencePattern to remove.
:type recurrence_pattern: ifcopenshell.entity_instance :type recurrence_pattern: ifcopenshell.entity_instance
@@ -33,6 +33,23 @@ class TestRemoveTask(test.bootstrap.IFC4):
ifcopenshell.api.sequence.remove_task(self.file, task) ifcopenshell.api.sequence.remove_task(self.file, task)
assert len(self.file.by_type("IfcTask")) == 0 assert len(self.file.by_type("IfcTask")) == 0
def test_remove_task_times(self):
self.file.create_entity("IfcProject")
task = ifcopenshell.api.sequence.add_task(self.file)
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task, is_recurring=True)
ifcopenshell.api.sequence.assign_recurrence_pattern(self.file, task_time, recurrence_type="DAILY")
task2 = ifcopenshell.api.sequence.add_task(self.file)
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task2, is_recurring=False)
ifcopenshell.api.sequence.remove_task(self.file, task)
ifcopenshell.api.sequence.remove_task(self.file, task2)
assert len(self.file.by_type("IfcTask")) == 0
assert len(self.file.by_type("IfcTaskTime")) == 0
assert len(self.file.by_type("IfcRecurrencePattern")) == 0
def test_remove_task_with_subtasks(self): def test_remove_task_with_subtasks(self):
self.file.create_entity("IfcProject") self.file.create_entity("IfcProject")
work_schedule = ifcopenshell.api.sequence.add_work_schedule(self.file) work_schedule = ifcopenshell.api.sequence.add_work_schedule(self.file)