Skip to content

Commit

Permalink
docs(cable-tree): Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed Sep 25, 2024
1 parent d8f9ccd commit 8eb6e77
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
10 changes: 8 additions & 2 deletions capellambse_context_diagrams/collectors/cable_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions docs/cable_tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ SPDX-FileCopyrightText: 2022 Copyright DB InfraGO AG and the capellambse-context-diagrams contributors
~ SPDX-License-Identifier: Apache-2.0
-->

# 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)
```
<figure markdown>
<img src="../assets/images/Cable Tree View of Control Signal.svg">
<figcaption>[LAB] Cable Tree View of Control Signal</figcaption>
</figure>

## Check out the code

To understand the collection have a look into the
[`cable_tree`][capellambse_context_diagrams.collectors.cable_tree]
module.
10 changes: 10 additions & 0 deletions docs/gen_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cable_tree_views.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8eb6e77

Please sign in to comment.