Slicer  4.13
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 launcherExecutableFilePath READ launcherExecutableFilePath CONSTANT)
76  Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
77  Q_PROPERTY(QString slicerDefaultSettingsFilePath READ slicerDefaultSettingsFilePath CONSTANT)
78  Q_PROPERTY(QString slicerUserSettingsFilePath READ slicerUserSettingsFilePath CONSTANT)
79  Q_PROPERTY(QString slicerRevisionUserSettingsFilePath READ slicerRevisionUserSettingsFilePath CONSTANT)
80  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath WRITE setExtensionsInstallPath)
81  Q_PROPERTY(QString intDir READ intDir CONSTANT)
82  Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
83  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
84  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
85  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
86  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
87  Q_PROPERTY(QString revision READ revision CONSTANT)
88  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
89  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
90  Q_PROPERTY(QString platform READ platform CONSTANT)
91  Q_PROPERTY(QString arch READ arch CONSTANT)
92  Q_PROPERTY(QString os READ os CONSTANT)
93  Q_PROPERTY(bool isCustomMainApplication READ isCustomMainApplication CONSTANT)
94  Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
95  Q_PROPERTY(QString mainApplicationRepositoryUrl READ mainApplicationRepositoryUrl CONSTANT)
96  Q_PROPERTY(QString mainApplicationRepositoryRevision READ mainApplicationRepositoryRevision CONSTANT)
97  Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
98  Q_PROPERTY(int mainApplicationMajorVersion READ mainApplicationMajorVersion CONSTANT)
99  Q_PROPERTY(int mainApplicationMinorVersion READ mainApplicationMinorVersion CONSTANT)
100  Q_PROPERTY(int mainApplicationPatchVersion READ mainApplicationPatchVersion CONSTANT)
101 
102 public:
103 
104  typedef QApplication Superclass;
105  qSlicerCoreApplication(int &argc, char **argv);
106  ~qSlicerCoreApplication() override;
107 
111  static qSlicerCoreApplication* application();
112 
116  {
117  AA_DisablePython = 1000,
118  AA_EnableTesting
119  };
120 
122  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
123 
125  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
126 
143  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
144 
155  Q_INVOKABLE QProcessEnvironment environment() const;
156 
161  Q_INVOKABLE void setEnvironmentVariable(const QString& key, const QString& value);
162 
164  Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
165 
168  Q_INVOKABLE void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
169 
172  Q_INVOKABLE void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
173 
176  void parseArguments(bool& exitWhenDone);
177 
179  ExitNotRequested = -1,
180  ExitSuccess = EXIT_SUCCESS,
181  ExitFailure = EXIT_FAILURE
182  };
197  int returnCode()const;
198 
210  static int exec();
211 
213  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
214 
216  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
217 
218  // Convenience method for getting a module logic from the application logic.
219  Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName)const;
220 
223  QString slicerHome() const;
224 
229  QString defaultScenePath() const;
230 
232  void setDefaultScenePath(const QString& path);
233 
240  QString slicerSharePath() const;
241 
244  bool isEmbeddedModule(const QString& moduleFileName)const;
245 
247  QString defaultTemporaryPath() const;
248 
250  QString temporaryPath() const;
251 
253  void setTemporaryPath(const QString& path);
254 
256  QString launcherExecutableFilePath()const;
257 
259  QString launcherSettingsFilePath()const;
260 
262  QString launcherRevisionSpecificUserSettingsFilePath()const;
263 
266  QString slicerDefaultSettingsFilePath()const;
267 
270  QString slicerUserSettingsFilePath()const;
271 
274  QString slicerRevisionUserSettingsFilePath()const;
275 
277  QString defaultExtensionsInstallPath() const;
278 
280  QString extensionsInstallPath() const;
281 
283  void setExtensionsInstallPath(const QString& path);
284 
285  void gatherExtensionsHistoryInformationOnStartup();
286 
289  QString intDir()const;
290 
292  bool isInstalled()const;
293 
297  QString releaseType()const;
298 
303  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
304 
306  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
307 
309  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
310 
312  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
313 
314 #ifdef Slicer_USE_PYTHONQT
315  qSlicerCorePythonManager* corePythonManager()const;
317 
320  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
321 
323  ctkPythonConsole* pythonConsole()const;
324 
329  void setPythonConsole(ctkPythonConsole* pythonConsole);
330 
331 #endif
332 
333 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
334  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
336 
339  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
340 #endif
341 
343  Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel()const;
344 
346  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
347 
349  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
350 
353  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
354 
356  qSlicerCoreCommandOptions* coreCommandOptions()const;
357 
360  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
361 
364  Q_INVOKABLE QSettings* defaultSettings()const;
365 
369  Q_INVOKABLE QSettings* userSettings()const;
370 
374  Q_INVOKABLE QSettings* settings()const;
375 
379  Q_INVOKABLE QSettings* revisionUserSettings()const;
380 
382  bool isCustomMainApplication()const;
383 
385  QString mainApplicationName()const;
386 
390  QString mainApplicationRepositoryUrl()const;
391 
395  QString mainApplicationRepositoryRevision()const;
396 
399  QString mainApplicationRevision()const;
400 
403  int mainApplicationMajorVersion() const;
404 
407  int mainApplicationMinorVersion() const;
408 
411  int mainApplicationPatchVersion() const;
412 
414  virtual QString copyrights()const;
415 
417  virtual QString acknowledgment()const;
418 
420  virtual QString libraries()const;
421 
424  QString repositoryUrl()const;
425 
428  QString repositoryBranch()const;
429 
432  QString repositoryRevision()const;
433 
435  QString revision()const;
436 
438  int majorVersion() const;
439 
441  int minorVersion() const;
442 
445  QString platform()const;
446 
449  QString arch()const;
450 
453  QString os()const;
454 
455 #ifdef Slicer_BUILD_DICOM_SUPPORT
456  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
458 
461  QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
462 #endif
463 
464  static void loadTranslations(const QString& dir);
465 
466  static void loadLanguage();
467 
472  static bool loadCaCertificates(const QString& slicerHome);
473 
474  Q_INVOKABLE int registerResource(const QByteArray& data);
475 
478  Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
479 
482  Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
483 
486  Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
487 
490  Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
491 
494  Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
495 
496 public slots:
497 
500  static void restart();
501 
502  bool unregisterResource(int handle);
503 
510  virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
513  virtual void pauseRender() {};
516  virtual void resumeRender() {};
517 
518 protected:
519 
523  virtual void handlePreApplicationCommandLineArguments();
524 
527  virtual void setMRMLScene(vtkMRMLScene * scene);
528 
529 protected slots:
530 
534  virtual void handleCommandLineArguments();
535 
536  virtual void onSlicerApplicationLogicModified();
537  virtual void onUserInformationModified();
538  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
539  void processAppLogicModified();
540  void processAppLogicReadData();
541  void processAppLogicWriteData();
542 
545  virtual void editNode(vtkObject*, void*, unsigned long) {};
546 
548  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
549 
551  virtual void onAboutToQuit();
552 
557  void requestInvokeEvent(vtkObject* caller, void* callData);
558 
562  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
563 
568  void invokeEvent();
569 
570 signals:
571  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
572 
576  void urlReceived(QString url);
577 
580  void invokeEventRequested(unsigned int delay, void* caller,
581  unsigned long event, void* callData);
582 
583 protected:
584  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
585  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
586 
587 private:
588  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
589  Q_DISABLE_COPY(qSlicerCoreApplication);
590 };
591 
593 
594 #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