diff --git a/capellambse_context_diagrams/collectors/default.py b/capellambse_context_diagrams/collectors/default.py index b714e993..8c899cca 100644 --- a/capellambse_context_diagrams/collectors/default.py +++ b/capellambse_context_diagrams/collectors/default.py @@ -39,10 +39,13 @@ def collector( ex_datas: list[generic.ExchangeData] = [] edges: common.ElementList[fa.AbstractExchange] for ex in (edges := list(chain.from_iterable(connections.values()))): - if ( - is_hierarchical := exchanges.is_hierarchical(ex, centerbox) - ) and not diagram.include_inner_objects: - continue + if is_hierarchical := exchanges.is_hierarchical(ex, centerbox): + if diagram.display_parent_relation: + centerbox["labels"][0][ + "layoutOptions" + ] = makers.DEFAULT_LABEL_LAYOUT_OPTIONS + if not diagram.include_inner_objects: + continue if not is_hierarchical or not diagram.display_parent_relation: elkdata = data else: @@ -59,11 +62,22 @@ def collector( made_boxes = {centerbox["id"]: centerbox} to_delete = set() to_delete.add(centerbox["id"]) + + def _make_box_and_update_globals( + obj: t.Any, + **kwargs: t.Any, + ) -> _elkjs.ELKInputChild: + box = makers.make_box( + obj, + **kwargs, + ) + global_boxes[obj.uuid] = box + made_boxes[obj.uuid] = box + return box + if diagram.display_parent_relation and diagram.target.owner: box = _make_box_and_update_globals( diagram.target.owner, - global_boxes, - made_boxes, no_symbol=diagram.display_symbols_as_boxes, layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS, ) @@ -94,8 +108,6 @@ def collector( else: box = _make_box_and_update_globals( child, - global_boxes, - made_boxes, height=height, no_symbol=diagram.display_symbols_as_boxes, ) @@ -111,8 +123,6 @@ def collector( if not (parent_box := global_boxes.get(current.owner.uuid)): parent_box = _make_box_and_update_globals( current.owner, - global_boxes, - made_boxes, no_symbol=diagram.display_symbols_as_boxes, layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS, ) @@ -143,8 +153,6 @@ def collector( if not (parent_box := global_boxes.get(current.owner.uuid)): parent_box = _make_box_and_update_globals( current.owner, - global_boxes, - made_boxes, no_symbol=diagram.display_symbols_as_boxes, layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS, ) @@ -173,21 +181,6 @@ def collector( return data -def _make_box_and_update_globals( - obj: t.Any, - global_boxes: dict[str, _elkjs.ELKInputChild], - made_boxes: dict[str, _elkjs.ELKInputChild], - **kwargs: t.Any, -) -> _elkjs.ELKInputChild: - box = makers.make_box( - obj, - **kwargs, - ) - global_boxes[obj.uuid] = box - made_boxes[obj.uuid] = box - return box - - def port_collector( target: common.GenericElement | common.ElementList, diagram_type: DT ) -> list[common.GenericElement]: diff --git a/tests/test_context_diagrams.py b/tests/test_context_diagrams.py index a19a34ef..2b6db5e1 100644 --- a/tests/test_context_diagrams.py +++ b/tests/test_context_diagrams.py @@ -140,7 +140,6 @@ def test_include_inner_objects_in_context_diagram( model: capellambse.MelodyModel, ) -> None: obj = model.by_uuid(TEST_HIERARCHY_UUID) - expected_children = TEST_HIERARCHY_CHILDREN_UUIDS adiag = obj.context_diagram.render(None, include_inner_objects=True) obj.context_diagram.render("svgdiagram", include_inner_objects=True).save( @@ -149,7 +148,7 @@ def test_include_inner_objects_in_context_diagram( children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children} - for uuid in expected_children: + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: assert uuid in children @@ -157,7 +156,6 @@ def test_exclude_inner_objects_in_context_diagram( model: capellambse.MelodyModel, ) -> None: obj = model.by_uuid(TEST_HIERARCHY_UUID) - expected_children = TEST_HIERARCHY_CHILDREN_UUIDS adiag = obj.context_diagram.render(None, include_inner_objects=False) obj.context_diagram.render("svgdiagram", include_inner_objects=False).save( @@ -166,10 +164,37 @@ def test_exclude_inner_objects_in_context_diagram( children = {obj.uuid for obj in adiag[TEST_HIERARCHY_UUID].children} - for uuid in expected_children: + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: assert uuid not in children +def test_exclude_inner_objects_and_hide_parent_relation_in_context_diagram( + model: capellambse.MelodyModel, +) -> None: + obj = model.by_uuid(TEST_HIERARCHY_UUID) + + adiag = obj.context_diagram.render( + None, + display_parent_relation=False, + include_inner_objects=False, + depth=2, + ) + obj.context_diagram.render( + "svgdiagram", + display_parent_relation=False, + include_inner_objects=False, + depth=2, + ).save(pretty=True) + + for uuid in TEST_HIERARCHY_CHILDREN_UUIDS: + with pytest.raises(KeyError): + adiag[uuid] # pylint: disable=pointless-statement + + for uuid in TEST_HIERARCHY_PARENTS_UUIDS: + with pytest.raises(KeyError): + adiag[uuid] # pylint: disable=pointless-statement + + def test_parent_relation_in_context_diagram( model: capellambse.MelodyModel, ) -> None: