Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerCoreApplication.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerCoreApplication_h
22 #define __qSlicerCoreApplication_h
23 
24 // Qt includes
25 #include <QApplication>
26 #include <QMetaType>
27 #include <QProcessEnvironment>
28 #include <QStringList>
29 #include <QVariant>
30 
31 // CTK includes
32 #include <ctkVTKObject.h>
33 
34 // SlicerCore includes
35 #include "vtkSlicerConfigure.h" // For Slicer_USE_PYTHONQT
36 #include "qSlicerBaseQTCoreExport.h"
37 
38 #ifdef Slicer_BUILD_DICOM_SUPPORT
39 class ctkDICOMDatabase;
40 #endif
41 class ctkErrorLogAbstractModel;
42 class QSettings;
45 class qSlicerCoreApplicationPrivate;
47 #ifdef Slicer_USE_PYTHONQT
49 class ctkPythonConsole;
50 #endif
51 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
53 #endif
59 class vtkMRMLScene;
60 
61 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreApplication : public QApplication
62 {
63  Q_OBJECT
64  QVTK_OBJECT
65  Q_ENUMS(ReturnCode)
66 
67 
68  Q_PROPERTY(QString slicerHome READ slicerHome CONSTANT)
72  Q_PROPERTY(QString defaultScenePath READ defaultScenePath WRITE setDefaultScenePath)
73  Q_PROPERTY(QString slicerSharePath READ slicerSharePath CONSTANT)
74  Q_PROPERTY(QString temporaryPath READ temporaryPath WRITE setTemporaryPath)
75  Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath)
76  Q_PROPERTY(QString launcherExecutableFilePath READ launcherExecutableFilePath CONSTANT)
77  Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
78  Q_PROPERTY(QString slicerDefaultSettingsFilePath READ slicerDefaultSettingsFilePath CONSTANT)
79  Q_PROPERTY(QString slicerUserSettingsFilePath READ slicerUserSettingsFilePath CONSTANT)
80  Q_PROPERTY(QString slicerRevisionUserSettingsFilePath READ slicerRevisionUserSettingsFilePath CONSTANT)
81  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath WRITE setExtensionsInstallPath)
82  Q_PROPERTY(QString intDir READ intDir CONSTANT)
83  Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
84  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
85  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
86  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
87  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
88  Q_PROPERTY(QString revision READ revision CONSTANT)
89  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
90  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
91  Q_PROPERTY(QString platform READ platform CONSTANT)
92  Q_PROPERTY(QString arch READ arch CONSTANT)
93  Q_PROPERTY(QString os READ os CONSTANT)
94  Q_PROPERTY(bool isCustomMainApplication READ isCustomMainApplication CONSTANT)
95  Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
96  Q_PROPERTY(QString mainApplicationRepositoryUrl READ mainApplicationRepositoryUrl CONSTANT)
97  Q_PROPERTY(QString mainApplicationRepositoryRevision READ mainApplicationRepositoryRevision CONSTANT)
98  Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
99  Q_PROPERTY(int mainApplicationMajorVersion READ mainApplicationMajorVersion CONSTANT)
100  Q_PROPERTY(int mainApplicationMinorVersion READ mainApplicationMinorVersion CONSTANT)
101  Q_PROPERTY(int mainApplicationPatchVersion READ mainApplicationPatchVersion CONSTANT)
102 
103 public:
104 
105  typedef QApplication Superclass;
106  qSlicerCoreApplication(int &argc, char **argv);
107  ~qSlicerCoreApplication() override;
108 
112  static qSlicerCoreApplication* application();
113 
117  {
118  AA_DisablePython = 1000,
119  AA_EnableTesting
120  };
121 
123  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
124 
126  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
127 
144  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
145 
156  Q_INVOKABLE QProcessEnvironment environment() const;
157 
162  Q_INVOKABLE void setEnvironmentVariable(const QString& key, const QString& value);
163 
165  Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
166 
169  Q_INVOKABLE void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
170 
173  Q_INVOKABLE void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
174 
177  void parseArguments(bool& exitWhenDone);
178 
180  ExitNotRequested = -1,
181  ExitSuccess = EXIT_SUCCESS,
182  ExitFailure = EXIT_FAILURE
183  };
198  int returnCode()const;
199 
211  static int exec();
212 
214  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
215 
217  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
218 
219  // Convenience method for getting a module logic from the application logic.
220  Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName)const;
221 
224  QString slicerHome() const;
225 
230  QString defaultScenePath() const;
231 
233  void setDefaultScenePath(const QString& path);
234 
241  QString slicerSharePath() const;
242 
245  bool isEmbeddedModule(const QString& moduleFileName)const;
246 
248  QString defaultTemporaryPath() const;
249 
251  QString temporaryPath() const;
252 
254  void setTemporaryPath(const QString& path);
255 
258  QString defaultCachePath() const;
259 
263  QString cachePath() const;
264 
267  void setCachePath(const QString& path);
268 
270  QString launcherExecutableFilePath()const;
271 
273  QString launcherSettingsFilePath()const;
274 
276  QString launcherRevisionSpecificUserSettingsFilePath()const;
277 
280  QString slicerDefaultSettingsFilePath()const;
281 
284  QString slicerUserSettingsFilePath()const;
285 
288  QString slicerRevisionUserSettingsFilePath()const;
289 
291  QString defaultExtensionsInstallPath() const;
292 
294  QString extensionsInstallPath() const;
295 
297  void setExtensionsInstallPath(const QString& path);
298 
299  void gatherExtensionsHistoryInformationOnStartup();
300 
303  QString intDir()const;
304 
306  bool isInstalled()const;
307 
311  QString releaseType()const;
312 
317  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
318 
320  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
321 
323  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
324 
326  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
327 
328 #ifdef Slicer_USE_PYTHONQT
329  qSlicerCorePythonManager* corePythonManager()const;
331 
334  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
335 
337  ctkPythonConsole* pythonConsole()const;
338 
343  void setPythonConsole(ctkPythonConsole* pythonConsole);
344 
345 #endif
346 
347 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
348  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
350 
353  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
354 #endif
355 
357  Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel()const;
358 
360  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
361 
363  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
364 
367  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
368 
370  qSlicerCoreCommandOptions* coreCommandOptions()const;
371 
374  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
375 
378  Q_INVOKABLE QSettings* defaultSettings()const;
379 
383  Q_INVOKABLE QSettings* userSettings()const;
384 
388  Q_INVOKABLE QSettings* settings()const;
389 
393  Q_INVOKABLE QSettings* revisionUserSettings()const;
394 
396  bool isCustomMainApplication()const;
397 
399  QString mainApplicationName()const;
400 
404  QString mainApplicationRepositoryUrl()const;
405 
409  QString mainApplicationRepositoryRevision()const;
410 
413  QString mainApplicationRevision()const;
414 
417  int mainApplicationMajorVersion() const;
418 
421  int mainApplicationMinorVersion() const;
422 
425  int mainApplicationPatchVersion() const;
426 
428  virtual QString copyrights()const;
429 
431  virtual QString acknowledgment()const;
432 
434  virtual QString libraries()const;
435 
438  QString repositoryUrl()const;
439 
442  QString repositoryBranch()const;
443 
446  QString repositoryRevision()const;
447 
449  QString revision()const;
450 
452  int majorVersion() const;
453 
455  int minorVersion() const;
456 
459  QString platform()const;
460 
463  QString arch()const;
464 
467  QString os()const;
468 
469 #ifdef Slicer_BUILD_DICOM_SUPPORT
470  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
472 
475  QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
476 #endif
477 
478  static void loadTranslations(const QString& dir);
479 
480  static void loadLanguage();
481 
486  static bool loadCaCertificates(const QString& slicerHome);
487 
488  Q_INVOKABLE int registerResource(const QByteArray& data);
489 
492  Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
493 
496  Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
497 
500  Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
501 
504  Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
505 
508  Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
509 
510 public slots:
511 
514  static void restart();
515 
516  bool unregisterResource(int handle);
517 
524  virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
527  virtual void pauseRender() {};
530  virtual void resumeRender() {};
531 
532 protected:
533 
537  virtual void handlePreApplicationCommandLineArguments();
538 
541  virtual void setMRMLScene(vtkMRMLScene * scene);
542 
543 protected slots:
544 
548  virtual void handleCommandLineArguments();
549 
550  virtual void onSlicerApplicationLogicModified();
551  virtual void onUserInformationModified();
552  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
553  void processAppLogicModified();
554  void processAppLogicReadData();
555  void processAppLogicWriteData();
556 
559  virtual void editNode(vtkObject*, void*, unsigned long) {};
560 
562  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
563 
565  virtual void onAboutToQuit();
566 
571  void requestInvokeEvent(vtkObject* caller, void* callData);
572 
576  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
577 
582  void invokeEvent();
583 
584 signals:
585  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
586 
590  void urlReceived(QString url);
591 
594  void invokeEventRequested(unsigned int delay, void* caller,
595  unsigned long event, void* callData);
596 
597 protected:
598  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
599  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
600 
601 private:
602  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
603  Q_DISABLE_COPY(qSlicerCoreApplication);
604 };
605 
607 
608 #endif
Superclass for MRML logic classes.
Q_DECLARE_METATYPE(QList< QVariantMap >)
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:61
virtual void setRenderPaused(bool pause)
virtual void editNode(vtkObject *, void *, unsigned long)
QScopedPointer< qSlicerCoreApplicationPrivate > d_ptr