Coverage for backend/flowsheetInternals/graphicData/logic/ungroup.py: 92%
27 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-06 23:27 +0000
1from typing import List
2from core.auxiliary.enums.unitOpData import SimulationObjectClass
3from flowsheetInternals.graphicData.models.groupingModel import Breadcrumbs, Grouping, GraphicObject
4from flowsheetInternals.unitops.models.SimulationObject import SimulationObject
5import random
6from typing import List
7from flowsheetInternals.unitops.models.delete_factory import DeleteFactory
10def ungroup(group: Grouping):
11 #groups parent object is set to none
12 parent_group = group.get_parent_group()
14 contained_objects : List[GraphicObject] = group.graphicObjects.all()
16 objects_to_update = []
17 for graphic_object in contained_objects:
18 # add all graphic objects to the parent group
19 simulationObject : SimulationObject = graphic_object.simulationObject
20 # See if a graphic object already exists within the parent group (should only happen for streams)
21 # If there is, delete the top level graphic object so that positioning is maintained from the grouped one.
22 parent_group_graphic_object = simulationObject.graphicObject.filter(group=parent_group).first()
23 if parent_group_graphic_object:
24 parent_group_graphic_object.delete()
26 graphic_object.group = parent_group
27 objects_to_update.append(graphic_object)
29 GraphicObject.objects.bulk_update(objects_to_update, ["group"])
31 DeleteFactory.delete_object(group.simulationObject)
33 # update zones in StreamDataEntry
34 for graphic_object in contained_objects:
35 simulationObject : SimulationObject = graphic_object.simulationObject
36 if simulationObject.is_stream():
37 continue
38 for stream_data_entry in simulationObject.StreamDataEntries.all(): 38 ↛ 39line 38 didn't jump to line 39 because the loop on line 38 never started
39 stream_data_entry.group = parent_group
40 stream_data_entry.save()