Skip to content

Commit

Permalink
feat(tree-view): Add handling of properties w/o Associations
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Sep 19, 2024
1 parent 54d96be commit e538f3a
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions capellambse_context_diagrams/collectors/tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import typing as t

import capellambse.model as m
from capellambse.metamodel import information
from capellambse.metamodel import information, modeltypes

from .. import _elkjs, context
from . import generic, makers
Expand All @@ -31,17 +31,14 @@


class ClassProcessor:
def __init__(
self,
data: _elkjs.ELKInputData,
all_associations: cabc.Iterable[information.Association],
) -> None:
def __init__(self, data: _elkjs.ELKInputData) -> None:
self.data = data
self.made_boxes: set[str] = {data.children[0].id}
self.made_edges: set[str] = set()
self.data_types: set[str] = set()
self.legend_boxes: list[_elkjs.ELKInputChild] = []
self.all_associations = all_associations

self._edge_count: dict[str, int] = {}

def __contains__(self, uuid: str) -> bool:
objects = self.data.children + self.data.edges # type: ignore[operator]
Expand All @@ -51,13 +48,29 @@ def process_class(self, cls: ClassInfo, params: dict[str, t.Any]):
self._process_box(cls.source, cls.partition, params)

if not cls.primitive and isinstance(cls.target, information.Class):
assert cls.prop is not None
self._process_box(cls.target, cls.partition, params)
edges = [
assoc
for assoc in self.all_associations
if cls.prop in assoc.navigable_members # type: ignore[attr-defined]
]
edge_id = edges[0].uuid

aggregation_kind_excludes = {
None,
modeltypes.AggregationKind.UNSET,
}
if cls.prop.association is not None:
edge_id = cls.prop.association.uuid
else:
logger.warning(
"No Association found for %s set on 'navigable_members'",
cls.prop._short_repr_(),
)
if cls.prop.kind not in aggregation_kind_excludes:
styleclass = cls.prop.kind.name.capitalize()
else:
styleclass = "Association"

i = self._edge_count.setdefault(cls.prop.uuid, 0)
i += 1
edge_id = f"__{styleclass}:{cls.prop.uuid}-{i}"

if edge_id not in self.made_edges:
self.made_edges.add(edge_id)
text = cls.prop.name if cls.prop else ""
Expand All @@ -68,6 +81,7 @@ def process_class(self, cls: ClassInfo, params: dict[str, t.Any]):

if start != "1" or end != "1":
text = f"[{start}..{end}] {text}"

self.data.edges.append(
_elkjs.ELKInputEdge(
id=edge_id,
Expand Down Expand Up @@ -141,11 +155,8 @@ def collector(
data.children[0].labels[0].layoutOptions.update(
makers.DEFAULT_LABEL_LAYOUT_OPTIONS
)
all_associations: cabc.Iterable[information.Association] = (
diagram._model.search("Association")
)
_set_layout_options(data, params)
processor = ClassProcessor(data, all_associations)
processor = ClassProcessor(data)
processor._set_data_types_and_labels(data.children[0], diagram.target)
for _, cls in get_all_classes(
diagram.target,
Expand Down

0 comments on commit e538f3a

Please sign in to comment.