Skip to content

Add trigger and action for State Machine transitions #3385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2024
Merged

Add trigger and action for State Machine transitions #3385

merged 6 commits into from
Jul 24, 2024

Conversation

ghillebrand
Copy link
Contributor

Adds trigger and action to a State Transition Models, in addition to guard, as per Issue #2845
trigger and action associations have been added to the UML model Transition Class Diagram , and the code updated to edit and display these attributes as trigger [guard] /action

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

What is the current behavior?

Currently, only guard text can be entered, which is displayed below the transition as [guard].
Issue Number: #2845

What is the new behavior?

Now trigger and action can independently be entered in the properties dialog, and are displayed according to the UML spec trigger[guard]/action on the transition. The text is below the transition, rather than above, which seems to be the UML preference for this.

Does this PR introduce a breaking change?

  • Yes
  • No

This does not seem to be backwards compatible - models created with these changes do not open in older versions of gaphor. This seems to be related to the file loading code. On trying to open a model created with these changes, gaphor (2.25.1 under windows) does nothing - no error, no crash, no model or diagram displayed.

Other information

My first PR/ change, so if I have omitted/ mangled something, my apologies!

Code working, still has some comments.

Previous versions of gaphor don't seem to be able load these models.

Note that in `transition.py`, line 22 there is a mypy #type ignore
Also added spaces between trigger, guard and action,
since they are hard to read in a proportional font.
@github-actions github-actions bot added the python Pull requests that update Python code label Jul 12, 2024
So they do not conflict in the model.
State transition code is now up to date with the latest (model) changes
in the main branch.
@amolenaar
Copy link
Member

Hi @ghillebrand,

You're definitely on the right track. The code looks okay. To fix the mypy issue, I moved some code around.

Some other changes:

  • Merged the code with the main branch. The @transactional has been deleted and the UML model had been updated.
  • Fixed a small issue in the model, where 2 relations referred to the same association end on behavior.
  • I moved the generation of the trigger/guard/action name to a separate method. I think that makes it somewhat more readable.

I was wondering if trigger and action should actually refer to exiting behaviors, such as a activity, state machine, and Interaction. Currently it's creating a new "Behavior" instance, with no relation to the rest of the model (Behavior should have been an abstract class in the model).

@ghillebrand
Copy link
Contributor Author

Thank you :) That all makes sense.

ITO the behaviour issue, the OP was happy if the trigger-guard-action could be displayed "properly", without too much methodology behind it. I certainly don't know/ use UML enough to begin to make a call on that!
If you can point me at how to make the text appear above the line, I would happily add that. I would like to understand the drawing side of gaphor better, and that would then meet all the of OP's requirements as I understand them.

My goal is to create a new model type, higraph, which would heavily re-use the STM code, and this was an excellent project to get my head around how the bits of gaphor interact. I should open a feature request, yes? I will outline the steps as I see them, and be guided by you guys on how/ where to implement the various parts.

@amolenaar
Copy link
Member

@ghillebrand

You refer to this?

image

The text positioning is mostly done automatic. The LinePresentation class initiates text placement and calls text_point_at_line, which will place the text close to the begin/center/end of the line. The position is dependent on the angle of the respected line segment.

Text placement is the same for all lines/vertices.

@amolenaar
Copy link
Member

This PR looks good. So I'll merge it.

@amolenaar amolenaar merged commit b01f89a into gaphor:main Jul 24, 2024
18 checks passed
@amolenaar amolenaar changed the title Stm trigger action Add trigger and action for State Machine transitions Jul 24, 2024
@ghillebrand
Copy link
Contributor Author

ghillebrand commented Jul 24, 2024

@ghillebrand

You refer to this?
image

The text positioning is mostly done automatic. The LinePresentation class initiates text placement and calls text_point_at_line, which will place the text close to the begin/center/end of the line. The position is dependent on the angle of the respected line segment.

Text placement is the same for all lines/vertices.

Yes, this is what I meant, and this looks like the code I was looking for. Other tools write the text above the line. When I get a chance, I will play with the hinting values, and see how they behave/ influence things. Controlling text position I would like to be able to do for higraphs.

@danyeaw danyeaw added feature A new feature and removed python Pull requests that update Python code labels Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants