ctkWorkflowStep.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QObject>
  16. #include <QState>
  17. // CTK includes
  18. #include "ctkWorkflowStep.h"
  19. #include "ctkWorkflowStep_p.h"
  20. #include "ctkWorkflow.h"
  21. #include "ctkLogger.h"
  22. // STD includes
  23. #include <iostream>
  24. //--------------------------------------------------------------------------
  25. static ctkLogger logger("org.commontk.core.ctkWorkflowStep");
  26. //--------------------------------------------------------------------------
  27. // --------------------------------------------------------------------------
  28. // ctkWorkflowStepPrivate methods
  29. // --------------------------------------------------------------------------
  30. ctkWorkflowStepPrivate::ctkWorkflowStepPrivate(ctkWorkflowStep& object)
  31. :q_ptr(&object)
  32. {
  33. this->Workflow = 0;
  34. this->HasValidateCommand = false;
  35. this->HasOnEntryCommand = false;
  36. this->HasOnExitCommand = false;
  37. // Create state
  38. this->ProcessingState = new QState();
  39. this->ValidationState = new QState();
  40. // Create 'validation' transition
  41. this->ValidationTransition =
  42. new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationTransition);
  43. this->ValidationTransition->setTargetState(this->ValidationState);
  44. this->ProcessingState->addTransition(this->ValidationTransition);
  45. // Create 'failed validation' transation
  46. this->ValidationFailedTransition = 0;
  47. this->ValidationFailedTransition =
  48. new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationFailedTransition);
  49. this->ValidationFailedTransition->setTargetState(this->ProcessingState);
  50. this->ValidationState->addTransition(this->ValidationFailedTransition);
  51. }
  52. // --------------------------------------------------------------------------
  53. ctkWorkflowStepPrivate::~ctkWorkflowStepPrivate()
  54. {
  55. delete this->ValidationState;
  56. delete this->ProcessingState;
  57. // If we delete the states, then Qt will handle deleting the transitions
  58. }
  59. // --------------------------------------------------------------------------
  60. void ctkWorkflowStepPrivate::validationCompleteInternal(bool validationResults, const QString& branchId)const
  61. {
  62. emit validationComplete(validationResults, branchId);
  63. }
  64. // --------------------------------------------------------------------------
  65. void ctkWorkflowStepPrivate::onEntryCompleteInternal()const
  66. {
  67. emit onEntryComplete();
  68. }
  69. // --------------------------------------------------------------------------
  70. void ctkWorkflowStepPrivate::onExitCompleteInternal()const
  71. {
  72. emit onExitComplete();
  73. }
  74. // --------------------------------------------------------------------------
  75. void ctkWorkflowStepPrivate::invokeValidateCommandInternal(const QString& desiredBranchId)const
  76. {
  77. emit invokeValidateCommand(desiredBranchId);
  78. }
  79. // --------------------------------------------------------------------------
  80. void ctkWorkflowStepPrivate::invokeOnEntryCommandInternal(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  81. {
  82. emit invokeOnEntryCommand(comingFrom, transitionType);
  83. }
  84. // --------------------------------------------------------------------------
  85. void ctkWorkflowStepPrivate::invokeOnExitCommandInternal(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  86. {
  87. emit invokeOnExitCommand(goingTo, transitionType);
  88. }
  89. // --------------------------------------------------------------------------
  90. // ctkWorkflowStep methods
  91. // --------------------------------------------------------------------------
  92. ctkWorkflowStep::ctkWorkflowStep(): d_ptr(new ctkWorkflowStepPrivate(*this))
  93. {
  94. Q_D(ctkWorkflowStep);
  95. d->Id = d->metaObject()->className();
  96. }
  97. // --------------------------------------------------------------------------
  98. ctkWorkflowStep::ctkWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId)
  99. : d_ptr(new ctkWorkflowStepPrivate(*this))
  100. {
  101. Q_D(ctkWorkflowStep);
  102. if (newId.isEmpty())
  103. {
  104. d->Id = d->metaObject()->className();
  105. }
  106. else
  107. {
  108. d->Id = newId;
  109. }
  110. d->Workflow = newWorkflow;
  111. }
  112. // --------------------------------------------------------------------------
  113. ctkWorkflowStep::ctkWorkflowStep(ctkWorkflowStepPrivate * pimpl):d_ptr(pimpl)
  114. {
  115. Q_D(ctkWorkflowStep);
  116. d->Id = d->metaObject()->className();
  117. }
  118. // --------------------------------------------------------------------------
  119. ctkWorkflowStep::ctkWorkflowStep(ctkWorkflowStepPrivate * pimpl,
  120. ctkWorkflow* newWorkflow, const QString& newId):d_ptr(pimpl)
  121. {
  122. Q_D(ctkWorkflowStep);
  123. if (newId.isEmpty())
  124. {
  125. d->Id = d->metaObject()->className();
  126. }
  127. else
  128. {
  129. d->Id = newId;
  130. }
  131. d->Workflow = newWorkflow;
  132. }
  133. // --------------------------------------------------------------------------
  134. ctkWorkflowStep::~ctkWorkflowStep()
  135. {
  136. }
  137. // --------------------------------------------------------------------------
  138. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflow*, workflow, Workflow);
  139. CTK_SET_CPP(ctkWorkflowStep, ctkWorkflow*, setWorkflow, Workflow);
  140. // --------------------------------------------------------------------------
  141. CTK_GET_CPP(ctkWorkflowStep, QString, id, Id);
  142. CTK_SET_CPP(ctkWorkflowStep, const QString&, setId, Id);
  143. // --------------------------------------------------------------------------
  144. CTK_GET_CPP(ctkWorkflowStep, QString, name, Name);
  145. CTK_SET_CPP(ctkWorkflowStep, const QString&, setName, Name);
  146. // --------------------------------------------------------------------------
  147. CTK_GET_CPP(ctkWorkflowStep, QString, description, Description);
  148. CTK_SET_CPP(ctkWorkflowStep, const QString&, setDescription, Description);
  149. // --------------------------------------------------------------------------
  150. CTK_GET_CPP(ctkWorkflowStep, QString, statusText, StatusText);
  151. CTK_SET_CPP(ctkWorkflowStep, const QString&, setStatusText, StatusText);
  152. // --------------------------------------------------------------------------
  153. CTK_GET_CPP(ctkWorkflowStep, bool, hasValidateCommand, HasValidateCommand);
  154. CTK_SET_CPP(ctkWorkflowStep, bool, setHasValidateCommand, HasValidateCommand);
  155. // --------------------------------------------------------------------------
  156. CTK_GET_CPP(ctkWorkflowStep, bool, hasOnEntryCommand, HasOnEntryCommand);
  157. CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnEntryCommand, HasOnEntryCommand);
  158. // --------------------------------------------------------------------------
  159. CTK_GET_CPP(ctkWorkflowStep, bool, hasOnExitCommand, HasOnExitCommand);
  160. CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnExitCommand, HasOnExitCommand);
  161. // --------------------------------------------------------------------------
  162. CTK_GET_CPP(ctkWorkflowStep, QState*, processingState, ProcessingState);
  163. CTK_GET_CPP(ctkWorkflowStep, QState*, validationState, ValidationState);
  164. // --------------------------------------------------------------------------
  165. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*, validationTransition, ValidationTransition);
  166. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*,
  167. validationFailedTransition, ValidationFailedTransition);
  168. // --------------------------------------------------------------------------
  169. QObject* ctkWorkflowStep::ctkWorkflowStepQObject()
  170. {
  171. Q_D(ctkWorkflowStep);
  172. return d;
  173. }
  174. // --------------------------------------------------------------------------
  175. void ctkWorkflowStep::validationComplete(bool validationResults, const QString& branchId)const
  176. {
  177. Q_D(const ctkWorkflowStep);
  178. d->validationCompleteInternal(validationResults, branchId);
  179. }
  180. // --------------------------------------------------------------------------
  181. void ctkWorkflowStep::onEntryComplete()const
  182. {
  183. Q_D(const ctkWorkflowStep);
  184. d->onEntryCompleteInternal();
  185. }
  186. // --------------------------------------------------------------------------
  187. void ctkWorkflowStep::onExitComplete()const
  188. {
  189. Q_D(const ctkWorkflowStep);
  190. d->onExitCompleteInternal();
  191. }
  192. // --------------------------------------------------------------------------
  193. void ctkWorkflowStep::invokeValidateCommand(const QString& desiredBranchId)const
  194. {
  195. Q_D(const ctkWorkflowStep);
  196. d->invokeValidateCommandInternal(desiredBranchId);
  197. }
  198. // --------------------------------------------------------------------------
  199. void ctkWorkflowStep::invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  200. {
  201. Q_D(const ctkWorkflowStep);
  202. d->invokeOnEntryCommandInternal(comingFrom, transitionType);
  203. }
  204. // --------------------------------------------------------------------------
  205. void ctkWorkflowStep::invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  206. {
  207. Q_D(const ctkWorkflowStep);
  208. d->invokeOnExitCommandInternal(goingTo, transitionType);
  209. }
  210. // --------------------------------------------------------------------------
  211. void ctkWorkflowStep::validate(const QString& desiredBranchId)
  212. {
  213. Q_D(ctkWorkflowStep);
  214. logger.info(QString("validate - validating the input from %1").arg(d->Name));
  215. this->validationComplete(true, desiredBranchId);
  216. }
  217. // --------------------------------------------------------------------------
  218. void ctkWorkflowStep::onEntry(const ctkWorkflowStep* comingFrom,
  219. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  220. {
  221. Q_UNUSED(comingFrom);
  222. Q_UNUSED(transitionType);
  223. // Signals that we are finished
  224. this->onEntryComplete();
  225. }
  226. // --------------------------------------------------------------------------
  227. void ctkWorkflowStep::onExit(const ctkWorkflowStep* goingTo,
  228. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  229. {
  230. Q_UNUSED(goingTo);
  231. Q_UNUSED(transitionType);
  232. // Signals that we are finished
  233. this->onExitComplete();
  234. }