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 
155 
164 
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 
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 
214 
216  virtual void goToStepSucceeded();
217 
219  virtual void goToStepFailed();
220 
223 
224 protected Q_SLOTS:
225 
229 
236 
237 Q_SIGNALS:
241 
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 is the basis for a workflow step.
ctkWorkflow is the basis for a workflow engine, i.e. a state machine with enhancements to support ctk...
Definition: ctkWorkflow.h:40
Q_INVOKABLE QList< ctkWorkflowStep * > forwardSteps(ctkWorkflowStep *step=0) const
void goToProcessingStateAfterValidationFailed()
Q_INVOKABLE bool hasTransition(ctkWorkflowStep *origin, ctkWorkflowStep *destination, const QString &branchId=QString(), const ctkWorkflow::TransitionDirectionality directionality=ctkWorkflow::Bidirectional)
Determine whether a transition has already been added.
Q_INVOKABLE ctkWorkflowStep * initialStep() const
Set/get the initial step.
ctkWorkflow(QObject *parent=0)
void performTransitionBetweenSteps()
Called when transitioning to the next step upon successful validation, or when transitioning to the p...
Q_INVOKABLE int backwardDistanceToStep(ctkWorkflowStep *fromStep=0, ctkWorkflowStep *origin=0) const
TransitionDirectionality
Transition directionalities.
Definition: ctkWorkflow.h:75
virtual void goToStepFailed()
Processing that occurs after the attempt to go to a 'goTo' step fails.
virtual Q_INVOKABLE void start()
Start the workflow. The workflow will always start in the initial step, even if it is stopped and res...
Q_INVOKABLE QList< ctkWorkflowStep * > finishSteps() const
Get the steps that are 'finish' steps (i.e. have no step following them)
void setVerbose(bool value)
void currentStepChanged(ctkWorkflowStep *currentStep)
virtual void goToStep(const QString &targetId)
Go to the given step by iteratively calling goForward() until we reach it.
virtual Q_INVOKABLE void stop()
Stops the workflow.
void setGoBackToOriginStepUponSuccess(bool flag)
void goFromGoToStepToStartingStep()
Goes to the step from which the attempt to go to the 'goTo' step was initiated.
virtual Q_INVOKABLE bool addTransition(ctkWorkflowStep *origin, ctkWorkflowStep *destination, const QString &branchId=QString(), const ctkWorkflow::TransitionDirectionality directionality=ctkWorkflow::Bidirectional)
Creates a transition between two steps, and adds the two steps to the workflow if they have not been ...
Q_INVOKABLE QList< ctkWorkflowStep * > steps() const
Returns list of steps managed by the workflow.
virtual void evaluateValidationResults(bool validationSucceeded, const QString &branchId)
Receives the result of a step's validate(const QString&) function.
bool verbose() const
If set debug messages will be displayed on standard output.
Q_INVOKABLE bool canGoBackward(ctkWorkflowStep *step=0) const
Q_INVOKABLE bool canGoToStep(const QString &targetId, ctkWorkflowStep *step=0) const
QScopedPointer< ctkWorkflowPrivate > d_ptr
Definition: ctkWorkflow.h:247
void stepRegistered(ctkWorkflowStep *step)
void attemptToGoToNextStep()
Q_INVOKABLE bool hasStep(const QString &id) const
void goToNextStepAfterSuccessfulValidation(const QString &branchId)
virtual Q_INVOKABLE void setInitialStep(ctkWorkflowStep *step)
bool goBackToOriginStepUponSuccess() const
virtual void goToStepSucceeded()
Processing that occurs after the attempt to go to a 'goTo' step succeeds.
Q_INVOKABLE ctkWorkflowStep * step(const QString &id) const
bool isRunning() const
Returns whether the workflow is currently running.
virtual ~ctkWorkflow()
QObject Superclass
Definition: ctkWorkflow.h:49
virtual void goBackward(const QString &desiredBranchId=QString())
Use this to trigger transition to the previous step (does not require validation)
Q_INVOKABLE QList< ctkWorkflowStep * > backwardSteps(ctkWorkflowStep *step=0) const
Q_INVOKABLE ctkWorkflowStep * currentStep() const
Q_INVOKABLE bool canGoForward(ctkWorkflowStep *step=0) const
virtual void goForward(const QString &desiredBranchId=QString())