Skip to content

Commit

Permalink
fix: Disply symbols as boxes for SystemFunction context diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenngn committed May 14, 2024
1 parent afa672d commit 016c9c7
Show file tree
Hide file tree
Showing 7 changed files with 2,146 additions and 1,316 deletions.
11 changes: 9 additions & 2 deletions capellambse_context_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def register_classes() -> None:
(
ctx.SystemFunction,
DiagramType.SAB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
{
"display_symbols_as_boxes": True,
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
(
la.LogicalComponent,
Expand Down Expand Up @@ -112,7 +116,10 @@ def register_classes() -> None:
(
pa.PhysicalFunction,
DiagramType.PAB,
{"render_styles": styling.BLUE_ACTOR_FNCS},
{
"display_parent_relation": True,
"render_styles": styling.BLUE_ACTOR_FNCS,
},
),
]
patch_styles(supported_classes)
Expand Down
118 changes: 59 additions & 59 deletions capellambse_context_diagrams/collectors/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ def collector(
diagram: context.ContextDiagram, params: dict[str, t.Any] | None = None
) -> _elkjs.ELKInputData:
"""Collect context data from ports of centric box."""
diagram.display_parent_relation = (params or {}).pop(
"display_parent_relation", diagram.display_parent_relation
)
diagram.display_derived_interfaces = (params or {}).pop(
"display_derived_interfaces", diagram.display_derived_interfaces
)
data = generic.collector(diagram, no_symbol=True)
ports = port_collector(diagram.target, diagram.type)
centerbox = data["children"][0]
Expand All @@ -41,7 +35,6 @@ 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):
if not diagram.display_parent_relation:
continue
Expand All @@ -61,8 +54,7 @@ def collector(
continue
global_boxes = {centerbox["id"]: centerbox}
made_boxes = {centerbox["id"]: centerbox}
to_delete = set()
to_delete.add(centerbox["id"])
boxes_to_delete = {centerbox["id"]}

def _make_box_and_update_globals(
obj: t.Any,
Expand All @@ -77,17 +69,19 @@ def _make_box_and_update_globals(
return box

if diagram.display_parent_relation:
if diagram.target.owner:
box = _make_box_and_update_globals(
diagram.target.owner,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
box["children"] = [centerbox]
del data["children"][0]
all_owners = generic.get_all_owners(diagram.target)
start = 0
common_owner = diagram.target
try:
if not isinstance(diagram.target.owner, generic.PackageTypes):
box = _make_box_and_update_globals(
diagram.target.owner,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
box["children"] = [centerbox]
del data["children"][0]
except AttributeError:
pass
diagram_target_owners = generic.get_all_owners(diagram.target)
common_owners = []

stack_heights: dict[str, float | int] = {
"input": -makers.NEIGHBOR_VMARGIN,
Expand Down Expand Up @@ -117,57 +111,63 @@ def _make_box_and_update_globals(

if diagram.display_parent_relation:
current = child
while (
current
and not isinstance(current, generic.PackageTypes)
and current.uuid not in all_owners
):
while current and current.uuid not in diagram_target_owners:
try:
if isinstance(current.owner, generic.PackageTypes):
break
if not (
parent_box := global_boxes.get(current.owner.uuid)
):
parent_box = _make_box_and_update_globals(
current.owner,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
new_box = global_boxes.get(current.uuid, current)
for box in (
children := parent_box.setdefault("children", [])
):
if box["id"] == current.uuid:
box = new_box
break
else:
children.append(new_box)
boxes_to_delete.add(current.uuid)
current = current.owner
except AttributeError:
break
common_owners.append(current.uuid)

stack_heights[side] += makers.NEIGHBOR_VMARGIN + height

if diagram.display_parent_relation and diagram.target.owner:
current = diagram.target.owner
common_owner_uuid = current.uuid
for owner in diagram_target_owners[::-1]:
if owner in common_owners:
common_owner_uuid = owner
break
while current and current.uuid != common_owner_uuid:
try:
if isinstance(current.owner, generic.PackageTypes):
break
if not (parent_box := global_boxes.get(current.owner.uuid)):
parent_box = _make_box_and_update_globals(
current.owner,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
new_box = global_boxes.get(current.uuid, current)
for box in (children := parent_box.setdefault("children", [])):
if box["id"] == current.uuid:
box = new_box
box = global_boxes.pop(current.uuid)
break
else:
children.append(new_box)
to_delete.add(current.uuid)
children.append(global_boxes.pop(current.uuid))
current = current.owner
try:
if all_owners.index(current.uuid, start) > start:
common_owner = current
except ValueError:
pass

stack_heights[side] += makers.NEIGHBOR_VMARGIN + height

if diagram.display_parent_relation and diagram.target.owner:
current = diagram.target.owner
while (
current
and not isinstance(current, generic.PackageTypes)
and current != common_owner
):
if not (parent_box := global_boxes.get(current.owner.uuid)):
parent_box = _make_box_and_update_globals(
current.owner,
no_symbol=diagram.display_symbols_as_boxes,
layout_options=makers.DEFAULT_LABEL_LAYOUT_OPTIONS,
)
for box in (children := parent_box.setdefault("children", [])):
if box["id"] == current.uuid:
box = global_boxes.pop(current.uuid)
break
else:
children.append(global_boxes.pop(current.uuid))

current = current.owner
except AttributeError:
break

for uuid in to_delete:
for uuid in boxes_to_delete:
del global_boxes[uuid]
data["children"].extend(global_boxes.values())
if diagram.display_parent_relation:
Expand Down
3 changes: 1 addition & 2 deletions capellambse_context_diagrams/collectors/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def move_edges(
target_owner_uuids = get_all_owners(c.target)
common_owner_uuid = None
for owner in source_owner_uuids:
if owner in set(target_owner_uuids):
if owner in target_owner_uuids:
common_owner_uuid = owner
break

Expand All @@ -247,7 +247,6 @@ def move_edges(
if edge["id"] == c.uuid:
owner_box.setdefault("edges", []).append(edge)
edges_to_remove.append(edge["id"])

data["edges"] = [
e for e in data["edges"] if e["id"] not in edges_to_remove
]
Expand Down
12 changes: 12 additions & 0 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ def render(self, fmt: str | None, /, **params) -> t.Any:

def _create_diagram(self, params: dict[str, t.Any]) -> cdiagram.Diagram:
transparent_background = params.pop("transparent_background", False)
self.display_parent_relation = params.pop(
"display_parent_relation", self.display_parent_relation
)
self.display_derived_interfaces = params.pop(
"display_derived_interfaces", self.display_derived_interfaces
)
self.display_symbols_as_boxes = params.pop(
"display_symbols_as_boxes", self.display_symbols_as_boxes
)
self.slim_center_box = params.pop(
"slim_center_box", self.slim_center_box
)
data = params.get("elkdata") or get_elkdata(self, params)
layout = try_to_layout(data)
add_context(layout, params.get("is_legend", False))
Expand Down
2 changes: 1 addition & 1 deletion capellambse_context_diagrams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class type that stores all previously named classes.

for i in child.get("children", []): # type: ignore
if i["type"] == "edge":
self._edges.setdefault(i["id"], (i, ref, element))
self._edges.setdefault(i["id"], (i, ref, parent))
else:
self.deserialize_child(i, ref, element)

Expand Down
Loading

0 comments on commit 016c9c7

Please sign in to comment.