sverweij/state-machine-cat

Add support for doActivities in SCXML model representation

noricor opened this issue · 9 comments

Hi,

Context

In our SCXML models we are using doActivities and they are encoded using the keyword, see SCXML spec 6.4.
Can you add support for this so that the generated SVG images also show the doActivities for SCXML input models.

Proposed Behavior

Support do activities in the form of


Current Behavior

It seems doActivities are currently not supported in models using the SCXML representation

Many thanks in advance

Cheers
J.

hi @noricor - thanks for this suggestion! I did have a peek at the SCXML specification and couldn't find anything on doActivities (/ doActivity/ activity/ activities), but my search skills could have abandoned me. I did look at section 6.4, but also failed to connect what is in there with (do)Activities.

Can you provide me a direct link to the spot in the SCXML spec where you found this?

(I'll be happy to implement onactivity or receive a pull request for the same - provided it is part of the scxml specification)

SCXML does have <onentry> and <onexit> for the same purpose, though. It's this what state-machine-cat uses when it translates the UML activity - e.g.:

doing:
  entry/ this an entry
  entry/ this an entry as well
  activity/ this is an activity
  activity/ this is another activity
  and this is an activity too
  exit/ this is an on exit trigger
  exit/ this is an on exit trigger as well
;

... translates to

<?xml version="1.0" encoding="UTF-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
    <state id="doing">
        <onentry>this an entry</onentry>
        <onentry>this an entry as well</onentry>
        <onentry>this is an activity</onentry>
        <onentry>this is another activity</onentry>
        <onentry>and this is an activity too</onentry>
        <onexit>this is an on exit trigger</onexit>
        <onexit>this is an on exit trigger as well</onexit>
    </state>
</scxml>

Hi and thanks for quick response.

You are right, do activities are not mentioned by name in the SCXML spec, this is one of the odd things
where SCXML standard diverges from UML even though both are based on Harel state charts.

SCXML spec says that invoke can be used to "create an instance of an external service" which in
practice nicely maps to doActivities, because oftentimes you dont want to implement them via entry and exit actions.

My use case is the generation of SVG from SCXML. The problem I have when providing an SCXML
model with statements is that they are not drawn in the resulting SVG, so information is lost
in the image.

So if you are not comfortable to translate them into doActivities (because technically they are not precisely it),
would it be possible to show them at least as invoked behaviour in graphical representation of the containing state?

Cheers

Hi @noricor thanks for the explanation. That mapping makes sense. Could you provide an example?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Hi, sorry for late reply, here an example that we use with our scxml4cpp engine to implement doActivities.

      <state id="Initialising">
        <invoke id="ActivityInitialising"/>
      </state>

This will define state Initialsing with doActivity named ActivityInitialising, the behaviour of the activity is then provided via a user defined method that is mapped to this activity id.

It would be wonderful if the graphical representation could also show this somehow,
because it is important that people see the activities they need to provide in generated
graphical diagrams.

Many thanks.

hi @noricor - thanks for the example (and the link). I've made a quick addition to the scxml parser to handle this. I'll later look into the broader picture (=> changes can be expected). You can try it out on a beta version which I've deployed on GitLab: sverweij.gitlab.io/state-machine-cat and on npm as state-machine-cat@9.2.0-beta-1.

=> Could you let me know whether this works for you?

image

Hi, thanks for quick implementation, looks good to me so far.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.