From 114c408d9796393a66572ab4aa6682fcd1e9e260 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Sun, 27 Oct 2024 12:28:43 +0100 Subject: [PATCH] fix: Floating ports --- .../collectors/default.py | 13 + tests/data/ContextDiagram.aird | 594 ++++++++++++++++++ tests/data/ContextDiagram.capella | 96 ++- tests/test_context_diagrams.py | 24 + 4 files changed, 726 insertions(+), 1 deletion(-) diff --git a/capellambse_context_diagrams/collectors/default.py b/capellambse_context_diagrams/collectors/default.py index a5725db9..bde950d4 100644 --- a/capellambse_context_diagrams/collectors/default.py +++ b/capellambse_context_diagrams/collectors/default.py @@ -109,7 +109,20 @@ def process_context(self): ) if self.diagram._hide_direct_children: self.centerbox.children = [] + hidden = set(edge.id for edge in self.centerbox.edges) + centerbox_ports = set(port.id for port in self.centerbox.ports) + port_uuids = set() + for ex in self.exchanges: + if ex.uuid not in hidden: + if ex.source.uuid in centerbox_ports: + port_uuids.add(ex.source.uuid) + if ex.target.uuid in centerbox_ports: + port_uuids.add(ex.target.uuid) + self.centerbox.edges = [] + self.centerbox.ports = [ + p for p in self.centerbox.ports if p.id in port_uuids + ] for label in self.centerbox.labels: label.layoutOptions = makers.CENTRIC_LABEL_LAYOUT_OPTIONS diff --git a/tests/data/ContextDiagram.aird b/tests/data/ContextDiagram.aird index f6d711cd..e15fab1f 100644 --- a/tests/data/ContextDiagram.aird +++ b/tests/data/ContextDiagram.aird @@ -162,6 +162,14 @@ + + +
+
+ + + + @@ -16133,4 +16141,590 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + KEEP_LOCATION + KEEP_SIZE + KEEP_RATIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/ContextDiagram.capella b/tests/data/ContextDiagram.capella index 2ae8a430..a60cf87c 100644 --- a/tests/data/ContextDiagram.capella +++ b/tests/data/ContextDiagram.capella @@ -62,7 +62,7 @@ definition="#682bd51d-5451-4930-a97e-8bfca6c3a127" value="true"/> + value="2021-07-23T15:00:00.000+0200"/> name="LA 9" abstractType="#b3d9d50e-7592-4689-8ba7-e50f082cd71c"/> + + id="062c9593-1fc9-43ce-aac5-4f37d0a9c346" targetElement="#5f31bf59-316e-4844-b44d-a38adba22313" sourceElement="#dbd99773-efb6-4476-bf5c-270a61f18b09"/> + + name="Derived Target" abstractType="#7cde329d-0f47-4eaa-a1ae-dc6ede90af57"/> + @@ -4321,6 +4333,76 @@ The predator is far away id="1f1545b8-04b8-4bd1-9009-c9d514155660" targetElement="#8b3b14d5-ed06-48fe-acd7-354657944e54" sourceElement="#aad1bc27-e66c-4b38-a54a-b2de4a73a3b4"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id="3d101a29-abb8-4510-956c-ab02e0f1b03c" targetElement="#83ba0220-54f2-48f7-bca1-cd87e39639f2" sourceElement="#4ec45aec-0d6a-411a-80ee-ebd3c1a53d2c"/> + + + + + + 1 + + +def test_context_diagram_hide_direct_children( + model: capellambse.MelodyModel, +) -> None: + obj = model.by_uuid("eca84d5c-fdcd-4cbe-90d5-7d00a256c62b") + expected_hidden_uuids = { + "a34300ee-6e63-4c72-b210-2adee00478f8", + "6a557565-c9d4-4216-8e9e-03539c0e6095", + "32483de8-abd5-4e50-811b-407fad44defa", + "e786b912-51ed-4bb8-b03c-acb05c48f0c8", + "727b7d69-3cd2-45cc-b423-1e7b93c83f5b", + "c0a2ae6d-ac5e-4a73-84ef-b7b9df344170", + "3e66b559-eea0-40af-b18c-0328ee10add7", + "1b978e1e-1368-44a2-a9e6-12818614b23e", # Port + } + + diag = obj.context_diagram + grey = diag.render(None, hide_direct_children=True) + diag.invalidate_cache() + white = diag.render(None, hide_direct_children=False) + + assert not set(element.uuid for element in grey) & expected_hidden_uuids + assert set(element.uuid for element in white) & expected_hidden_uuids