diff --git a/capellambse_context_diagrams/collectors/cable_tree.py b/capellambse_context_diagrams/collectors/cable_tree.py index 23de7f8..f71ba77 100644 --- a/capellambse_context_diagrams/collectors/cable_tree.py +++ b/capellambse_context_diagrams/collectors/cable_tree.py @@ -25,6 +25,7 @@ def __init__( params: dict[str, t.Any], ) -> None: self.diagram = diagram + self.diagram._port_label_position = "OUTSIDE" self.obj: m.ModelElement = self.diagram.target self.data = makers.make_diagram(diagram) self.data.layoutOptions = DEFAULT_LAYOUT_OPTIONS @@ -69,7 +70,12 @@ def make_edge( tgt_obj: m.ModelElement, ) -> _elkjs.ELKInputEdge: edge = _elkjs.ELKInputEdge( - id=link.uuid, sources=[src_obj.uuid], targets=[tgt_obj.uuid] + id=link.uuid, + sources=[src_obj.uuid], + targets=[tgt_obj.uuid], + labels=makers.make_label( + link.name, + ), ) self.data.edges.append(edge) self.edges[link.uuid] = edge @@ -100,7 +106,7 @@ def make_port_and_owner( if port := self.ports.get(port_obj.uuid): return box port = makers.make_port(port_obj.uuid) - # port.labels = makers.make_label(port_obj.name) + port.labels = makers.make_label(port_obj.name) box.ports.append(port) self.ports[port_obj.uuid] = port return box diff --git a/docs/cable_tree.md b/docs/cable_tree.md new file mode 100644 index 0000000..e26eec0 --- /dev/null +++ b/docs/cable_tree.md @@ -0,0 +1,28 @@ + + +# Cable Tree View Diagram + +The `Cable Tree View` diagram visualizes the cable connections between ports. You can access `.cable_tree` on any `pa.PhysicalLink` element. + +??? example "Cable Tree View of Control Signal" + + ``` py + import capellambse + + model = capellambse.MelodyModel("tests/data/ContextDiagram.aird") + diag = model.by_uuid("5c55b11b-4911-40fb-9c4c-f1363dad846e").cable_tree + diag.render("svgdiagram").save(pretty=True) + ``` +
+ +
[LAB] Cable Tree View of Control Signal
+
+ +## Check out the code + +To understand the collection have a look into the +[`cable_tree`][capellambse_context_diagrams.collectors.cable_tree] +module. diff --git a/docs/gen_images.py b/docs/gen_images.py index 4d7f664..580203e 100644 --- a/docs/gen_images.py +++ b/docs/gen_images.py @@ -43,6 +43,7 @@ realization_comp_uuid = "b9f9a83c-fb02-44f7-9123-9d86326de5f1" data_flow_uuid = "3b83b4ba-671a-4de8-9c07-a5c6b1d3c422" derived_uuid = "47c3130b-ec39-4365-a77a-5ab6365d1e2e" +cable_tree_uuid = "5c55b11b-4911-40fb-9c4c-f1363dad846e" def generate_index_images() -> None: @@ -206,6 +207,14 @@ def generate_interface_with_hide_interface_image(): print(diag.render("svg", **params), file=fd) +def generate_cable_tree_image(): + diag: context.CableTreeViewDiagram = model.by_uuid( + cable_tree_uuid + ).cable_tree + with mkdocs_gen_files.open(f"{str(dest / diag.name)}.svg", "w") as fd: + print(diag.render("svg", transparent_background=False), file=fd) + + generate_index_images() generate_hierarchy_image() generate_symbol_images() @@ -234,3 +243,4 @@ def generate_interface_with_hide_interface_image(): generate_derived_image() generate_interface_with_hide_functions_image() generate_interface_with_hide_interface_image() +generate_cable_tree_image() diff --git a/mkdocs.yml b/mkdocs.yml index b26e4d5..2221b70 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -96,6 +96,8 @@ nav: - Overview: realization_view.md - DataFlow View: - Overview: data_flow_view.md + - Cable Tree View: + - Overview: cable_tree.md - Extras: - Filters: extras/filters.md - Styling: extras/styling.md diff --git a/tests/test_cable_tree_views.py b/tests/test_cable_tree_views.py new file mode 100644 index 0000000..f8f907d --- /dev/null +++ b/tests/test_cable_tree_views.py @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2022 Copyright DB InfraGO AG and the capellambse-context-diagrams contributors +# SPDX-License-Identifier: Apache-2.0 + +import capellambse +import pytest + + +@pytest.mark.parametrize("uuid", ["5c55b11b-4911-40fb-9c4c-f1363dad846e"]) +@pytest.mark.parametrize("fmt", ["svgdiagram", "svg", None]) +def test_exchange_item_relation_views( + model: capellambse.MelodyModel, uuid: str, fmt: str +) -> None: + obj = model.by_uuid(uuid) + + diag = obj.cable_tree + diag.render("svgdiagram").save(pretty=True) + + assert diag.render(fmt)