From 25b9cd074f42f197275854482558d95dff96bf1c Mon Sep 17 00:00:00 2001 From: ewuerger Date: Thu, 19 Jan 2023 13:45:48 +0100 Subject: [PATCH] fix(aird): Add `ChangeEvent` expression text in label of `StateTransition` --- capellambse/aird/_edge_factories.py | 29 +++++++++++++++++-- .../melodymodel/5_2/Melody Model Test.aird | 4 +-- .../melodymodel/5_2/Melody Model Test.capella | 3 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/capellambse/aird/_edge_factories.py b/capellambse/aird/_edge_factories.py index 616b98d0a..a3bf5f957 100644 --- a/capellambse/aird/_edge_factories.py +++ b/capellambse/aird/_edge_factories.py @@ -9,6 +9,8 @@ import math import typing as t +from lxml import etree + from capellambse import diagram, helpers from . import _common as C @@ -474,9 +476,7 @@ def state_transition_factory(seb: C.SemanticElementBuilder) -> diagram.Edge: seb.melodyobjs[0], seb.melodyobjs[0].get("triggers", "") ) label = ", ".join( - i.get("name", "(unnamed trigger)") - for i in triggers - if i is not None + _get_trigger_expression(i, seb) for i in triggers if i is not None ) if guard := _guard_condition(seb, "guard"): @@ -495,6 +495,29 @@ def state_transition_factory(seb: C.SemanticElementBuilder) -> diagram.Edge: return edge +def _get_trigger_expression( + trigger: etree._Element, seb: C.SemanticElementBuilder +) -> str: + exprid = trigger.get("expression") + if not exprid: + return "" + + change_event_type = trigger.attrib[helpers.ATT_XT] + if change_event_type.endswith("TimeEvent"): + kind = trigger.get("kind", "AT") + elif change_event_type.endswith("ChangeEvent"): + kind = trigger.get("kind", "WHEN") + + constraint = seb.melodyloader.follow_link(seb.melodyobjs[0], exprid) + try: + spec = next(constraint.iterchildren("ownedSpecification")) + body = next(spec.iterchildren("bodies")) + except StopIteration: + return "" + + return f"({kind}) {body.text}" + + def sequence_link_factory(seb: C.SemanticElementBuilder) -> diagram.Edge: """Create a SequenceLink. diff --git a/tests/data/melodymodel/5_2/Melody Model Test.aird b/tests/data/melodymodel/5_2/Melody Model Test.aird index b1549ab89..5a56fb70f 100644 --- a/tests/data/melodymodel/5_2/Melody Model Test.aird +++ b/tests/data/melodymodel/5_2/Melody Model Test.aird @@ -12,7 +12,7 @@ - + @@ -1905,7 +1905,7 @@ - + diff --git a/tests/data/melodymodel/5_2/Melody Model Test.capella b/tests/data/melodymodel/5_2/Melody Model Test.capella index f8113e57e..7499686ca 100644 --- a/tests/data/melodymodel/5_2/Melody Model Test.capella +++ b/tests/data/melodymodel/5_2/Melody Model Test.capella @@ -764,7 +764,8 @@ The predator is far away + id="680f13b6-c446-4510-974f-0de9da6bd2be" name="TimeEvent 3" expression="#20925467-cfbf-47bc-bad6-ad842973f4d4" + kind="AFTER">