Skip to content

Commit

Permalink
fix(aird): Add ChangeEvent expression text in label of `StateTransi…
Browse files Browse the repository at this point in the history
…tion`
  • Loading branch information
ewuerger committed Jan 19, 2023
1 parent dce8fd8 commit 25b9cd0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
29 changes: 26 additions & 3 deletions capellambse/aird/_edge_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import math
import typing as t

from lxml import etree

from capellambse import diagram, helpers

from . import _common as C
Expand Down Expand Up @@ -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"):
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/data/melodymodel/5_2/Melody Model Test.aird
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Mode%20State%20Machine']"/>
<target xmi:type="org.polarsys.capella.core.data.capellacommon:Region" href="Melody%20Model%20Test.capella#eeeb98a7-6063-4115-8b4b-40a51cc0df49"/>
</ownedRepresentationDescriptors>
<ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" uid="_KLGoEKyJEeqCdMaqCWkrKg" name="[MSM] Weather Modes" repPath="#_KK2wcKyJEeqCdMaqCWkrKg" changeId="ad7ad644-891d-4133-bfa7-a2428cafaa7a">
<ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" uid="_KLGoEKyJEeqCdMaqCWkrKg" name="[MSM] Weather Modes" repPath="#_KK2wcKyJEeqCdMaqCWkrKg" changeId="2ecc9bed-c64f-436c-86e3-daa962188a17">
<description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Mode%20State%20Machine']"/>
<target xmi:type="org.polarsys.capella.core.data.capellacommon:Region" href="Melody%20Model%20Test.capella#a94806d8-71bb-4eb8-987b-bdce6ca99cb8"/>
</ownedRepresentationDescriptors>
Expand Down Expand Up @@ -1905,7 +1905,7 @@
</ownedStyle>
<actualMapping xmi:type="description_1:EdgeMapping" href="platform:/plugin/org.polarsys.capella.core.sirius.analysis/description/common.odesign#//@ownedViewpoints[name='Common']/@ownedRepresentations[name='Mode%20State%20Machine']/@defaultLayer/@edgeMappings[name='MSM_Transition']"/>
</ownedDiagramElements>
<ownedDiagramElements xmi:type="diagram:DEdge" uid="_uoAC9KyJEeqCdMaqCWkrKg" name="(AT) Night, (WHEN) Sleeping [SUN = 0] " sourceNode="_o9NqYKyJEeqCdMaqCWkrKg" targetNode="_p-qgUKyJEeqCdMaqCWkrKg">
<ownedDiagramElements xmi:type="diagram:DEdge" uid="_uoAC9KyJEeqCdMaqCWkrKg" name="(AFTER) Night, (WHEN) Sleeping [SUN = 0] " sourceNode="_o9NqYKyJEeqCdMaqCWkrKg" targetNode="_p-qgUKyJEeqCdMaqCWkrKg">
<target xmi:type="org.polarsys.capella.core.data.capellacommon:StateTransition" href="Melody%20Model%20Test.capella#d0ea4afa-4231-4a3d-b1db-03655738dab8"/>
<semanticElements xmi:type="org.polarsys.capella.core.data.capellacommon:StateTransition" href="Melody%20Model%20Test.capella#d0ea4afa-4231-4a3d-b1db-03655738dab8"/>
<ownedStyle xmi:type="diagram:EdgeStyle" uid="_uoAC9ayJEeqCdMaqCWkrKg" strokeColor="0,0,0">
Expand Down
3 changes: 2 additions & 1 deletion tests/data/melodymodel/5_2/Melody Model Test.capella
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ The predator is far away</bodies>
</ownedConstraints>
</ownedStateEvents>
<ownedStateEvents xsi:type="org.polarsys.capella.core.data.capellacommon:TimeEvent"
id="680f13b6-c446-4510-974f-0de9da6bd2be" name="TimeEvent 3" expression="#20925467-cfbf-47bc-bad6-ad842973f4d4">
id="680f13b6-c446-4510-974f-0de9da6bd2be" name="TimeEvent 3" expression="#20925467-cfbf-47bc-bad6-ad842973f4d4"
kind="AFTER">
<ownedConstraints xsi:type="org.polarsys.capella.core.data.capellacore:Constraint"
id="20925467-cfbf-47bc-bad6-ad842973f4d4" name="">
<ownedSpecification xsi:type="org.polarsys.capella.core.data.information.datavalue:OpaqueExpression"
Expand Down

0 comments on commit 25b9cd0

Please sign in to comment.