Skip to content

Commit

Permalink
fix(generator): allow end states from choice states in the initial st…
Browse files Browse the repository at this point in the history
…ate transition path (#165)
  • Loading branch information
finger563 authored May 23, 2024
1 parent d7e9c15 commit 092610a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/common/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ define(['./checkModel', 'underscore'], function(checkModel, _) {
obj.isDeepHistory = false;
obj.isShallowHistory = false;
obj.isEnd = false;
obj.hasEndTransition = false;
},
processModel: function(model) {
var self = this;
Expand Down Expand Up @@ -173,7 +174,9 @@ define(['./checkModel', 'underscore'], function(checkModel, _) {
}
else {
var endTransition = checkModel.getEndTransitions( parent, model.objects );
obj.endTransition = endTransition[0];
obj.hasEndTransition = endTransition.length > 0;
if (obj.hasEndTransition)
obj.endTransition = endTransition[0];
}
}
// Process Choice Pseudostate Data
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/SoftwareGenerator/templates/uml/ChoiceState.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Going into a choice pseudo-state, let it handle its
// guards and perform the state transition
if (false) { } // makes geneeration easier :)
if (false) { } // makes generation easier :)
{{#each ExternalTransitions}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{#if Guard}}
Expand All @@ -17,6 +17,13 @@ else if ( true ) {
{{> ChoiceStateTempl nextState}}
{{else if nextState.isState}}
_root->{{nextState.pointerName}}.initialize();
{{else if nextState.isEnd}}
if (false) { } // makes generation easier :)
{{#nextState.endTransition}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{> ExternalTransitionTempl }}
{{/addTransition}}
{{~/nextState.endTransition}}
{{/if}}
}
{{/addTransition}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ else if ( {{{Guard}}} ) {
else if ( true ) {
_root->log("\033[37mNO GUARD on EXTERNAL TRANSITION:{{{path}}}\033[0m");
{{/if}}
{{#if nextState.isChoice}}
{{#if nextState.isChoice}}
// Going into a choice pseudo-state, let it handle its
// guards and perform the state transition
if (false) { } // makes geneeration easier :)
if (false) { } // makes generation easier :)
{{#each nextState.ExternalTransitions}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{> ExternalTransitionTempl }}
{{/addTransition}}
{{~/each}}
{{else if nextState.endTransition}}
{{else if nextState.hasEndTransition}}
// Going into an end pseudo-state that is not the root end state,
// follow its parent end transition
if (false) { }
Expand All @@ -24,7 +24,7 @@ else if ( true ) {
{{> ExternalTransitionTempl }}
{{/addTransition}}
{{~/nextState.endTransition}}
{{else}}
{{else}}
// Transitioning states!
{{#renderTransition exit="true" entry="true" transition=.}}{{/renderTransition}}
{{#if nextState.isState}}
Expand All @@ -42,5 +42,5 @@ else if ( true ) {
{{/if}}
// make sure nothing else handles this event
handled = true;
{{/if}}
{{/if}}
}
34 changes: 27 additions & 7 deletions src/plugins/SoftwareGenerator/templates/uml/InitTransition.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,35 @@ else if ( true ) {
// Going into a choice pseudo-state, let it handle its
// guards and perform the state transition
if (false) { } // makes generation easier :)
{{#each nextState.ExternalTransitions}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{> InitTransitionTempl }}
{{/addTransition}}
{{~/each}}
{{#each nextState.ExternalTransitions}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{> InitTransitionTempl }}
{{/addTransition}}
{{~/each}}
{{else if nextState.hasEndTransition}}
// Going into an end pseudo-state that is not the root end state,
// follow its parent end transition
if (false) { }
{{#nextState.endTransition}}
{{#addTransition trans=.. previous=../previousTransitions}}
{{> InitTransitionTempl }}
{{/addTransition}}
{{~/nextState.endTransition}}
{{else}}
// Transitioning states!
{{#renderTransition exit="false" entry="true" transition=.}}{{/renderTransition}}
// now initialize the actual next state
{{#renderTransition exit="false" entry="true" transition=.}}{{/renderTransition}}
{{#if nextState.isState}}
// going into regular state
_root->{{{nextState.pointerName}}}.initialize();
{{else if nextState.isEnd}}
// going into end pseudo-state THIS SHOULD BE TOP LEVEL END STATE
_root->{{{nextState.pointerName}}}.makeActive();
{{else if nextState.isDeepHistory}}
// going into deep history pseudo-state
_root->{{{nextState.parent.pointerName}}}.setDeepHistory();
{{else if nextState.isShallowHistory}}
// going into shallow history pseudo-state
_root->{{{nextState.parent.pointerName}}}.setShallowHistory();
{{/if}}
{{/if}}
}

0 comments on commit 092610a

Please sign in to comment.