Skip to content

Commit

Permalink
fix(tree_view): Handle properties without association
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Apr 16, 2024
1 parent c2029d6 commit 1c95630
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions capellambse_context_diagrams/collectors/tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions capellambse_context_diagrams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c95630

Please sign in to comment.