Slicer  5.3
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
54 #ifdef Slicer_BUILD_APPLICATIONUPDATE_SUPPORT
56 #endif
63 class vtkMRMLScene;
64 
65 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreApplication : public QApplication
66 {
67  Q_OBJECT
68  QVTK_OBJECT
69  Q_ENUMS(ReturnCode)
70 
71 
72  Q_PROPERTY(QString slicerHome READ slicerHome CONSTANT)
76  Q_PROPERTY(QString defaultScenePath READ defaultScenePath WRITE setDefaultScenePath)
77  Q_PROPERTY(QString slicerSharePath READ slicerSharePath CONSTANT)
78  Q_PROPERTY(QString temporaryPath READ temporaryPath WRITE setTemporaryPath)
79  Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath)
80  Q_PROPERTY(QString startupWorkingPath READ startupWorkingPath CONSTANT)
81  Q_PROPERTY(QString launcherExecutableFilePath READ launcherExecutableFilePath CONSTANT)
82  Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
83  Q_PROPERTY(QString slicerDefaultSettingsFilePath READ slicerDefaultSettingsFilePath CONSTANT)
84  Q_PROPERTY(QString slicerUserSettingsFilePath READ slicerUserSettingsFilePath CONSTANT)
85  Q_PROPERTY(QString slicerRevisionUserSettingsFilePath READ slicerRevisionUserSettingsFilePath CONSTANT)
86  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath WRITE setExtensionsInstallPath)
87  Q_PROPERTY(QString intDir READ intDir CONSTANT)
88  Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
89  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
90  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
91  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
92  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
93  Q_PROPERTY(QString revision READ revision CONSTANT)
94  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
95  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
96  Q_PROPERTY(QString documentationBaseUrl READ documentationBaseUrl)
97  Q_PROPERTY(QString documentationVersion READ documentationVersion CONSTANT)
98  Q_PROPERTY(QString documentationLanguage READ documentationLanguage)
99  Q_PROPERTY(QString platform READ platform CONSTANT)
100  Q_PROPERTY(QString arch READ arch CONSTANT)
101  Q_PROPERTY(QString os READ os CONSTANT)
102  Q_PROPERTY(bool isCustomMainApplication READ isCustomMainApplication CONSTANT)
103  Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
104  Q_PROPERTY(QString mainApplicationRepositoryUrl READ mainApplicationRepositoryUrl CONSTANT)
105  Q_PROPERTY(QString mainApplicationRepositoryRevision READ mainApplicationRepositoryRevision CONSTANT)
106  Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
107  Q_PROPERTY(int mainApplicationMajorVersion READ mainApplicationMajorVersion CONSTANT)
108  Q_PROPERTY(int mainApplicationMinorVersion READ mainApplicationMinorVersion CONSTANT)
109  Q_PROPERTY(int mainApplicationPatchVersion READ mainApplicationPatchVersion CONSTANT)
110 
111 public:
112 
113  typedef QApplication Superclass;
114  qSlicerCoreApplication(int &argc, char **argv);
115  ~qSlicerCoreApplication() override;
116 
120  static qSlicerCoreApplication* application();
121 
125  {
126  AA_DisablePython = 1000,
127  AA_EnableTesting
128  };
129 
131  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
132 
134  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
135 
152  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
153 
155  QString startupWorkingPath() const;
156 
167  Q_INVOKABLE QProcessEnvironment environment() const;
168 
173  Q_INVOKABLE void setEnvironmentVariable(const QString& key, const QString& value);
174 
176  Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
177 
180  Q_INVOKABLE void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
181 
184  Q_INVOKABLE void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
185 
188  void parseArguments(bool& exitWhenDone);
189 
191  ExitNotRequested = -1,
192  ExitSuccess = EXIT_SUCCESS,
193  ExitFailure = EXIT_FAILURE
194  };
209  int returnCode()const;
210 
221  static int exec();
222 
224  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
225 
227  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
228 
229  // Convenience method for getting a module logic from the application logic.
230  Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName)const;
231 
234  QString slicerHome() const;
235 
240  QString defaultScenePath() const;
241 
243  void setDefaultScenePath(const QString& path);
244 
251  QString slicerSharePath() const;
252 
255  bool isEmbeddedModule(const QString& moduleFileName)const;
256 
258  QString defaultTemporaryPath() const;
259 
261  QString temporaryPath() const;
262 
264  void setTemporaryPath(const QString& path);
265 
268  QString defaultCachePath() const;
269 
273  QString cachePath() const;
274 
277  void setCachePath(const QString& path);
278 
280  QString launcherExecutableFilePath()const;
281 
283  QString launcherSettingsFilePath()const;
284 
286  QString launcherRevisionSpecificUserSettingsFilePath()const;
287 
290  QString slicerDefaultSettingsFilePath()const;
291 
294  QString slicerUserSettingsFilePath()const;
295 
298  QString slicerRevisionUserSettingsFilePath()const;
299 
301  QString defaultExtensionsInstallPath() const;
302 
304  QString extensionsInstallPath() const;
305 
307  void setExtensionsInstallPath(const QString& path);
308 
311  QString intDir()const;
312 
314  bool isInstalled()const;
315 
319  QString releaseType()const;
320 
325  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
326 
328  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
329 
331  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
332 
334  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
335 
336 #ifdef Slicer_USE_PYTHONQT
337  qSlicerCorePythonManager* corePythonManager()const;
339 
342  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
343 
345  ctkPythonConsole* pythonConsole()const;
346 
351  void setPythonConsole(ctkPythonConsole* pythonConsole);
352 
353 #endif
354 
355 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
356  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
358 
361  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
362 #endif
363 
364 #ifdef Slicer_BUILD_APPLICATIONUPDATE_SUPPORT
365  Q_INVOKABLE qSlicerApplicationUpdateManager* applicationUpdateManager()const;
367 
370  void setapplicationUpdateManager(qSlicerApplicationUpdateManager* model);
371 #endif
372 
374  Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel()const;
375 
377  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
378 
380  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
381 
384  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
385 
387  qSlicerCoreCommandOptions* coreCommandOptions()const;
388 
391  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
392 
395  Q_INVOKABLE QSettings* defaultSettings()const;
396 
400  Q_INVOKABLE QSettings* userSettings()const;
401 
405  Q_INVOKABLE QSettings* settings()const;
406 
410  Q_INVOKABLE QSettings* revisionUserSettings()const;
411 
413  bool isCustomMainApplication()const;
414 
416  QString mainApplicationName()const;
417 
421  QString mainApplicationRepositoryUrl()const;
422 
426  QString mainApplicationRepositoryRevision()const;
427 
430  QString mainApplicationRevision()const;
431 
434  int mainApplicationMajorVersion() const;
435 
438  int mainApplicationMinorVersion() const;
439 
442  int mainApplicationPatchVersion() const;
443 
449  QString documentationBaseUrl()const;
450 
454  QString documentationVersion()const;
455 
458  QString documentationLanguage()const;
459 
463  Q_INVOKABLE QString moduleDocumentationUrl(const QString &moduleName)const;
464 
466  virtual QString copyrights()const;
467 
469  virtual QString acknowledgment()const;
470 
472  virtual QString libraries()const;
473 
476  QString repositoryUrl()const;
477 
480  QString repositoryBranch()const;
481 
484  QString repositoryRevision()const;
485 
487  QString revision()const;
488 
490  int majorVersion() const;
491 
493  int minorVersion() const;
494 
497  QString platform()const;
498 
501  QString arch()const;
502 
505  QString os()const;
506 
507 #ifdef Slicer_BUILD_DICOM_SUPPORT
508  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
510 
513  QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
514 #endif
515 
517  Q_INVOKABLE static QStringList translationFolders();
518 
521  Q_INVOKABLE static void loadTranslations(const QString& dir);
522 
525  Q_INVOKABLE static void loadLanguage();
526 
532  Q_INVOKABLE static bool loadCaCertificates(const QString& slicerHome);
533 
536  Q_INVOKABLE static QString caCertificatesPath(const QString& slicerHome);
537 
538  Q_INVOKABLE int registerResource(const QByteArray& data);
539 
542  Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
543 
546  Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
547 
550  Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
551 
554  Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
555 
558  Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
559 
560 public slots:
561 
564  static void restart();
565 
566  bool unregisterResource(int handle);
567 
574  virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
577  virtual void pauseRender() {};
580  virtual void resumeRender() {};
581 
585  virtual bool loadFiles(const QStringList& filePaths, vtkMRMLMessageCollection* userMessages=nullptr);
586 
590  virtual void openUrl(const QString& url);
591 
592 protected:
593 
597  virtual void handlePreApplicationCommandLineArguments();
598 
601  virtual void setMRMLScene(vtkMRMLScene * scene);
602 
603 protected slots:
604 
608  virtual void handleCommandLineArguments();
609 
610  virtual void onSlicerApplicationLogicModified();
611  virtual void onUserInformationModified();
612  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
613  void processAppLogicModified();
614  void processAppLogicReadData();
615  void processAppLogicWriteData();
616 
619  virtual void editNode(vtkObject*, void*, unsigned long) {};
620 
622  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
623 
625  virtual void onAboutToQuit();
626 
631  void requestInvokeEvent(vtkObject* caller, void* callData);
632 
636  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
637 
642  void invokeEvent();
643 
644 signals:
645  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
646 
650  void urlReceived(QString url);
651 
654  void invokeEventRequested(unsigned int delay, void* caller,
655  unsigned long event, void* callData);
656 
657 protected:
658  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
659  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
660 
661 private:
662  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
663  Q_DISABLE_COPY(qSlicerCoreApplication);
664 };
665 
667 
668 class Q_SLICER_BASE_QTCORE_EXPORT SlicerRenderBlocker
676 {
677 public:
680  {
681  this->Application = qSlicerCoreApplication::application();
682  if (this->Application)
683  {
684  this->Application->pauseRender();
685  }
686  };
688  {
689  if (this->Application)
690  {
691  this->Application->resumeRender();
692  }
693  }
694 };
695 
696 #endif
Superclass for MRML logic classes.
Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ServerAPI)
static qSlicerCoreApplication * application()
Safe replacement of qSlicerCoreApplication::pauseRender/resumeRender.
Class querying and storing extensions data.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
Class querying application updates on the download server.
qSlicerCoreApplication * Application
virtual void setRenderPaused(bool pause)
virtual void editNode(vtkObject *, void *, unsigned long)
QScopedPointer< qSlicerCoreApplicationPrivate > d_ptr