ctkWorkflowStep.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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(ctkWorkflow* newWorkflow, const QString& newId)
  93. : d_ptr(new ctkWorkflowStepPrivate(*this))
  94. {
  95. Q_D(ctkWorkflowStep);
  96. if (newId.isEmpty())
  97. {
  98. d->Id = d->metaObject()->className();
  99. }
  100. else
  101. {
  102. d->Id = newId;
  103. }
  104. d->Workflow = newWorkflow;
  105. }
  106. // --------------------------------------------------------------------------
  107. ctkWorkflowStep::~ctkWorkflowStep()
  108. {
  109. }
  110. // --------------------------------------------------------------------------
  111. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflow*, workflow, Workflow);
  112. CTK_SET_CPP(ctkWorkflowStep, ctkWorkflow*, setWorkflow, Workflow);
  113. // --------------------------------------------------------------------------
  114. CTK_GET_CPP(ctkWorkflowStep, QString, id, Id);
  115. CTK_SET_CPP(ctkWorkflowStep, const QString&, setId, Id);
  116. // --------------------------------------------------------------------------
  117. CTK_GET_CPP(ctkWorkflowStep, QString, name, Name);
  118. CTK_SET_CPP(ctkWorkflowStep, const QString&, setName, Name);
  119. // --------------------------------------------------------------------------
  120. CTK_GET_CPP(ctkWorkflowStep, QString, description, Description);
  121. CTK_SET_CPP(ctkWorkflowStep, const QString&, setDescription, Description);
  122. // --------------------------------------------------------------------------
  123. CTK_GET_CPP(ctkWorkflowStep, QString, statusText, StatusText);
  124. CTK_SET_CPP(ctkWorkflowStep, const QString&, setStatusText, StatusText);
  125. // --------------------------------------------------------------------------
  126. CTK_GET_CPP(ctkWorkflowStep, bool, hasValidateCommand, HasValidateCommand);
  127. CTK_SET_CPP(ctkWorkflowStep, bool, setHasValidateCommand, HasValidateCommand);
  128. // --------------------------------------------------------------------------
  129. CTK_GET_CPP(ctkWorkflowStep, bool, hasOnEntryCommand, HasOnEntryCommand);
  130. CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnEntryCommand, HasOnEntryCommand);
  131. // --------------------------------------------------------------------------
  132. CTK_GET_CPP(ctkWorkflowStep, bool, hasOnExitCommand, HasOnExitCommand);
  133. CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnExitCommand, HasOnExitCommand);
  134. // --------------------------------------------------------------------------
  135. CTK_GET_CPP(ctkWorkflowStep, QState*, processingState, ProcessingState);
  136. CTK_GET_CPP(ctkWorkflowStep, QState*, validationState, ValidationState);
  137. // --------------------------------------------------------------------------
  138. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*, validationTransition, ValidationTransition);
  139. CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*,
  140. validationFailedTransition, ValidationFailedTransition);
  141. // --------------------------------------------------------------------------
  142. QObject* ctkWorkflowStep::ctkWorkflowStepQObject()
  143. {
  144. Q_D(ctkWorkflowStep);
  145. return d;
  146. }
  147. // --------------------------------------------------------------------------
  148. void ctkWorkflowStep::validationComplete(bool validationResults, const QString& branchId)const
  149. {
  150. Q_D(const ctkWorkflowStep);
  151. d->validationCompleteInternal(validationResults, branchId);
  152. }
  153. // --------------------------------------------------------------------------
  154. void ctkWorkflowStep::onEntryComplete()const
  155. {
  156. Q_D(const ctkWorkflowStep);
  157. d->onEntryCompleteInternal();
  158. }
  159. // --------------------------------------------------------------------------
  160. void ctkWorkflowStep::onExitComplete()const
  161. {
  162. Q_D(const ctkWorkflowStep);
  163. d->onExitCompleteInternal();
  164. }
  165. // --------------------------------------------------------------------------
  166. void ctkWorkflowStep::invokeValidateCommand(const QString& desiredBranchId)const
  167. {
  168. Q_D(const ctkWorkflowStep);
  169. d->invokeValidateCommandInternal(desiredBranchId);
  170. }
  171. // --------------------------------------------------------------------------
  172. void ctkWorkflowStep::invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  173. {
  174. Q_D(const ctkWorkflowStep);
  175. d->invokeOnEntryCommandInternal(comingFrom, transitionType);
  176. }
  177. // --------------------------------------------------------------------------
  178. void ctkWorkflowStep::invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  179. {
  180. Q_D(const ctkWorkflowStep);
  181. d->invokeOnExitCommandInternal(goingTo, transitionType);
  182. }
  183. // --------------------------------------------------------------------------
  184. void ctkWorkflowStep::validate(const QString& desiredBranchId)
  185. {
  186. Q_D(ctkWorkflowStep);
  187. logger.info(QString("validate - validating the input from %1").arg(d->Name));
  188. this->validationComplete(true, desiredBranchId);
  189. }
  190. // --------------------------------------------------------------------------
  191. void ctkWorkflowStep::onEntry(const ctkWorkflowStep* comingFrom,
  192. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  193. {
  194. Q_UNUSED(comingFrom);
  195. Q_UNUSED(transitionType);
  196. // Signals that we are finished
  197. this->onEntryComplete();
  198. }
  199. // --------------------------------------------------------------------------
  200. void ctkWorkflowStep::onExit(const ctkWorkflowStep* goingTo,
  201. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  202. {
  203. Q_UNUSED(goingTo);
  204. Q_UNUSED(transitionType);
  205. // Signals that we are finished
  206. this->onExitComplete();
  207. }