CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkWorkflow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkWorkflow_h
22 #define __ctkWorkflow_h
23 
24 // Qt includes
25 #include <QObject>
26 
27 // CTK includes
28 #include "ctkPimpl.h"
29 #include "ctkCoreExport.h"
30 
31 class ctkWorkflowStep;
32 class ctkWorkflowPrivate;
33 class QAbstractState;
34 
38 
39 class CTK_CORE_EXPORT ctkWorkflow : public QObject
40 {
41  Q_OBJECT
43  Q_PROPERTY(bool isRunning READ isRunning DESIGNABLE false)
44  Q_PROPERTY(bool goBackToOriginStepUponSuccess READ goBackToOriginStepUponSuccess WRITE setGoBackToOriginStepUponSuccess)
45  Q_PROPERTY(bool verbose READ verbose WRITE setVerbose)
46 
47 public:
48 
49  typedef QObject Superclass;
50  explicit ctkWorkflow(QObject* parent = 0);
51  virtual ~ctkWorkflow();
52 
56  Q_INVOKABLE virtual void start();
57 
59  bool isRunning()const;
60 
63  Q_INVOKABLE virtual void stop();
64 
75  {
76  Bidirectional = 0,
78  Backward
79  };
80 
90  Q_INVOKABLE virtual bool addTransition(ctkWorkflowStep* origin, ctkWorkflowStep* destination,
91  const QString& branchId = QString(),
92  const ctkWorkflow::TransitionDirectionality directionality
94 
104  Q_INVOKABLE bool hasTransition(ctkWorkflowStep* origin, ctkWorkflowStep* destination,
105  const QString& branchId = QString(),
106  const ctkWorkflow::TransitionDirectionality directionality
108 
112  Q_INVOKABLE ctkWorkflowStep* initialStep()const;
113  Q_INVOKABLE virtual void setInitialStep(ctkWorkflowStep* step);
114 
117  Q_INVOKABLE ctkWorkflowStep* currentStep()const;
118 
121  Q_INVOKABLE bool hasStep(const QString& id)const;
122 
125  Q_INVOKABLE ctkWorkflowStep* step(const QString& id)const;
126 
131  Q_INVOKABLE bool canGoForward(ctkWorkflowStep* step=0)const;
132 
137  Q_INVOKABLE bool canGoBackward(ctkWorkflowStep* step=0)const;
138 
145  Q_INVOKABLE bool canGoToStep(const QString& targetId, ctkWorkflowStep* step=0)const;
146 
154  Q_INVOKABLE QList<ctkWorkflowStep*> forwardSteps(ctkWorkflowStep* step=0)const;
155 
163  Q_INVOKABLE QList<ctkWorkflowStep*> backwardSteps(ctkWorkflowStep* step=0)const;
164 
166  Q_INVOKABLE QList<ctkWorkflowStep*> finishSteps()const;
167 
169  Q_INVOKABLE QList<ctkWorkflowStep*> steps()const;
170 
171  // Returns the distance of a given to step to another step.
172  // The directionality used here is ctkWorkflow::Bidirectional or ctkWorkflow::Backward.
173  // By default, step is the current step and origin the initial step.
174  //
175  // This is different from the other method as it's not limited to the backward or forward steps
176  // but actually performs a recursive search.
177  Q_INVOKABLE int backwardDistanceToStep(ctkWorkflowStep* fromStep = 0, ctkWorkflowStep* origin = 0)const;
178 
185  bool goBackToOriginStepUponSuccess()const;
186  void setGoBackToOriginStepUponSuccess(bool flag);
187 
189  bool verbose()const;
190  void setVerbose(bool value);
191 
192 public Q_SLOTS:
193 
196  virtual void goForward(const QString& desiredBranchId = QString());
197 
199  virtual void goBackward(const QString& desiredBranchId = QString());
200 
202  virtual void goToStep(const QString& targetId);
203 
207  virtual void evaluateValidationResults(bool validationSucceeded, const QString& branchId);
208 
209 protected:
210 
211  void goToNextStepAfterSuccessfulValidation(const QString& branchId);
212 
213  void goToProcessingStateAfterValidationFailed();
214 
216  virtual void goToStepSucceeded();
217 
219  virtual void goToStepFailed();
220 
222  void goFromGoToStepToStartingStep();
223 
224 protected Q_SLOTS:
225 
228  void attemptToGoToNextStep();
229 
235  void performTransitionBetweenSteps();
236 
237 Q_SIGNALS:
240  void currentStepChanged(ctkWorkflowStep* currentStep);
241 
244  void stepRegistered(ctkWorkflowStep* step);
245 
246 protected:
247  QScopedPointer<ctkWorkflowPrivate> d_ptr;
248 
249 private:
250  Q_DECLARE_PRIVATE(ctkWorkflow);
251  Q_DISABLE_COPY(ctkWorkflow);
252 };
253 
254 #endif
255 
ctkWorkflowStep
ctkWorkflowStep is the basis for a workflow step.
Definition: ctkWorkflowStep.h:45
ctkWorkflow
ctkWorkflow is the basis for a workflow engine, i.e. a state machine with enhancements to support ctk...
Definition: ctkWorkflow.h:39
QList
Definition: ctkCmdLineModuleBackend.h:30
ctkWorkflow::Bidirectional
@ Bidirectional
Definition: ctkWorkflow.h:76
ctkWorkflow::Forward
@ Forward
Definition: ctkWorkflow.h:77
ctkWorkflow::Superclass
QObject Superclass
Definition: ctkWorkflow.h:49
ctkWorkflow::d_ptr
QScopedPointer< ctkWorkflowPrivate > d_ptr
Definition: ctkWorkflow.h:247
ctkWrapPythonQt.verbose
verbose
Definition: ctkWrapPythonQt.py:235
ctkWorkflow::TransitionDirectionality
TransitionDirectionality
Transition directionalities.
Definition: ctkWorkflow.h:74
ctkPimpl.h