Slicer  5.0
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
60 class vtkMRMLScene;
61 
62 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreApplication : public QApplication
63 {
64  Q_OBJECT
65  QVTK_OBJECT
66  Q_ENUMS(ReturnCode)
67 
68 
69  Q_PROPERTY(QString slicerHome READ slicerHome CONSTANT)
73  Q_PROPERTY(QString defaultScenePath READ defaultScenePath WRITE setDefaultScenePath)
74  Q_PROPERTY(QString slicerSharePath READ slicerSharePath CONSTANT)
75  Q_PROPERTY(QString temporaryPath READ temporaryPath WRITE setTemporaryPath)
76  Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath)
77  Q_PROPERTY(QString startupWorkingPath READ startupWorkingPath CONSTANT)
78  Q_PROPERTY(QString launcherExecutableFilePath READ launcherExecutableFilePath CONSTANT)
79  Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
80  Q_PROPERTY(QString slicerDefaultSettingsFilePath READ slicerDefaultSettingsFilePath CONSTANT)
81  Q_PROPERTY(QString slicerUserSettingsFilePath READ slicerUserSettingsFilePath CONSTANT)
82  Q_PROPERTY(QString slicerRevisionUserSettingsFilePath READ slicerRevisionUserSettingsFilePath CONSTANT)
83  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath WRITE setExtensionsInstallPath)
84  Q_PROPERTY(QString intDir READ intDir CONSTANT)
85  Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
86  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
87  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
88  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
89  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
90  Q_PROPERTY(QString revision READ revision CONSTANT)
91  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
92  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
93  Q_PROPERTY(QString documentationBaseUrl READ documentationBaseUrl)
94  Q_PROPERTY(QString documentationVersion READ documentationVersion CONSTANT)
95  Q_PROPERTY(QString documentationLanguage READ documentationLanguage)
96  Q_PROPERTY(QString platform READ platform CONSTANT)
97  Q_PROPERTY(QString arch READ arch CONSTANT)
98  Q_PROPERTY(QString os READ os CONSTANT)
99  Q_PROPERTY(bool isCustomMainApplication READ isCustomMainApplication CONSTANT)
100  Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
101  Q_PROPERTY(QString mainApplicationRepositoryUrl READ mainApplicationRepositoryUrl CONSTANT)
102  Q_PROPERTY(QString mainApplicationRepositoryRevision READ mainApplicationRepositoryRevision CONSTANT)
103  Q_PROPERTY(QString mainApplicationRevision READ mainApplicationRevision CONSTANT)
104  Q_PROPERTY(int mainApplicationMajorVersion READ mainApplicationMajorVersion CONSTANT)
105  Q_PROPERTY(int mainApplicationMinorVersion READ mainApplicationMinorVersion CONSTANT)
106  Q_PROPERTY(int mainApplicationPatchVersion READ mainApplicationPatchVersion CONSTANT)
107 
108 public:
109 
110  typedef QApplication Superclass;
111  qSlicerCoreApplication(int &argc, char **argv);
112  ~qSlicerCoreApplication() override;
113 
117  static qSlicerCoreApplication* application();
118 
122  {
123  AA_DisablePython = 1000,
124  AA_EnableTesting
125  };
126 
128  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
129 
131  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
132 
149  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
150 
152  QString startupWorkingPath() const;
153 
164  Q_INVOKABLE QProcessEnvironment environment() const;
165 
170  Q_INVOKABLE void setEnvironmentVariable(const QString& key, const QString& value);
171 
173  Q_INVOKABLE bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
174 
177  Q_INVOKABLE void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
178 
181  Q_INVOKABLE void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
182 
185  void parseArguments(bool& exitWhenDone);
186 
188  ExitNotRequested = -1,
189  ExitSuccess = EXIT_SUCCESS,
190  ExitFailure = EXIT_FAILURE
191  };
206  int returnCode()const;
207 
218  static int exec();
219 
221  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
222 
224  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
225 
226  // Convenience method for getting a module logic from the application logic.
227  Q_INVOKABLE vtkMRMLAbstractLogic* moduleLogic(const QString& moduleName)const;
228 
231  QString slicerHome() const;
232 
237  QString defaultScenePath() const;
238 
240  void setDefaultScenePath(const QString& path);
241 
248  QString slicerSharePath() const;
249 
252  bool isEmbeddedModule(const QString& moduleFileName)const;
253 
255  QString defaultTemporaryPath() const;
256 
258  QString temporaryPath() const;
259 
261  void setTemporaryPath(const QString& path);
262 
265  QString defaultCachePath() const;
266 
270  QString cachePath() const;
271 
274  void setCachePath(const QString& path);
275 
277  QString launcherExecutableFilePath()const;
278 
280  QString launcherSettingsFilePath()const;
281 
283  QString launcherRevisionSpecificUserSettingsFilePath()const;
284 
287  QString slicerDefaultSettingsFilePath()const;
288 
291  QString slicerUserSettingsFilePath()const;
292 
295  QString slicerRevisionUserSettingsFilePath()const;
296 
298  QString defaultExtensionsInstallPath() const;
299 
301  QString extensionsInstallPath() const;
302 
304  void setExtensionsInstallPath(const QString& path);
305 
308  QString intDir()const;
309 
311  bool isInstalled()const;
312 
316  QString releaseType()const;
317 
322  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
323 
325  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
326 
328  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
329 
331  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
332 
333 #ifdef Slicer_USE_PYTHONQT
334  qSlicerCorePythonManager* corePythonManager()const;
336 
339  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
340 
342  ctkPythonConsole* pythonConsole()const;
343 
348  void setPythonConsole(ctkPythonConsole* pythonConsole);
349 
350 #endif
351 
352 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
353  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
355 
358  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
359 #endif
360 
362  Q_INVOKABLE ctkErrorLogAbstractModel* errorLogModel()const;
363 
365  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
366 
368  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
369 
372  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
373 
375  qSlicerCoreCommandOptions* coreCommandOptions()const;
376 
379  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
380 
383  Q_INVOKABLE QSettings* defaultSettings()const;
384 
388  Q_INVOKABLE QSettings* userSettings()const;
389 
393  Q_INVOKABLE QSettings* settings()const;
394 
398  Q_INVOKABLE QSettings* revisionUserSettings()const;
399 
401  bool isCustomMainApplication()const;
402 
404  QString mainApplicationName()const;
405 
409  QString mainApplicationRepositoryUrl()const;
410 
414  QString mainApplicationRepositoryRevision()const;
415 
418  QString mainApplicationRevision()const;
419 
422  int mainApplicationMajorVersion() const;
423 
426  int mainApplicationMinorVersion() const;
427 
430  int mainApplicationPatchVersion() const;
431 
437  QString documentationBaseUrl()const;
438 
442  QString documentationVersion()const;
443 
446  QString documentationLanguage()const;
447 
451  Q_INVOKABLE QString moduleDocumentationUrl(const QString &moduleName)const;
452 
454  virtual QString copyrights()const;
455 
457  virtual QString acknowledgment()const;
458 
460  virtual QString libraries()const;
461 
464  QString repositoryUrl()const;
465 
468  QString repositoryBranch()const;
469 
472  QString repositoryRevision()const;
473 
475  QString revision()const;
476 
478  int majorVersion() const;
479 
481  int minorVersion() const;
482 
485  QString platform()const;
486 
489  QString arch()const;
490 
493  QString os()const;
494 
495 #ifdef Slicer_BUILD_DICOM_SUPPORT
496  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
498 
501  QSharedPointer<ctkDICOMDatabase> dicomDatabaseShared() const;
502 #endif
503 
505  Q_INVOKABLE static QStringList translationFolders();
506 
509  Q_INVOKABLE static void loadTranslations(const QString& dir);
510 
513  Q_INVOKABLE static void loadLanguage();
514 
519  Q_INVOKABLE static bool loadCaCertificates(const QString& slicerHome);
520 
521  Q_INVOKABLE int registerResource(const QByteArray& data);
522 
525  Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
526 
529  Q_INVOKABLE QString toSlicerHomeAbsolutePath(const QString& path) const;
530 
533  Q_INVOKABLE QString toSlicerHomeRelativePath(const QString& path) const;
534 
537  Q_INVOKABLE QStringList toSlicerHomeAbsolutePaths(const QStringList& path) const;
538 
541  Q_INVOKABLE QStringList toSlicerHomeRelativePaths(const QStringList& path) const;
542 
543 public slots:
544 
547  static void restart();
548 
549  bool unregisterResource(int handle);
550 
557  virtual void setRenderPaused(bool pause) { Q_UNUSED(pause); };
560  virtual void pauseRender() {};
563  virtual void resumeRender() {};
564 
568  virtual bool loadFiles(const QStringList& filePaths, vtkMRMLMessageCollection* userMessages=nullptr);
569 
573  virtual void openUrl(const QString& url);
574 
575 protected:
576 
580  virtual void handlePreApplicationCommandLineArguments();
581 
584  virtual void setMRMLScene(vtkMRMLScene * scene);
585 
586 protected slots:
587 
591  virtual void handleCommandLineArguments();
592 
593  virtual void onSlicerApplicationLogicModified();
594  virtual void onUserInformationModified();
595  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
596  void processAppLogicModified();
597  void processAppLogicReadData();
598  void processAppLogicWriteData();
599 
602  virtual void editNode(vtkObject*, void*, unsigned long) {};
603 
605  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
606 
608  virtual void onAboutToQuit();
609 
614  void requestInvokeEvent(vtkObject* caller, void* callData);
615 
619  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
620 
625  void invokeEvent();
626 
627 signals:
628  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
629 
633  void urlReceived(QString url);
634 
637  void invokeEventRequested(unsigned int delay, void* caller,
638  unsigned long event, void* callData);
639 
640 protected:
641  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
642  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
643 
644 private:
645  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
646  Q_DISABLE_COPY(qSlicerCoreApplication);
647 };
648 
650 
651 class Q_SLICER_BASE_QTCORE_EXPORT SlicerRenderBlocker
659 {
660 public:
663  {
664  this->Application = qSlicerCoreApplication::application();
665  if (this->Application)
666  {
667  this->Application->pauseRender();
668  }
669  };
671  {
672  if (this->Application)
673  {
674  this->Application->resumeRender();
675  }
676  }
677 };
678 
679 #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
qSlicerCoreApplication * Application
virtual void setRenderPaused(bool pause)
virtual void editNode(vtkObject *, void *, unsigned long)
QScopedPointer< qSlicerCoreApplicationPrivate > d_ptr