Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix interface context diagram collection #121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions capellambse_context_diagrams/_elkjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ class ELKInputData(BaseELKModel):
default_factory=list
)

def get_children_by_id(self, search_id: str) -> ELKInputChild | None:
"""Recursively search for a child with the given id."""
for child in self.children:
if child.id == search_id:
return child

if found_child := child.get_children_by_id(search_id):
return found_child
return None


class ELKInputChild(ELKInputData):
"""Children of either `ELKInputData` or `ELKInputChild`."""
Expand Down
32 changes: 15 additions & 17 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
cabc.Iterable[common.GenericElement],
]

STYLECLASS_PREFIX = "__Derived"


class ContextProcessor:
def __init__(
Expand All @@ -52,21 +50,21 @@ def __init__(
self.made_boxes = {self.centerbox.id: self.centerbox}
self.boxes_to_delete = {self.centerbox.id}
self.edges: list[fa.AbstractExchange] = []
if self.diagram.display_parent_relation:
if self.diagram._display_parent_relation:
self.diagram_target_owners = generic.get_all_owners(
self.diagram.target
)
self.common_owners: set[str] = set()

def process_context(self):
if (
self.diagram.display_parent_relation
self.diagram._display_parent_relation
and getattr(self.diagram.target, "owner", None) is not None
and not isinstance(self.diagram.target.owner, generic.PackageTypes)
):
box = self._make_box(
self.diagram.target.owner,
no_symbol=self.diagram.display_symbols_as_boxes,
no_symbol=self.diagram._display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
box.children = [self.centerbox]
Expand All @@ -78,7 +76,7 @@ def process_context(self):
}
self._process_ports(stack_heights)

if self.diagram.display_parent_relation and self.diagram.target.owner:
if self.diagram._display_parent_relation and self.diagram.target.owner:
current = self.diagram.target.owner
while (
current
Expand All @@ -96,7 +94,7 @@ def process_context(self):
del self.global_boxes[uuid]

self.data.children.extend(self.global_boxes.values())
if self.diagram.display_parent_relation:
if self.diagram._display_parent_relation:
owner_boxes: dict[str, _elkjs.ELKInputChild] = {
uuid: box
for uuid, box in self.made_boxes.items()
Expand Down Expand Up @@ -124,7 +122,7 @@ def _process_exchanges(self) -> tuple[
if is_hierarchical := exchanges.is_hierarchical(
ex, self.centerbox
):
if not self.diagram.display_parent_relation:
if not self.diagram._display_parent_relation:
continue
self.centerbox.labels[0].layoutOptions = (
makers.DEFAULT_LABEL_LAYOUT_OPTIONS
Expand Down Expand Up @@ -167,11 +165,11 @@ def _process_ports(self, stack_heights: dict[str, float | int]) -> None:
box = self._make_box(
port,
height=height,
no_symbol=self.diagram.display_symbols_as_boxes,
no_symbol=self.diagram._display_symbols_as_boxes,
)
box.ports = [makers.make_port(j.uuid) for j in local_ports]

if self.diagram.display_parent_relation:
if self.diagram._display_parent_relation:
current = port
while (
current
Expand Down Expand Up @@ -205,7 +203,7 @@ def _make_owner_box(
if not (parent_box := self.global_boxes.get(obj.owner.uuid)):
parent_box = self._make_box(
obj.owner,
no_symbol=diagram.display_symbols_as_boxes,
no_symbol=diagram._display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
assert (obj_box := self.global_boxes.get(obj.uuid))
Expand All @@ -227,7 +225,7 @@ def collector(
processor = ContextProcessor(diagram, data, params=params)
processor.process_context()
derivator = DERIVATORS.get(type(diagram.target))
if diagram.display_derived_interfaces and derivator is not None:
if diagram._display_derived_interfaces and derivator is not None:
derivator(
diagram,
data,
Expand Down Expand Up @@ -403,21 +401,21 @@ def derive_from_functions(
for i, (uuid, derived_component) in enumerate(components.items(), 1):
box = makers.make_box(
derived_component,
no_symbol=diagram.display_symbols_as_boxes,
no_symbol=diagram._display_symbols_as_boxes,
)
class_ = type(derived_comp).__name__
box.id = f"{STYLECLASS_PREFIX}-{class_}:{uuid}"
box.id = f"{makers.STYLECLASS_PREFIX}-{class_}:{uuid}"
data.children.append(box)
source_id = f"{STYLECLASS_PREFIX}-CP_INOUT:{i}"
target_id = f"{STYLECLASS_PREFIX}-CP_INOUT:{-i}"
source_id = f"{makers.STYLECLASS_PREFIX}-CP_INOUT:{i}"
target_id = f"{makers.STYLECLASS_PREFIX}-CP_INOUT:{-i}"
box.ports.append(makers.make_port(source_id))
centerbox.ports.append(makers.make_port(target_id))
if i % 2 == 0:
source_id, target_id = target_id, source_id

data.edges.append(
_elkjs.ELKInputEdge(
id=f"{STYLECLASS_PREFIX}-ComponentExchange:{i}",
id=f"{makers.STYLECLASS_PREFIX}-ComponentExchange:{i}",
sources=[source_id],
targets=[target_id],
)
Expand Down
Loading
Loading