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