sequence.copy_work_schedule #6901

Similar to e50215ddc but for IfcWorkSchedules

Button location - https://files.catbox.moe/jfd1ol.png
This commit is contained in:
Andrej730
2025-07-24 19:25:36 +05:00
parent f5b28c0df8
commit b76b05fc71
11 changed files with 135 additions and 3 deletions
@@ -38,6 +38,7 @@ from .assign_sequence import assign_sequence
from .assign_work_plan import assign_work_plan
from .calculate_task_duration import calculate_task_duration
from .cascade_schedule import cascade_schedule
from .copy_work_schedule import copy_work_schedule
from .create_baseline import create_baseline
from .duplicate_task import duplicate_task
from .edit_lag_time import edit_lag_time
@@ -84,6 +85,7 @@ __all__ = [
"assign_work_plan",
"calculate_task_duration",
"cascade_schedule",
"copy_work_schedule",
"create_baseline",
"duplicate_task",
"edit_lag_time",
@@ -0,0 +1,51 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 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 ifcopenshell.api.control
import ifcopenshell.api.sequence
import ifcopenshell.util.element
def copy_work_schedule(
file: ifcopenshell.file,
work_schedule: ifcopenshell.entity_instance,
) -> ifcopenshell.entity_instance:
"""Copy a work schedule.
:param work_schedule: IfcWorkSchedule to copy.
:return: The duplicated IfcWorkSchedule entity.
Example:
.. code:: python
work_plan = ifcopenshell.api.sequence.add_work_plan(model, name="Construction")
schedule = ifcopenshell.api.sequence.add_work_schedule(model,
name="Construction Schedule A", work_plan=work_plan)
new_schedule = ifcopenshell.api.sequence.copy_work_schedule(model, schedule)
"""
# Shared code logic with copy_cost_schedule.
new_schedule = ifcopenshell.util.element.copy(file, work_schedule)
for rel in work_schedule.Controls:
for task in rel.RelatedObjects:
duplicated_tasks = ifcopenshell.api.sequence.duplicate_task(file, task)[1]
# All other nested items are not connected to the work schedule explicitly.
duplicated_task = duplicated_tasks[0]
ifcopenshell.api.control.assign_control(file, new_schedule, duplicated_task)
return new_schedule
@@ -27,6 +27,7 @@ import ifcopenshell.util.sequence
from typing import Union, Any
# TODO: inconsistent name with other copy_xxx api methods.
def duplicate_task(
file: ifcopenshell.file, task: ifcopenshell.entity_instance
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]]:
@@ -58,7 +59,7 @@ def duplicate_task(
class Usecase:
file: ifcopenshell.file
settings: dict[str, Any]
settings: dict[str, list[ifcopenshell.entity_instance]]
def execute(self):
self.tracker = {"current": [], "duplicate": []}
@@ -66,14 +67,16 @@ class Usecase:
self.copy_sequence_relationship(self.tracker["current"], self.tracker["duplicate"])
return self.tracker["current"], self.tracker["duplicate"]
def duplicate_task(self, task):
def duplicate_task(self, task: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
new_task = ifcopenshell.util.element.copy_deep(self.file, task)
self.tracker["current"].append(task)
self.tracker["duplicate"].append(new_task)
self.copy_indirect_attributes(task, new_task)
return new_task
def copy_indirect_attributes(self, from_element, to_element):
def copy_indirect_attributes(
self, from_element: ifcopenshell.entity_instance, to_element: ifcopenshell.entity_instance
) -> None:
for inverse in self.file.get_inverse(from_element):
if inverse.is_a("IfcRelDefinesByProperties"):
inverse = ifcopenshell.util.element.copy(self.file, inverse)