From 1c9563043d81cca582eef1f251b59e25d590a685 Mon Sep 17 00:00:00 2001 From: Martin Lehmann Date: Tue, 16 Apr 2024 16:39:00 +0200 Subject: [PATCH] fix(tree_view): Handle properties without association --- .../collectors/tree_view.py | 9 +++++++-- capellambse_context_diagrams/serializers.py | 17 +++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/capellambse_context_diagrams/collectors/tree_view.py b/capellambse_context_diagrams/collectors/tree_view.py index d9b3de44..081d1eec 100644 --- a/capellambse_context_diagrams/collectors/tree_view.py +++ b/capellambse_context_diagrams/collectors/tree_view.py @@ -39,6 +39,7 @@ def __init__( self.data_types: set[str] = set() self.legend_boxes: list[_elkjs.ELKInputChild] = [] self.all_associations = all_associations + self.edge_counter = 0 def __contains__(self, uuid: str) -> bool: objects = self.data["children"] + self.data["edges"] # type: ignore[operator] @@ -54,8 +55,12 @@ def process_class(self, cls: ClassInfo, params: dict[str, t.Any]): for assoc in self.all_associations if cls.prop in assoc.navigable_members ] - assert len(edges) == 1 - if (edge_id := edges[0].uuid) not in self.made_edges: + if len(edges) == 1: + edge_id = edges[0].uuid + else: + edge_id = f"__Association_{self.edge_counter}" + self.edge_counter += 1 + if edge_id not in self.made_edges: self.made_edges.add(edge_id) text = cls.prop.name if cls.multiplicity is None: diff --git a/capellambse_context_diagrams/serializers.py b/capellambse_context_diagrams/serializers.py index e482eb8f..ff27d0fa 100644 --- a/capellambse_context_diagrams/serializers.py +++ b/capellambse_context_diagrams/serializers.py @@ -112,7 +112,10 @@ def deserialize_child( [`diagram.Diagram`][capellambse.diagram.Diagram] : Diagram class type that stores all previously named classes. """ - styleclass: str | None = self.get_styleclass(child["id"]) + if child["id"].startswith("__"): + styleclass = child["id"][2:].split("_", 1)[0] + else: + styleclass = self.get_styleclass(child["id"]) element: diagram.Box | diagram.Edge | diagram.Circle if child["type"] in {"node", "port"}: assert parent is None or isinstance(parent, diagram.Box) @@ -215,9 +218,10 @@ class type that stores all previously named classes. element = parent elif child["type"] == "junction": - uuid = child["id"].split("_", maxsplit=1)[0] + uuid = child["id"].rsplit("_", maxsplit=1)[0] pos = diagram.Vector2D(**child["position"]) if self._is_hierarchical(uuid): + # FIXME should this use `parent` instead? pos += self.diagram[self._diagram.target.uuid].pos element = diagram.Circle( @@ -252,13 +256,14 @@ def get_styleclass(self, uuid: str) -> str | None: """Return the style-class string from a given [`_elkjs.ELKOutputChild`][capellambse_context_diagrams._elkjs.ELKOutputChild]. """ - styleclass: str | None try: melodyobj = self._diagram._model.by_uuid(uuid) - styleclass = diagram.get_styleclass(melodyobj) except KeyError: - styleclass = None - return styleclass + if not uuid.startswith("__"): + return None + return uuid[2:].split("_", 1)[0] + else: + return diagram.get_styleclass(melodyobj) def get_styleoverrides( self, child: _elkjs.ELKOutputChild