ctkWorkflowStep.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. #ifndef __ctkWorkflowStep_h
  15. #define __ctkWorkflowStep_h
  16. // Qt includes
  17. class QObject;
  18. class QState;
  19. // CTK includes
  20. #include "ctkPimpl.h"
  21. #include "ctkCoreExport.h"
  22. #include "ctkWorkflowTransitions.h"
  23. class ctkWorkflow;
  24. class ctkWorkflowStepPrivate;
  25. /// \brief ctkWorkflowStep is the basis for a workflow step.
  26. ///
  27. /// A workflow step is a placeholder for various states and transitions that are used in a
  28. /// typical workflow. Such steps can be added to instances of the ctkWorkflow class.
  29. class CTK_CORE_EXPORT ctkWorkflowStep
  30. {
  31. public:
  32. explicit ctkWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId);
  33. virtual ~ctkWorkflowStep();
  34. /// Get the \a workflow associated with this step
  35. ctkWorkflow* workflow()const;
  36. /// Get id
  37. QString id()const;
  38. /// Set/get \a name
  39. QString name()const;
  40. void setName(const QString& newName);
  41. /// Set/get \a description
  42. QString description()const;
  43. void setDescription(const QString& newDescription);
  44. /// Get \a statusText
  45. QString statusText()const;
  46. /// Set/get whether a validationCommand has been provided in a separate QObject
  47. /// \note see method 2 described for validation()
  48. /// \sa validation()
  49. bool hasValidateCommand()const;
  50. void setHasValidateCommand(bool newHasValidateCommand);
  51. /// Set/get whether an onEntryCommand has been provided in a separate QObject
  52. /// \note See method2 in onEntry()
  53. /// \sa onEntry()
  54. bool hasOnEntryCommand()const;
  55. void setHasOnEntryCommand(bool newHasOnEntryCommand);
  56. ///
  57. /// Set/get whether an onExitCommand has been provided in a separate QObject
  58. /// \note See method2 in onExit()
  59. /// \sa onExit()
  60. bool hasOnExitCommand()const;
  61. void setHasOnExitCommand(bool newHasOnExitCommand);
  62. /// Get QObject associated with this step, to connect signals/slots
  63. QObject* ctkWorkflowStepQObject();
  64. protected:
  65. /// Set step Id
  66. void setId(const QString& newStepId);
  67. /// Set workflow
  68. void setWorkflow(ctkWorkflow* newWorkflow);
  69. void setStatusText(const QString& newText);
  70. /// \brief Get the step's processing state.
  71. ///
  72. /// This state is used to perform the processing associated with this step.
  73. QState* processingState()const;
  74. /// \brief Get the step's validation state.
  75. ///
  76. /// This state is used to validate the processing associated with this step.
  77. QState* validationState()const;
  78. /// \brief Get the step's validation transition.
  79. ///
  80. /// The validation transition is used to bring the state machine
  81. /// from the step's processingState to its validationState.
  82. /// More specifically:
  83. /// <ul>
  84. /// <li>its origin state is the processingState state</li>
  85. /// <li>its destination state is the validationState state</li>
  86. /// </ul>
  87. ///
  88. /// The transition is of type ctkWorkflowTransition with the value
  89. /// ctkWorkflowTransitionType::ValidationTransition.
  90. ctkWorkflowIntrastepTransition* validationTransition()const;
  91. /// \brief Get the step's validation failed transition.
  92. ///
  93. /// The validationFailed transition is used to bring the state
  94. /// machine from the step's validationState state back to its
  95. /// processingState, when validation of the processing step fails
  96. /// (i.e. validate(const QString&) returns false).
  97. ///
  98. /// More specifically:
  99. /// <ul>
  100. /// <li>its origin state is the validatationState state</li>
  101. /// <li>its destination state is the processingState state</li>
  102. /// </ul>
  103. ///
  104. /// The transition is of type ctkWorkflowTransition with the value
  105. /// ctkWorkflowTransitionType::ValidationFailedTransition.
  106. ctkWorkflowIntrastepTransition* validationFailedTransition()const;
  107. /// \brief Reimplement this function for step-specific processing when entering a step.
  108. ///
  109. /// To define a custom step, developers can either reimplement the onEntry() method in a subclass
  110. /// of ctkWorkflowStep, or create a ctkWorkflowStep instance and use signals and slots, as
  111. /// similarly as described for validate().
  112. ///
  113. /// Each step should be self-contained, \a comingFrom and \a transitionType may
  114. /// be used only to decide on how processing should be done for the current step.
  115. ///
  116. /// \param comingFrom gives the step that the state machine was in before
  117. /// transitioning to this step.
  118. ///
  119. /// \param transitionType gives the type of the transition used to get to this step.
  120. virtual void onEntry(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  121. /// \brief Reimplement this function for step-specific processing when exiting a step.
  122. ///
  123. /// To define a custom step, developers can either reimplement the onExit() method
  124. /// in a subclass of ctkWorkflowStep, or create a ctkWorkflowStep instance and use signals and
  125. /// slots, similarly as described for validate().
  126. ///
  127. /// Each step should be self-contained, \a goingTo and \a transitionType may be used only to
  128. /// decide on how processing should be done for the current step.
  129. ///
  130. /// \param goingTo gives the step that the state machine will go to after
  131. /// transitioning from this step.
  132. ///
  133. /// \param transitionType gives the type of the transition used to get to this step.
  134. virtual void onExit(const ctkWorkflowStep* goingTo,
  135. const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);
  136. /// \brief Validates the computation performed in this step's processing state.
  137. ///
  138. /// When creating a custom step, developers can create a validate(const QString&) method is one of two ways:
  139. /// 1) Reimplement the validate(const QString&) method in a subclass of
  140. /// ctkWorkflowStep, following these instructions:
  141. /// <ul>
  142. /// <li>emit the signal ctkWorkflowStep::validateComplete(bool, const QString&) (true on successful validation,
  143. /// false on failure; the QString is the desired branchId to use with branching workflows)</li>
  144. /// </ul>
  145. //
  146. /// OR:
  147. ///
  148. /// 2) Create an instance of a ctkWorkflowStep then:
  149. /// <ul>
  150. /// <li>Call setHasValidateCommand(1) on the step
  151. /// <li>Create a slot foo() associated with any QObject*, following these instructions:</li>
  152. /// <ul>
  153. /// <li>Emit a signal bar(int, const QString&) (true on successful validation, false on
  154. /// failure)</li>
  155. /// <li>Set the following two connections:</li>
  156. /// <ul>
  157. /// <li>QObject::connect(step, SIGNAL(invokeValidateCommand(const QString&)), object,
  158. /// SLOT(foo(const QString&)))</li>
  159. /// <li>QObject::connect(object, SIGNAl(bar(bool, const QString&)), workflow,
  160. /// SLOT(evaluateValidationResults(bool, const QString&)))</li>
  161. /// </ul>
  162. /// </ul>
  163. /// </ul>
  164. virtual void validate(const QString& desiredBranchId = QString());
  165. /// \brief Signal (emitted by the private implementation) indicating that validation of this
  166. /// step's processing should be performed.
  167. ///
  168. /// \sa validation()
  169. void invokeValidateCommand(const QString& desiredBranchId = QString())const;
  170. /// \brief Signal (emitted by the private implementation) indicating that validation of this
  171. /// step's processing has completed.
  172. ///
  173. /// \sa validation()
  174. void validationComplete(bool validationSuceeded, const QString& branchId = QString())const;
  175. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onEntry'
  176. /// processing should be performed.
  177. ///
  178. /// \sa onEntry()
  179. void invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const;
  180. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onEntry'
  181. /// processing has completed.
  182. ///
  183. /// \sa onEntry()
  184. void onEntryComplete()const;
  185. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onExit'
  186. /// processing should be performed.
  187. ///
  188. /// \sa onExit()
  189. void invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const;
  190. /// \brief Signal (emitted by the private implementation) indicating that the step's 'onExit'
  191. /// processing has completed.
  192. ///
  193. /// \sa onExit()
  194. void onExitComplete()const;
  195. protected:
  196. QScopedPointer<ctkWorkflowStepPrivate> d_ptr;
  197. private:
  198. Q_DECLARE_PRIVATE(ctkWorkflowStep);
  199. Q_DISABLE_COPY(ctkWorkflowStep);
  200. friend class ctkWorkflow; // For access to processingState, validationState, setWorkflow, validate
  201. friend class ctkWorkflowPrivate; // For access to invokeOn{Entry,Exit}Command, on{Entry,Exit}
  202. };
  203. #endif