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 
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
QFinalState * finalState
Final State.
Definition: ActionStateMachine.h:114
The generic/default application.
Definition: Application.h:63
virtual ~ActionStateMachine()=default
destructor
void finished()
finish everything properly when the state machine entered the final state and quit ...
Definition: ActionStateMachine.cpp:250
QVector< camitk::Action::ApplyStatus > stringToStatus(QString listOfStatus)
Definition: ActionStateMachine.cpp:416
static int argc
argc given from command line
Definition: Application.h:369
This Class is the base class for your application.
Definition: MainWindow.h:62
void setCamiTKAction(ActionState *actionState, QDomElement actionElement)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:443
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
void setCamiTKSaveAction(SaveActionState *actionState, QDomElement actionElement)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:530
QString getDomNodeLocation(QDomNode)
build a specific error message containing the line and column if available
Definition: ActionStateMachine.cpp:566
QString name
Application&#39;s name.
Definition: ActionStateMachine.h:99
The state (in a state machine point of view) corresponding to the current processed action...
Definition: ActionState.h:48
ActionStateMachine(int &argc, char **argv, QString inputFileName="", QString outputDirectory="")
construtor.
Definition: ActionStateMachine.cpp:50
QDomDocument scxmlDoc
XML tree containing infos.
Definition: ActionStateMachine.h:108
void createTransitions(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:347
static char ** argv
argv given from command line
Definition: Application.h:372
QString parseSCXMLTree()
parse the XML file (using Qt DOM API) This method may throw an AbortException if a problem occurs...
Definition: ActionStateMachine.cpp:209
void initMainWindow()
initialized main window
Definition: ActionStateMachine.cpp:154
This Class describes ActionStateMachine MainWindow extension.
Definition: ActionStateMachine.h:58
camitk::MainWindow * mainWindow
main window
Definition: ActionStateMachine.h:105
QStateMachine machine
Actual state machine.
Definition: ActionStateMachine.h:102
QTextStream * logStream
Log stream to write report on logFile.
Definition: ActionStateMachine.h:123
QFile * logFile
Log file.
Definition: ActionStateMachine.h:126
QTime * startTime
To get track of the Action State Machine the duration.
Definition: ActionStateMachine.h:120
The asm application uses a state machine.
Definition: SaveActionState.h:37
void createAllActionStates(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:260
QDir saveDirectory
Where to save all files.
Definition: ActionStateMachine.h:117
void autoNext()
Automatically loop to apply to next state for all states.
Definition: ActionStateMachine.cpp:122
QString getSaveDirectory()
where to save the files
Definition: ActionStateMachine.cpp:561
QMap< QString, ActionState * > * statesMap
Map of action state to build transitions.
Definition: ActionStateMachine.h:111