Fix bug where nested elements didn't show elements of the active task (only children)

This commit is contained in:
Dion Moult
2025-10-07 13:06:26 +11:00
parent 3aa5ddb070
commit cf61111386
3 changed files with 27 additions and 62 deletions
+8 -10
View File
@@ -512,14 +512,12 @@ class Sequence(bonsai.core.tool.Sequence):
@classmethod
def get_task_inputs(cls, task: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
props = cls.get_work_schedule_props()
is_deep = props.show_nested_inputs
return ifcopenshell.util.sequence.get_task_inputs(task, is_deep)
return ifcopenshell.util.sequence.get_task_inputs(task, is_recursive=props.show_nested_inputs)
@classmethod
def get_task_outputs(cls, task: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
props = cls.get_work_schedule_props()
is_deep = props.show_nested_outputs
return ifcopenshell.util.sequence.get_task_outputs(task, is_deep)
return ifcopenshell.util.sequence.get_task_outputs(task, is_recursive=props.show_nested_outputs)
@classmethod
def are_entities_same_class(cls, entities: list[ifcopenshell.entity_instance]) -> bool:
@@ -540,8 +538,7 @@ class Sequence(bonsai.core.tool.Sequence):
if not task:
return
props = cls.get_work_schedule_props()
is_deep = props.show_nested_resources
return ifcopenshell.util.sequence.get_task_resources(task, is_deep)
return ifcopenshell.util.sequence.get_task_resources(task, props.show_nested_resources)
@classmethod
def load_task_inputs(cls, inputs: list[ifcopenshell.entity_instance]) -> None:
@@ -1582,7 +1579,7 @@ class Sequence(bonsai.core.tool.Sequence):
@classmethod
def create_new_task_json(cls, task, json, type_map=None, baseline_schedule=None):
task_time = task.TaskTime
resources = ifcopenshell.util.sequence.get_task_resources(task, is_deep=False)
resources = ifcopenshell.util.sequence.get_task_resources(task, is_recursive=False)
string_resources = ""
resources_usage = ""
@@ -1689,8 +1686,8 @@ class Sequence(bonsai.core.tool.Sequence):
) -> list[ifcopenshell.entity_instance]:
products = []
for task in ifcopenshell.util.sequence.get_root_tasks(work_schedule):
products.extend(ifcopenshell.util.sequence.get_task_inputs(task, is_deep=True))
products.extend(ifcopenshell.util.sequence.get_task_outputs(task, is_deep=True))
products.extend(ifcopenshell.util.sequence.get_task_inputs(task, is_recursive=True))
products.extend(ifcopenshell.util.sequence.get_task_outputs(task, is_recursive=True))
return products
@classmethod
@@ -1794,7 +1791,8 @@ class Sequence(bonsai.core.tool.Sequence):
if not task:
return
bpy.ops.object.select_all(action="DESELECT")
for element in set(cls.get_task_inputs(task) + cls.get_task_outputs(task)):
props = cls.get_work_schedule_props()
for element in cls.get_task_inputs(task) | cls.get_task_outputs(task):
if obj := tool.Ifc.get_object(element):
obj.select_set(True)
@@ -143,7 +143,7 @@ class Usecase:
return next(e for e in self.file.get_inverse(self.task_time) if e.is_a("IfcTask"))
def handle_resource_calculation(self):
resources = ifcopenshell.util.sequence.get_task_resources(self.task, is_deep=False)
resources = ifcopenshell.util.sequence.get_task_resources(self.task, is_recursive=False)
for resource in resources:
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"):
ifcopenshell.api.resource.calculate_resource_usage(self.file, resource=resource)
@@ -329,61 +329,28 @@ def guess_date_range(work_schedule: ifcopenshell.entity_instance):
return earliest, latest
def get_direct_task_outputs(task: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
return [rel.RelatingProduct for rel in task.HasAssignments if rel.is_a("IfcRelAssignsToProduct")]
def get_task_outputs(
task: ifcopenshell.entity_instance, is_recursive: bool = False
) -> set[ifcopenshell.entity_instance]:
if is_recursive:
return {o for subtask in [task] + list(get_all_nested_tasks(task)) for o in get_task_outputs(subtask)}
return {rel.RelatingProduct for rel in task.HasAssignments if rel.is_a("IfcRelAssignsToProduct")}
def get_task_outputs(task: ifcopenshell.entity_instance, is_deep: bool = False) -> list[ifcopenshell.entity_instance]:
if not is_deep:
return get_direct_task_outputs(task)
else:
return [output for nested_task in get_all_nested_tasks(task) for output in get_direct_task_outputs(nested_task)]
def get_task_inputs(
task: ifcopenshell.entity_instance, is_recursive: bool = False
) -> set[ifcopenshell.entity_instance]:
if is_recursive:
return {o for subtask in [task] + list(get_all_nested_tasks(task)) for o in get_task_inputs(subtask)}
return {o for rel in task.OperatesOn for o in rel.RelatedObjects if o.is_a("IfcProduct")}
def get_task_inputs(task: ifcopenshell.entity_instance, is_deep: bool = False) -> list[ifcopenshell.entity_instance]:
if not is_deep:
return [
object
for rel in task.OperatesOn
if rel.is_a("IfcRelAssignsToProcess")
for object in rel.RelatedObjects
if object.is_a("IfcProduct")
]
else:
return [
output
for nested_task in get_all_nested_tasks(task)
for output in [
object
for rel in nested_task.OperatesOn
if rel.is_a("IfcRelAssignsToProcess")
for object in rel.RelatedObjects
if object.is_a("IfcProduct")
]
]
def get_task_resources(task: ifcopenshell.entity_instance, is_deep: bool = False) -> list[ifcopenshell.entity_instance]:
if not is_deep:
return [
object
for rel in task.OperatesOn
if rel.is_a("IfcRelAssignsToProcess")
for object in rel.RelatedObjects
if object.is_a("IfcResource")
]
else:
return [
resource
for nested_task in get_all_nested_tasks(task)
for resource in [
object
for rel in nested_task.OperatesOn
if rel.is_a("IfcRelAssignsToProcess")
for object in rel.RelatedObjects
if object.is_a("IfcResource")
]
]
def get_task_resources(
task: ifcopenshell.entity_instance, is_recursive: bool = False
) -> set[ifcopenshell.entity_instance]:
if is_recursive:
return {r for subtask in [task] + list(get_all_nested_tasks(task)) for r in get_task_resources(subtask)}
return {o for rel in task.OperatesOn for o in rel.RelatedObjects if o.is_a("IfcResource")}
def has_task_outputs(task: ifcopenshell.entity_instance) -> bool: