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