Computer Assited Medical Intervention Tool Kit  version 4.1
ActionStateMachine.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 
27 #ifndef ACTIONSTATEMACHINE_H
28 #define ACTIONSTATEMACHINE_H
29 
30 
31 // -- Qt stuff
32 #include <QTextStream>
33 #include <QStateMachine>
34 #include <QState>
35 #include <QFinalState>
36 #include <QDir>
37 
38 // -- Qt XML stuff
39 #include <QtXml/QDomDocument>
40 #include <QtXml/QDomNodeList>
41 
42 // -- CamiTK Core stuff
43 #include <AbortException.h>
44 #include <Application.h>
45 
46 // -- CamiTK Local stuff
47 #include "ActionState.h"
48 #include "SaveActionState.h"
49 
59  Q_OBJECT
60 
61 public:
65  ActionStateMachine(int& argc, char** argv, QString inputFileName = "", QString outputDirectory = "");
66 
68  virtual ~ActionStateMachine() = default;
69 
71  QString getSaveDirectory();
72 
73 public slots:
75  void autoNext();
76 
77 private slots:
79  void finished();
80 
81 protected:
83  void initMainWindow();
84 
88  void checkSCXMLFile(QString filename);
89 
93  QString parseSCXMLTree();
94 
97 
99  QString name;
100 
102  QStateMachine machine;
103 
106 
108  QDomDocument scxmlDoc;
109 
111  QMap<QString, ActionState*>* statesMap;
112 
114  QFinalState* finalState;
115 
117  QDir saveDirectory;
118 
120  QTime* startTime;
121 
123  QTextStream* logStream;
124 
126  QFile* logFile;
127 
129 
130 private:
133 
135  void createAllActionStates(QDomNodeList nodeList);
136 
138  void createTransitions(QDomNodeList nodeList);
139 
141  void setCamiTKAction(ActionState* actionState, QDomElement actionElement);
142 
144  void setCamiTKSaveAction(SaveActionState* actionState, QDomElement actionElement);
145 
146  QVector<camitk::Action::ApplyStatus> stringToStatus(QString listOfStatus);
148 
150  QString getDomNodeLocation(QDomNode);
151 };
152 
153 #endif // ACTIONSTATEMACHINE_H
camitk::Application::argv
static char ** argv
argv given from command line
Definition: Application.h:371
SaveActionState::saveComponentsInfo::type
QString type
Definition: SaveActionState.h:85
ActionStateMachine::finished
void finished()
finish everything properly when the state machine entered the final state and quit
Definition: ActionStateMachine.cpp:250
ActionStateMachine::createAllActionStates
void createAllActionStates(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:260
ActionState::setAction
void setAction(camitk::Action *action, QMap< QString, QVariant > parameters, QMap< QString, QString > inputComponentNames, QMap< QString, QString > outputComponentNames)
Definition: ActionState.cpp:53
CAMITK_WARNING
#define CAMITK_WARNING(MSG)
Log for warning verbosity (the most common one) Will appear by default.
Definition: Log.h:261
camitk::MainWindow::redirectToConsole
virtual void redirectToConsole(bool)
use or not the application console (redirect or not standard out/err streams)
Definition: MainWindow.cpp:323
camitk::NONE
Definition: RendererWidget.h:177
ActionState.h
AbortException.h
ActionStateMachine::autoNext
void autoNext()
Automatically loop to apply to next state for all states.
Definition: ActionStateMachine.cpp:122
camitk::Application::setMainWindow
void setMainWindow(MainWindow *mw)
set the main window.
Definition: Application.cpp:245
ActionState
The state (in a state machine point of view) corresponding to the current processed action.
Definition: ActionState.h:47
ActionStateMachine::checkSCXMLFile
void checkSCXMLFile(QString filename)
check that the file is a SCXML file (simple checking, no XML Schema validation yet) This method may t...
Definition: ActionStateMachine.cpp:175
ActionStateMachine.h
ActionStateMachine::name
QString name
Application's name.
Definition: ActionStateMachine.h:120
ActionStateMachine::~ActionStateMachine
virtual ~ActionStateMachine()=default
destructor
ActionTransition::isNamed
bool isNamed(QString) const
Check the name of the transition (i.e. text of the button)
Definition: ActionTransition.cpp:147
ActionStateMachine::scxmlDoc
QDomDocument scxmlDoc
XML tree containing infos.
Definition: ActionStateMachine.h:129
ActionStateViewer::getActionStateViewer
static ActionStateViewer * getActionStateViewer()
returns the unique instance oh ActionStateViewer
Definition: ActionStateViewer.cpp:40
ActionStateViewer::setState
void setState(ActionState *actionState)
Definition: ActionStateViewer.cpp:88
ActionStateMachine::stringToStatus
QVector< camitk::Action::ApplyStatus > stringToStatus(QString listOfStatus)
Definition: ActionStateMachine.cpp:416
Log.h
ActionTransition::addComponentToClose
void addComponentToClose(QString compName, QString compType, bool force=false)
add a component's name and type to the list of component to close during the transition.
Definition: ActionTransition.cpp:152
camitk::Action
Action class is an abstract class that enables you to build a action (generally on a component)....
Definition: Action.h:228
ActionState::addActionTransition
ActionTransition * addActionTransition(QString transitionName, QAbstractState *nextState, bool applyAction=true, QVector< camitk::Action::ApplyStatus > disableConditions=QVector< camitk::Action::ApplyStatus >())
Adds a possible transition from this action.
Definition: ActionState.cpp:81
SaveActionState.h
camitk::Application
The generic/default application. Once this class is intanciated in the main, everything is setup....
Definition: Application.h:62
ActionState::getName
QString getName()
Returns the name of the action state (may be different from the name of the actual action)
Definition: ActionState.cpp:66
ActionStateMachine::setCamiTKAction
void setCamiTKAction(ActionState *actionState, QDomElement actionElement)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:443
camitk::AbortException
Exception class to handle abortion in component instantiation. Particularly useful to handle construc...
Definition: AbortException.h:64
CAMITK_ERROR
#define CAMITK_ERROR(MSG)
Log for error verbosity (the minimum verbosity) Will always appear.
Definition: Log.h:271
ActionStateMachine
This Class describes ActionStateMachine MainWindow extension. This application use a modified version...
Definition: ActionStateMachine.h:57
MedicalImageViewer.h
ActionStateMachine::getDomNodeLocation
QString getDomNodeLocation(QDomNode)
build a specific error message containing the line and column if available
Definition: ActionStateMachine.cpp:566
ActionStateMachine::machine
QStateMachine machine
Actual state machine.
Definition: ActionStateMachine.h:123
SaveActionState::setInput
void setInput(QVector< saveComponentsInfo > inputComponentsInfo)
Definition: SaveActionState.cpp:46
ActionStateMachine::setCamiTKSaveAction
void setCamiTKSaveAction(SaveActionState *actionState, QDomElement actionElement)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:530
ActionStateMachine::startTime
QTime * startTime
To get track of the Action State Machine the duration.
Definition: ActionStateMachine.h:141
camitk::MainWindow::setCentralViewer
virtual void setCentralViewer(Viewer *)
set the central Viewer of the application.
Definition: MainWindow.cpp:283
ActionTransition.h
ActionStateMachine::logFile
QFile * logFile
Log file.
Definition: ActionStateMachine.h:147
SaveActionState::saveComponentsInfo::name
QString name
Definition: SaveActionState.h:84
MainWindow.h
SaveActionState::saveComponentsInfo::extension
QString extension
Definition: SaveActionState.h:86
ActionStateMachine::saveDirectory
QDir saveDirectory
Where to save all files.
Definition: ActionStateMachine.h:138
ActionStateMachine::ActionStateMachine
ActionStateMachine(int &argc, char **argv, QString inputFileName="", QString outputDirectory="")
construtor.
Definition: ActionStateMachine.cpp:50
ActionTransition
This class handle a transition between two states (including previous/next buttons)....
Definition: ActionTransition.h:58
camitk::MainWindow::showStatusBar
void showStatusBar(bool)
show the status bar (by default it is hidden)
Definition: MainWindow.cpp:312
camitk::MainWindow
This Class is the base class for your application. It sets up the main window and providing a menubar...
Definition: MainWindow.h:83
SaveActionState::saveComponentsInfo::directory
QString directory
Definition: SaveActionState.h:87
ActionStateMachine::createTransitions
void createTransitions(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:347
Explorer.h
ActionStateMachine::parseSCXMLTree
QString parseSCXMLTree()
parse the XML file (using Qt DOM API) This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:209
ActionTransition::autoNext
void autoNext()
programmatically activate the transition (during autoNext), i.e. call "click" on the button
Definition: ActionTransition.cpp:160
ActionStateMachine::getSaveDirectory
QString getSaveDirectory()
where to save the files
Definition: ActionStateMachine.cpp:561
ActionStateMachine::statesMap
QMap< QString, ActionState * > * statesMap
Map of action state to build transitions.
Definition: ActionStateMachine.h:132
ActionStateMachine::initMainWindow
void initMainWindow()
initialized main window
Definition: ActionStateMachine.cpp:154
camitk::MainWindow::addDockViewer
virtual void addDockViewer(Qt::DockWidgetArea, Viewer *)
add a Viewer to the application as a docking widget and specify where it has to be docked Note that M...
Definition: MainWindow.cpp:259
ActionState::setAlternativeDesc
void setAlternativeDesc(QString altDescText, QVector< camitk::Action::ApplyStatus > statusList)
May change its description according to the previous action result.
Definition: ActionState.cpp:155
camitk::MainWindow::setWindowSubtitle
void setWindowSubtitle(QString)
The subtitle is situated at the end of the title, on the title bar, is helps for example showing whic...
Definition: MainWindow.cpp:202
Core.h
ActionStateMachine::finalState
QFinalState * finalState
Final State.
Definition: ActionStateMachine.h:135
ExtensionManager.h
camitk::Application::argc
static int argc
argc given from command line
Definition: Application.h:368
ActionStateViewer.h
ActionStateMachine::mainWindow
camitk::MainWindow * mainWindow
main window
Definition: ActionStateMachine.h:126
SaveActionState
The asm application uses a state machine. This class implements the state of action save.
Definition: SaveActionState.h:36
SaveActionState::saveComponentsInfo
Definition: SaveActionState.h:61
Application.h
camitk
Definition: Action.cpp:36
ActionStateMachine::logStream
QTextStream * logStream
Log stream to write report on logFile.
Definition: ActionStateMachine.h:144