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

feat(tree-view): Add handling of properties w/o Associations #140

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
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
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"
ewuerger marked this conversation as resolved.
Show resolved Hide resolved

i = self._edge_count.setdefault(cls.prop.uuid, 0)
i += 1
edge_id = f"__{styleclass}:{cls.prop.uuid}-{i}"
ewuerger marked this conversation as resolved.
Show resolved Hide resolved

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
Loading