From 092610a27006d4b09610bdca808a01a0e5caec2c Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Thu, 23 May 2024 12:43:38 -0500 Subject: [PATCH] fix(generator): allow end states from choice states in the initial state transition path (#165) --- src/common/processor.js | 5 ++- .../templates/uml/ChoiceState.tmpl | 9 ++++- .../templates/uml/ExternalTransition.tmpl | 10 +++--- .../templates/uml/InitTransition.tmpl | 34 +++++++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/common/processor.js b/src/common/processor.js index 6da0b1e..f3fadea 100644 --- a/src/common/processor.js +++ b/src/common/processor.js @@ -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; @@ -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 diff --git a/src/plugins/SoftwareGenerator/templates/uml/ChoiceState.tmpl b/src/plugins/SoftwareGenerator/templates/uml/ChoiceState.tmpl index c8e29bd..f16d3eb 100644 --- a/src/plugins/SoftwareGenerator/templates/uml/ChoiceState.tmpl +++ b/src/plugins/SoftwareGenerator/templates/uml/ChoiceState.tmpl @@ -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}} @@ -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}} diff --git a/src/plugins/SoftwareGenerator/templates/uml/ExternalTransition.tmpl b/src/plugins/SoftwareGenerator/templates/uml/ExternalTransition.tmpl index cd67e74..4d39270 100644 --- a/src/plugins/SoftwareGenerator/templates/uml/ExternalTransition.tmpl +++ b/src/plugins/SoftwareGenerator/templates/uml/ExternalTransition.tmpl @@ -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) { } @@ -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}} @@ -42,5 +42,5 @@ else if ( true ) { {{/if}} // make sure nothing else handles this event handled = true; - {{/if}} +{{/if}} } diff --git a/src/plugins/SoftwareGenerator/templates/uml/InitTransition.tmpl b/src/plugins/SoftwareGenerator/templates/uml/InitTransition.tmpl index 9862cab..9be7d2e 100644 --- a/src/plugins/SoftwareGenerator/templates/uml/InitTransition.tmpl +++ b/src/plugins/SoftwareGenerator/templates/uml/InitTransition.tmpl @@ -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}} }