123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- /*=========================================================================
- Library: CTK
- Copyright (c) Kitware Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0.txt
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =========================================================================*/
- // Qt includes
- #include <QDebug>
- #include <QMetaType>
- #include <QObject>
- #include <QState>
- // CTK includes
- #include "ctkWorkflowStep.h"
- #include "ctkWorkflowStep_p.h"
- #include "ctkWorkflow.h"
- // STD includes
- #include <iostream>
- // --------------------------------------------------------------------------
- // ctkWorkflowStepPrivate methods
- // --------------------------------------------------------------------------
- ctkWorkflowStepPrivate::ctkWorkflowStepPrivate(ctkWorkflowStep& object)
- :q_ptr(&object)
- {
- qRegisterMetaType<ctkWorkflowStep*>("ctkWorkflowStep*");
- this->Workflow = 0;
- this->WidgetType = false;
- this->HasValidateCommand = false;
- this->HasOnEntryCommand = false;
- this->HasOnExitCommand = false;
- // Create state
- this->ProcessingState = new QState();
- this->ValidationState = new QState();
- // Create 'validation' transition
- this->ValidationTransition =
- new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationTransition);
- this->ValidationTransition->setTargetState(this->ValidationState);
- this->ProcessingState->addTransition(this->ValidationTransition);
- // Create 'failed validation' transation
- this->ValidationFailedTransition = 0;
- this->ValidationFailedTransition =
- new ctkWorkflowIntrastepTransition(ctkWorkflowIntrastepTransition::ValidationFailedTransition);
- this->ValidationFailedTransition->setTargetState(this->ProcessingState);
- this->ValidationState->addTransition(this->ValidationFailedTransition);
- }
- // --------------------------------------------------------------------------
- ctkWorkflowStepPrivate::~ctkWorkflowStepPrivate()
- {
- if (!this->ValidationState.isNull())
- {
- delete this->ValidationState;
- }
- if (!this->ProcessingState.isNull())
- {
- delete this->ProcessingState;
- }
- // If we delete the states, then Qt will handle deleting the transitions
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::validationCompleteInternal(bool validationResults, const QString& branchId)const
- {
- emit validationComplete(validationResults, branchId);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::onEntryCompleteInternal()const
- {
- emit onEntryComplete();
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::onExitCompleteInternal()const
- {
- emit onExitComplete();
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::invokeValidateCommandInternal(const QString& desiredBranchId)const
- {
- emit invokeValidateCommand(desiredBranchId);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::invokeOnEntryCommandInternal(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
- {
- emit invokeOnEntryCommand(comingFrom, transitionType);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStepPrivate::invokeOnExitCommandInternal(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
- {
- emit invokeOnExitCommand(goingTo, transitionType);
- }
- // --------------------------------------------------------------------------
- // ctkWorkflowStep methods
- // --------------------------------------------------------------------------
- ctkWorkflowStep::ctkWorkflowStep(): d_ptr(new ctkWorkflowStepPrivate(*this))
- {
- }
- // --------------------------------------------------------------------------
- ctkWorkflowStep::ctkWorkflowStep(const QString& newId)
- : d_ptr(new ctkWorkflowStepPrivate(*this))
- {
- Q_D(ctkWorkflowStep);
- d->Id = newId;
- }
- // --------------------------------------------------------------------------
- ctkWorkflowStep::ctkWorkflowStep(ctkWorkflowStepPrivate * pimpl,
- const QString& newId):d_ptr(pimpl)
- {
- Q_D(ctkWorkflowStep);
- d->Id = newId;
- }
- // --------------------------------------------------------------------------
- ctkWorkflowStep::~ctkWorkflowStep()
- {
- }
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, ctkWorkflow*, workflow, Workflow);
- CTK_SET_CPP(ctkWorkflowStep, ctkWorkflow*, setWorkflow, Workflow);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, QString, id, Id);
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::setId(const QString& newId)
- {
- Q_D(ctkWorkflowStep);
- if (d->Workflow && d->Workflow->hasStep(newId) && !this->id().isEmpty())
- {
- qWarning() << QString("ctkWorkflowStep - Failed to change id from '%1' to '%2' - "
- "Step already added to a workflow !").arg(this->id()).arg(newId);
- return;
- }
- d->Id = newId;
- }
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, QString, name, Name);
- CTK_SET_CPP(ctkWorkflowStep, const QString&, setName, Name);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, QString, description, Description);
- CTK_SET_CPP(ctkWorkflowStep, const QString&, setDescription, Description);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, QString, statusText, StatusText);
- CTK_SET_CPP(ctkWorkflowStep, const QString&, setStatusText, StatusText);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, bool, hasValidateCommand, HasValidateCommand);
- CTK_SET_CPP(ctkWorkflowStep, bool, setHasValidateCommand, HasValidateCommand);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, bool, hasOnEntryCommand, HasOnEntryCommand);
- CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnEntryCommand, HasOnEntryCommand);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, bool, hasOnExitCommand, HasOnExitCommand);
- CTK_SET_CPP(ctkWorkflowStep, bool, setHasOnExitCommand, HasOnExitCommand);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, QState*, processingState, ProcessingState);
- CTK_GET_CPP(ctkWorkflowStep, QState*, validationState, ValidationState);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*, validationTransition, ValidationTransition);
- CTK_GET_CPP(ctkWorkflowStep, ctkWorkflowIntrastepTransition*,
- validationFailedTransition, ValidationFailedTransition);
- // --------------------------------------------------------------------------
- CTK_GET_CPP(ctkWorkflowStep, bool, isWidgetType, WidgetType);
- // --------------------------------------------------------------------------
- QObject* ctkWorkflowStep::ctkWorkflowStepQObject()
- {
- Q_D(ctkWorkflowStep);
- return d;
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::validationComplete(bool validationResults, const QString& branchId)const
- {
- Q_D(const ctkWorkflowStep);
- d->validationCompleteInternal(validationResults, branchId);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::onEntryComplete()const
- {
- Q_D(const ctkWorkflowStep);
- d->onEntryCompleteInternal();
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::onExitComplete()const
- {
- Q_D(const ctkWorkflowStep);
- d->onExitCompleteInternal();
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::invokeValidateCommand(const QString& desiredBranchId)const
- {
- Q_D(const ctkWorkflowStep);
- d->invokeValidateCommandInternal(desiredBranchId);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::invokeOnEntryCommand(const ctkWorkflowStep* comingFrom, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
- {
- Q_D(const ctkWorkflowStep);
- d->invokeOnEntryCommandInternal(comingFrom, transitionType);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::invokeOnExitCommand(const ctkWorkflowStep* goingTo, const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)const
- {
- Q_D(const ctkWorkflowStep);
- d->invokeOnExitCommandInternal(goingTo, transitionType);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::validate(const QString& desiredBranchId)
- {
- Q_D(ctkWorkflowStep);
- if (this->workflow()->verbose())
- {
- qDebug() << QString("validate - validating the input from %1").arg(d->Name);
- }
- this->validationComplete(true, desiredBranchId);
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::onEntry(const ctkWorkflowStep* comingFrom,
- const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
- {
- Q_UNUSED(comingFrom);
- Q_UNUSED(transitionType);
- // Signals that we are finished
- this->onEntryComplete();
- }
- // --------------------------------------------------------------------------
- void ctkWorkflowStep::onExit(const ctkWorkflowStep* goingTo,
- const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType)
- {
- Q_UNUSED(goingTo);
- Q_UNUSED(transitionType);
- // Signals that we are finished
- this->onExitComplete();
- }
|