Computer Assited Medical Intervention Tool Kit  version 5.0
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-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
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:433
SaveActionState::saveComponentsInfo::type
QString type
Definition: SaveActionState.h:88
ActionStateMachine::finished
void finished()
finish everything properly when the state machine entered the final state and quit
Definition: ActionStateMachine.cpp:662
Explorer
The Explorer viewer displays the list of all data currently opened in the application....
Definition: Explorer.h:64
ActionStateWizard::getLogDirectory
QString getLogDirectory()
Return the current directory name to use as output log directory.
Definition: ActionStateWizard.cpp:54
ActionStateMachine::createAllActionStates
void createAllActionStates(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:678
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:266
ActionStateWizard.h
camitk::MainWindow::redirectToConsole
virtual void redirectToConsole(bool)
use or not the application console (redirect or not standard out/err streams)
Definition: MainWindow.cpp:393
ActionStateViewerExtension
Definition: ActionStateViewerExtension.h:32
ActionState.h
AbortException.h
ActionStateMachine::autoNext
void autoNext()
Automatically loop to apply to next state for all states.
Definition: ActionStateMachine.cpp:506
MedicalImageViewer
All-in-one medical image viewer.
Definition: MedicalImageViewer.h:59
camitk::Application::setMainWindow
void setMainWindow(MainWindow *mw)
set the main window.
Definition: Application.cpp:251
ActionState
The state (in a state machine point of view) corresponding to the current processed action.
Definition: ActionState.h:48
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:593
ActionStateMachine.h
ActionStateMachine::name
QString name
Application's name.
Definition: ActionStateMachine.h:122
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:148
camitk::Application::registerAllViewers
static int registerAllViewers(ViewerExtension *)
register all viewers from the given ViewerExtension
Definition: Application.cpp:918
ActionStateViewerExtension.h
ActionStateMachine::scxmlDoc
QDomDocument scxmlDoc
XML tree containing infos.
Definition: ActionStateMachine.h:131
ActionStateMachine::stringToStatus
QVector< camitk::Action::ApplyStatus > stringToStatus(QString listOfStatus)
Definition: ActionStateMachine.cpp:837
ActionStateViewerExtension::init
virtual void init() override
initialize all the actions
Definition: ActionStateViewerExtension.cpp:33
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:153
camitk::Action
Action class is an abstract class that enables you to build a action (generally on a component)....
Definition: Action.h:231
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:82
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:864
camitk::AbortException
Exception class to handle abortion in component instantiation. Particularly useful to handle construc...
Definition: AbortException.h:66
CAMITK_ERROR
#define CAMITK_ERROR(MSG)
Log for error verbosity (the minimum verbosity) Will always appear.
Definition: Log.h:276
ActionStateMachine
This Class describes ActionStateMachine MainWindow extension. This application use a modified version...
Definition: ActionStateMachine.h:58
MedicalImageViewer.h
ActionStateMachine::getDomNodeLocation
QString getDomNodeLocation(QDomNode)
build a specific error message containing the line and column if available
Definition: ActionStateMachine.cpp:987
camitk::ViewerExtension::initResources
void initResources()
Load, for the selected langage (asked to the Application), the associated .qm file.
Definition: ViewerExtension.cpp:80
ActionStateMachine::machine
QStateMachine machine
Actual state machine.
Definition: ActionStateMachine.h:125
SaveActionState::setInput
void setInput(QVector< saveComponentsInfo > inputComponentsInfo)
Definition: SaveActionState.cpp:47
ActionStateMachine::setCamiTKSaveAction
void setCamiTKSaveAction(SaveActionState *actionState, QDomElement actionElement)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:951
ActionStateMachine::startTime
QTime * startTime
To get track of the Action State Machine the duration.
Definition: ActionStateMachine.h:143
ActionStateWizard::getSCXMLFilename
QString getSCXMLFilename()
Return the current filename of scxml file to use as input file.
Definition: ActionStateWizard.cpp:49
camitk::MainWindow::setCentralViewer
virtual void setCentralViewer(Viewer *)
set the central Viewer of the application.
Definition: MainWindow.cpp:323
ActionTransition.h
ActionStateMachine::logFile
QFile * logFile
Log file.
Definition: ActionStateMachine.h:149
SaveActionState::saveComponentsInfo::name
QString name
Definition: SaveActionState.h:87
MainWindow.h
SaveActionState::saveComponentsInfo::extension
QString extension
Definition: SaveActionState.h:89
ActionStateViewer
The current action state viewer.
Definition: ActionStateViewer.h:45
ActionStateMachine::saveDirectory
QDir saveDirectory
Where to save all files.
Definition: ActionStateMachine.h:140
ActionStateMachine::ActionStateMachine
ActionStateMachine(int &argc, char **argv, QString inputFileName="", QString outputDirectory="")
construtor.
Definition: ActionStateMachine.cpp:52
ActionTransition
This class handle a transition between two states (including previous/next buttons)....
Definition: ActionTransition.h:59
MedicalImageViewer::setToolbarAutoVisibility
virtual void setToolbarAutoVisibility(bool)
force toolbar visibility.
Definition: MedicalImageViewer.cpp:302
camitk::MainWindow::showStatusBar
void showStatusBar(bool)
show the status bar (by default it is hidden)
Definition: MainWindow.cpp:383
camitk::Application::getName
static QString getName()
get the application name
Definition: Application.cpp:203
camitk::MainWindow
This class is the base class for your application. It sets up the main window and creates a menubar,...
Definition: MainWindow.h:89
SaveActionState::saveComponentsInfo::directory
QString directory
Definition: SaveActionState.h:90
ActionStateMachine::createTransitions
void createTransitions(QDomNodeList nodeList)
This method may throw an AbortException if a problem occurs.
Definition: ActionStateMachine.cpp:768
CAMITK_TRACE
#define CAMITK_TRACE(MSG)
Log for trace verbosity (the most verbose one, should be used for bug report) The msg will appear onl...
Definition: Log.h:256
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:627
ActionTransition::autoNext
void autoNext()
programmatically activate the transition (during autoNext), i.e. call "click" on the button
Definition: ActionTransition.cpp:161
ActionStateWizard
This dialog is shown only if at least one of the two required input parameters (SCXML and output dire...
Definition: ActionStateWizard.h:39
ActionStateMachine::getSaveDirectory
QString getSaveDirectory()
where to save the files
Definition: ActionStateMachine.cpp:982
ActionStateMachine::initMainWindow
void initMainWindow()
initialized main window
Definition: ActionStateMachine.cpp:558
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:299
ActionState::setAlternativeDesc
void setAlternativeDesc(QString altDescText, QVector< camitk::Action::ApplyStatus > statusList)
May change its description according to the previous action result.
Definition: ActionState.cpp:161
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:223
Core.h
ActionStateMachine::finalState
QFinalState * finalState
Final State.
Definition: ActionStateMachine.h:137
ExtensionManager.h
camitk::Application::argc
static int argc
argc given from command line
Definition: Application.h:430
ActionStateViewer.h
ActionStateMachine::statesMap
QMap< QString, ActionState * > statesMap
Map of action state to build transitions.
Definition: ActionStateMachine.h:134
ActionStateMachine::mainWindow
camitk::MainWindow * mainWindow
main window
Definition: ActionStateMachine.h:128
SaveActionState
The asm application uses a state machine. This class implements the state of action save.
Definition: SaveActionState.h:37
SaveActionState::saveComponentsInfo
Definition: SaveActionState.h:63
Application.h
camitk
Definition: Action.cpp:35
ActionStateMachine::logStream
QTextStream * logStream
Log stream to write report on logFile.
Definition: ActionStateMachine.h:146