ctkWorkflowStep.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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()
  31. {
  32. this->Workflow = 0;
  33. this->HasValidateCommand = false;
  34. this->HasOnEntryCommand = false;
  35. this->HasOnExitCommand = false;
  36. // Create state
  37. this->ProcessingState = new QState();
  38. this->ValidationState = new QState();
  39. // Create 'validation' transition
  40. this->ValidationTransition =
  41. new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationTransition);
  42. this->ValidationTransition->setTargetState(this->ValidationState);
  43. this->ProcessingState->addTransition(this->ValidationTransition);
  44. // Create 'failed validation' transation
  45. this->ValidationFailedTransition = 0;
  46. this->ValidationFailedTransition =
  47. new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationFailedTransition);
  48. this->ValidationFailedTransition->setTargetState(this->ProcessingState);
  49. this->ValidationState->addTransition(this->ValidationFailedTransition);
  50. }
  51. // --------------------------------------------------------------------------
  52. ctkWorkflowStepPrivate::~ctkWorkflowStepPrivate()
  53. {
  54. delete this->ValidationState;
  55. delete this->ProcessingState;
  56. // If we delete the states, then Qt will handle deleting the transitions
  57. }
  58. // --------------------------------------------------------------------------
  59. void ctkWorkflowStepPrivate::validationCompleteInternal(bool validationResults, const QString& branchId)const
  60. {
  61. emit validationComplete(validationResults, branchId);
  62. }
  63. // --------------------------------------------------------------------------
  64. void ctkWorkflowStepPrivate::onEntryCompleteInternal()const
  65. {
  66. emit onEntryComplete();
  67. }
  68. // --------------------------------------------------------------------------
  69. void ctkWorkflowStepPrivate::onExitCompleteInternal()const
  70. {
  71. emit onExitComplete();
  72. }
  73. // --------------------------------------------------------------------------
  74. void ctkWorkflowStepPrivate::invokeValidateCommandInternal(const QString& desiredBranchId)const
  75. {
  76. emit invokeValidateCommand(desiredBranchId);
  77. }
  78. // --------------------------------------------------------------------------
  79. void ctkWorkflowStepPrivate::invokeOnEntryCommandInternal(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  80. {
  81. emit invokeOnEntryCommand(comingFrom, transitionType);
  82. }
  83. // --------------------------------------------------------------------------
  84. void ctkWorkflowStepPrivate::invokeOnExitCommandInternal(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  85. {
  86. emit invokeOnExitCommand(goingTo, transitionType);
  87. }
  88. // --------------------------------------------------------------------------
  89. // ctkWorkflowStep methods
  90. // --------------------------------------------------------------------------
  91. ctkWorkflowStep::ctkWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId)
  92. {
  93. CTK_INIT_PRIVATE(ctkWorkflowStep);
  94. CTK_D(ctkWorkflowStep);
  95. if (newId.isEmpty())
  96. {
  97. d->Id = d->metaObject()->className();
  98. }
  99. else
  100. {
  101. d->Id = newId;
  102. }
  103. d->Workflow = newWorkflow;
  104. }
  105. // --------------------------------------------------------------------------
  106. CTK_GET_CXX(ctkWorkflowStep, ctkWorkflow*, workflow, Workflow);
  107. CTK_SET_CXX(ctkWorkflowStep, ctkWorkflow*, setWorkflow, Workflow);
  108. // --------------------------------------------------------------------------
  109. CTK_GET_CXX(ctkWorkflowStep, QString, id, Id);
  110. CTK_SET_CXX(ctkWorkflowStep, const QString&, setId, Id);
  111. // --------------------------------------------------------------------------
  112. CTK_GET_CXX(ctkWorkflowStep, QString, name, Name);
  113. CTK_SET_CXX(ctkWorkflowStep, const QString&, setName, Name);
  114. // --------------------------------------------------------------------------
  115. CTK_GET_CXX(ctkWorkflowStep, QString, description, Description);
  116. CTK_SET_CXX(ctkWorkflowStep, const QString&, setDescription, Description);
  117. // --------------------------------------------------------------------------
  118. CTK_GET_CXX(ctkWorkflowStep, QString, statusText, StatusText);
  119. CTK_SET_CXX(ctkWorkflowStep, const QString&, setStatusText, StatusText);
  120. // --------------------------------------------------------------------------
  121. CTK_GET_CXX(ctkWorkflowStep, bool, hasValidateCommand, HasValidateCommand);
  122. CTK_SET_CXX(ctkWorkflowStep, bool, setHasValidateCommand, HasValidateCommand);
  123. // --------------------------------------------------------------------------
  124. CTK_GET_CXX(ctkWorkflowStep, bool, hasOnEntryCommand, HasOnEntryCommand);
  125. CTK_SET_CXX(ctkWorkflowStep, bool, setHasOnEntryCommand, HasOnEntryCommand);
  126. // --------------------------------------------------------------------------
  127. CTK_GET_CXX(ctkWorkflowStep, bool, hasOnExitCommand, HasOnExitCommand);
  128. CTK_SET_CXX(ctkWorkflowStep, bool, setHasOnExitCommand, HasOnExitCommand);
  129. // --------------------------------------------------------------------------
  130. CTK_GET_CXX(ctkWorkflowStep, QState*, processingState, ProcessingState);
  131. CTK_GET_CXX(ctkWorkflowStep, QState*, validationState, ValidationState);
  132. // --------------------------------------------------------------------------
  133. CTK_GET_CXX(ctkWorkflowStep, ctkWorkflowIntrastepTransition*, validationTransition, ValidationTransition);
  134. CTK_GET_CXX(ctkWorkflowStep, ctkWorkflowIntrastepTransition*,
  135. validationFailedTransition, ValidationFailedTransition);
  136. // --------------------------------------------------------------------------
  137. QObject* ctkWorkflowStep::ctkWorkflowStepQObject()
  138. {
  139. CTK_D(ctkWorkflowStep);
  140. return d;
  141. }
  142. // --------------------------------------------------------------------------
  143. void ctkWorkflowStep::validationComplete(bool validationResults, const QString& branchId)const
  144. {
  145. CTK_D(const ctkWorkflowStep);
  146. d->validationCompleteInternal(validationResults, branchId);
  147. }
  148. // --------------------------------------------------------------------------
  149. void ctkWorkflowStep::onEntryComplete()const
  150. {
  151. CTK_D(const ctkWorkflowStep);
  152. d->onEntryCompleteInternal();
  153. }
  154. // --------------------------------------------------------------------------
  155. void ctkWorkflowStep::onExitComplete()const
  156. {
  157. CTK_D(const ctkWorkflowStep);
  158. d->onExitCompleteInternal();
  159. }
  160. // --------------------------------------------------------------------------
  161. void ctkWorkflowStep::invokeValidateCommand(const QString& desiredBranchId)const
  162. {
  163. CTK_D(const ctkWorkflowStep);
  164. d->invokeValidateCommandInternal(desiredBranchId);
  165. }
  166. // --------------------------------------------------------------------------
  167. void ctkWorkflowStep::invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  168. {
  169. CTK_D(const ctkWorkflowStep);
  170. d->invokeOnEntryCommandInternal(comingFrom, transitionType);
  171. }
  172. // --------------------------------------------------------------------------
  173. void ctkWorkflowStep::invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
  174. {
  175. CTK_D(const ctkWorkflowStep);
  176. d->invokeOnExitCommandInternal(goingTo, transitionType);
  177. }
  178. // --------------------------------------------------------------------------
  179. void ctkWorkflowStep::validate(const QString& desiredBranchId)
  180. {
  181. CTK_D(ctkWorkflowStep);
  182. logger.info(QString("validate - validating the input from %1").arg(d->Name));
  183. this->validationComplete(true, desiredBranchId);
  184. }
  185. // --------------------------------------------------------------------------
  186. void ctkWorkflowStep::onEntry(const ctkWorkflowStep* comingFrom,
  187. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  188. {
  189. Q_UNUSED(comingFrom);
  190. Q_UNUSED(transitionType);
  191. // Signals that we are finished
  192. this->onEntryComplete();
  193. }
  194. // --------------------------------------------------------------------------
  195. void ctkWorkflowStep::onExit(const ctkWorkflowStep* goingTo,
  196. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
  197. {
  198. Q_UNUSED(goingTo);
  199. Q_UNUSED(transitionType);
  200. // Signals that we are finished
  201. this->onExitComplete();
  202. }