Computer Assisted Medical Intervention Tool Kit  version 6.0
Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1/*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, 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#ifndef CAMITKAPPLICATION_H
27#define CAMITKAPPLICATION_H
28
29// -- Core stuff
30#include "CamiTKAPI.h"
31#include "InterfaceLogger.h"
32
33// -- QT stuff
34#include <QApplication>
35#include <QSettings>
36#include <QDir>
37#include <QFileInfo>
38#include <QStack>
39#include <QList>
40#include <QTranslator>
41
42class vtkObject;
43namespace camitk {
44class MainWindow;
45class ActionExtension;
46class ViewerExtension;
47class Action;
48class Viewer;
49class HistoryItem;
51class Property;
52class PropertyObject;
53class SplashScreen;
54
83class CAMITK_API Application : public QApplication {
84 Q_OBJECT
85
86public:
87
110 Application(QString name, int& argc, char** argv, bool autoloadExtension = true, bool registerFileExtension = false, bool useSplashScreen = false);
111
113 ~Application() override;
114
118
120 bool notify(QObject*, QEvent*) override;
121
123 static QString getName();
124
140 static QSettings& getSettings();
141
154 static int exec();
155
157 static void restart(QString reason);
158
161 static const QDir getLastUsedDirectory();
162
164 static void setLastUsedDirectory(QDir);
165
169 static void addRecentDocument(QString);
170
173
175 static const int getMaxRecentDocuments();
176
178
182
188 static Component* open(const QString& fileName, bool blockRefresh = false);
189
194 static Component* openDirectory(const QString& dirName, const QString& pluginName);
195
198 static bool loadWorkspace(const QString& filepath);
199
205 static bool close(Component* component, bool blockRefresh = false);
206
212 static bool save(Component* component);
213
218 static bool saveWorkspace(const QString& filepath);
219
227 static QString getUniqueComponentName(QString name, const ComponentList& components = getTopLevelComponents());
228
233 static const ComponentList& getTopLevelComponents();
234
239 static const ComponentList& getAllComponents();
240
242 static bool isAlive(Component*);
243
245 static bool isAlive(Action*);
246
248 static bool hasModified();
249
251
256
260 static const ComponentList& getSelectedComponents();
261
265 static void clearSelectedComponents();
267
270
272 static Action* getAction(QString);
273
275 static const ActionList getActions();
276
279
282
284 static ActionList getActions(ComponentList, QString);
285
290
295
299 static void setTriggeredAction(Action* action);
300
302 static Action* getTriggeredAction();
304
307
309 static Viewer* getViewer(QString name);
310
314 static Viewer* getNewViewer(QString name, QString className);
315
317 static const ViewerList getViewers();
318
320 static const ViewerList getViewers(Component*);
321
323 static bool registerViewer(Viewer*);
324
330
336
340
352 void setMainWindow(MainWindow* mw, bool redirect = true);
353
358 static MainWindow* getMainWindow();
359
361 static void refresh();
362
369 static void showStatusBarMessage(QString msg, int timeout = 0);
370
374 static void resetProgressBar();
375
381 static void setProgressBarValue(int);
382
395 static void vtkProgressFunction(vtkObject* caller, long unsigned int, void*, void*);
397
400
405 static void addHistoryItem(HistoryItem item);
406
411
416 static void saveHistoryAsSCXML();
417
419
422
425 static QString getSelectedLanguage();
427
430
438
439
443 friend class Component;
444 friend class PersistenceManager;
446
447private slots:
448 void quitting();
449
450private:
452 static QString name;
453
455 static MainWindow* mainWindow;
456
458 static SplashScreen* splashScreen;
459
461 static int argc;
462
464 static char** argv;
465
466 static Action* currentAction;
467
471 static QList<QFileInfo> recentDocuments;
472
474 static QDir lastUsedDirectory;
475
477 static int maxRecentDocuments;
478
480 static QTranslator* translator;
482
485
492 static ComponentList& getTopLevelComponentList();
493
501 static ComponentList& getAllComponentList();
502
510 static ComponentList& getSelectedComponentList();
511
524 static void setSelected(Component* component, bool isSelected);
525
532 static void addComponent(Component*);
533
540 static void removeComponent(Component*);
541
543
546
548 static QSettings settings;
549
551 static void applyPropertyValues();
552
554 static void applyMainWindowPropertyValues();
555
557
560
571 static QStack<HistoryItem>& getHistory();
572
574
577
587 static QMap<QString, Action*>& getActionMap();
588
590 static ActionList sort(ActionSet);
592
595
607 static QMap<QString, Viewer*>& getViewerMap();
608
610 static ViewerExtension* getViewerExtension(Viewer* viewer);
611
613 static ViewerList sort(ViewerSet);
615
618
621 static void createProperties();
622
632 static PropertyObject* propertyObject;
634
636 static void initResources();
637
638protected:
643 bool eventFilter(QObject* object, QEvent* event) override;
644};
645
646
647
648}
649
650#endif // CAMITKAPPLICATION_H
#define CAMITK_API
Definition CamiTKAPI.h:66
Definition PersistenceManager.h:30
This class describes what is a generic Action extension.
Definition ActionExtension.h:57
Action class is an abstract class that enables you to build a action (generally an algorithm that wor...
Definition Action.h:215
static MainWindow * getMainWindow()
get the main window
Definition Application.cpp:348
static void restart(QString reason)
ask the user and if ok restart the application for the given reason
Definition Application.cpp:384
static void saveHistoryAsSCXML()
Save the history as an SCXML file, stored using.
Definition Application.cpp:1333
static const ViewerList getViewers()
get all the viewers registered in the application (note: the returned ViewerList is guaranteed to be ...
Definition Application.cpp:1140
static QSettings & getSettings()
Get the Core wide settings.
Definition Application.cpp:360
static const int getMaxRecentDocuments()
get the maximal number of recent documents stored
Definition Application.cpp:547
static const ComponentList & getAllComponents()
get the current application wide list of all Components.
Definition Application.cpp:1274
static PropertyObject * getPropertyObject()
Get the property object of the application.
Definition Application.cpp:1717
static void addHistoryItem(HistoryItem item)
Add the history item to the application history.
Definition Application.cpp:1323
static const ActionList getActions()
get all the actions registered in the application (note: the returned ActionList is guaranteed to be ...
Definition Application.cpp:896
static int registerAllViewers(ViewerExtension *)
register all viewers from the given ViewerExtension
Definition Application.cpp:1078
static void clearSelectedComponents()
clear all the selection, i.e call setSelected(false) for all the previously selected components and c...
Definition Application.cpp:1297
static void setTriggeredAction(Action *action)
set the currently triggered action This is used by Action::trigger(..) to refresh all the viewer (the...
Definition Application.cpp:1306
static const ComponentList & getTopLevelComponents()
get the current application wide list of instantiated top-level Components.
Definition Application.cpp:1269
static const QList< QFileInfo > getRecentDocuments()
Get the list of recent documents.
Definition Application.cpp:542
static Viewer * getNewViewer(QString name, QString className)
instantiate a new viewer of the given name and given class name (Viewer inheriting class).
Definition Application.cpp:1120
static void showStatusBarMessage(QString msg, int timeout=0)
Set a message to the status bar.
Definition Application.cpp:437
static Action * getAction(QString)
get a registered action given its name
Definition Application.cpp:968
static void vtkProgressFunction(vtkObject *caller, long unsigned int, void *, void *)
Observer function to be called by vtkFilters and to update progress bar Example of use:
Definition Application.cpp:482
static int unregisterAllActions(ActionExtension *)
unregister all actions from the given ActionExtension
Definition Application.cpp:925
static QString getUniqueComponentName(QString name, const ComponentList &components=getTopLevelComponents())
Get a unique name from the given name in the given componentList.
Definition Application.cpp:1203
static void setLastUsedDirectory(QDir)
set (force) the last used directory
Definition Application.cpp:537
static bool loadWorkspace(const QString &filepath)
load a camitk file and its content into the application
Definition Application.cpp:730
static const QDir getLastUsedDirectory()
Get the last used directory (e.g.
Definition Application.cpp:532
static int registerAllActions(ActionExtension *)
register all actions from the given ActionExtension
Definition Application.cpp:901
static const ComponentList & getSelectedComponents()
get the currently selected Components.
Definition Application.cpp:1279
static Component * openDirectory(const QString &dirName, const QString &pluginName)
load a directory and returns the corresponding Component (returns nullptr if an error occurs)
Definition Application.cpp:651
static Component * open(const QString &fileName, bool blockRefresh=false)
load the filename and returns the corresponding top level Component (returns nullptr if an error occu...
Definition Application.cpp:552
static Viewer * getViewer(QString name)
get the pointer to a registered viewer given its name
Definition Application.cpp:1042
static void resetProgressBar()
Resets the progress bar if it exists.
Definition Application.cpp:455
friend class Component
Definition Application.h:443
friend class PersistenceManager
Definition Application.h:444
static bool hasModified()
Return true if at least one of the opened components has been modified, false otherwise.
Definition Application.cpp:1191
static bool close(Component *component, bool blockRefresh=false)
Close a Component: if it has been changed, ask the user for more information, then if everything is o...
Definition Application.cpp:757
Application(QString name, int &argc, char **argv, bool autoloadExtension=true, bool registerFileExtension=false, bool useSplashScreen=false)
Initializes the window system and constructs a CamiTK application object with argc command line argum...
Definition Application.cpp:84
static bool registerViewer(Viewer *)
register a viewer in the viewer list (therefore allowing it to be refreshed by the main window automa...
Definition Application.cpp:1047
static bool saveWorkspace(const QString &filepath)
save the current workspace to a .camitk file.
Definition Application.cpp:869
static void addRecentDocument(QString)
Add a document to the list of recent documents (e.g.
Definition Application.cpp:497
static bool save(Component *component)
save a component to its file (as given by component->getFileName()).
Definition Application.cpp:806
static int unregisterAllViewers(ViewerExtension *)
unregister all viewers from the given ViewerExtension
Definition Application.cpp:1145
static Action * getTriggeredAction()
get the currently triggered action
Definition Application.cpp:1311
static int exec()
Overriden from QApplication: Enters the main event loop and waits until exit() is called,...
Definition Application.cpp:365
static HistoryItem removeLastHistoryItem()
Remove the last pushed actions in the history of the current pipeline.
Definition Application.cpp:1328
bool notify(QObject *, QEvent *) override
reimplemented from QApplication to catch all exception from external libs used in CEP (e....
Definition Application.cpp:263
static void refresh()
refresh the main window (this will call the refresh method of all viewers)
Definition Application.cpp:425
bool eventFilter(QObject *object, QEvent *event) override
Event filter of this class instance to watch its properties instances.
Definition Application.cpp:1722
void setMainWindow(MainWindow *mw, bool redirect=true)
set the main window.
Definition Application.cpp:294
static bool isAlive(Component *)
does this Component still exist? (components can be deleted)
Definition Application.cpp:1182
static QString getSelectedLanguage()
Returns for the current CamiTK application, the selected language (stored in its ....
Definition Application.cpp:1627
static QString getName()
get the application name
Definition Application.cpp:243
static void setProgressBarValue(int)
set the progress bar value, value should be in [0..100].
Definition Application.cpp:468
This class describes what is a generic Component extension.
Definition ComponentExtension.h:59
HistoryItem class describes the entry of an action used in a pipeline, in the history.
Definition HistoryItem.h:61
This class is the base class for your application.
Definition MainWindow.h:68
This class describes a property object.
Definition PropertyObject.h:72
This class describes a property that can be used in components and actions or any class that needs to...
Definition Property.h:306
CamiTK application splash screen.
Definition SplashScreen.h:44
This class describes what is a generic Action extension.
Definition ViewerExtension.h:85
Viewer is an abstract class that is the base class for all viewers.
Definition Viewer.h:182
Definition action.py:1
Definition Action.cpp:40
QSet< Action * > ActionSet
A set of Action.
Definition CamiTKAPI.h:164
QList< Action * > ActionList
A list of Action.
Definition CamiTKAPI.h:170
QList< Component * > ComponentList
A list of Component.
Definition CamiTKAPI.h:161
QSet< Viewer * > ViewerSet
A set of Viewer.
Definition CamiTKAPI.h:167
QList< Viewer * > ViewerList
A list of Viewer.
Definition CamiTKAPI.h:173