Slicer  4.10
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 QSettings;
44 class qSlicerCoreApplicationPrivate;
46 #ifdef Slicer_USE_PYTHONQT
48 class ctkPythonConsole;
49 #endif
50 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
52 #endif
57 class vtkMRMLScene;
58 
59 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreApplication : public QApplication
60 {
61  Q_OBJECT
62  QVTK_OBJECT
63  Q_ENUMS(ReturnCode)
64 
65 
66  Q_PROPERTY(QString slicerHome READ slicerHome CONSTANT)
70  Q_PROPERTY(QString defaultScenePath READ defaultScenePath WRITE setDefaultScenePath)
71  Q_PROPERTY(QString slicerSharePath READ slicerSharePath CONSTANT)
72  Q_PROPERTY(QString temporaryPath READ temporaryPath WRITE setTemporaryPath)
73  Q_PROPERTY(QString launcherExecutableFilePath READ launcherExecutableFilePath CONSTANT)
74  Q_PROPERTY(QString launcherSettingsFilePath READ launcherSettingsFilePath CONSTANT)
75  Q_PROPERTY(QString slicerDefaultSettingsFilePath READ slicerDefaultSettingsFilePath CONSTANT)
76  Q_PROPERTY(QString slicerUserSettingsFilePath READ slicerUserSettingsFilePath CONSTANT)
77  Q_PROPERTY(QString slicerRevisionUserSettingsFilePath READ slicerRevisionUserSettingsFilePath CONSTANT)
78  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath WRITE setExtensionsInstallPath)
79  Q_PROPERTY(QString intDir READ intDir CONSTANT)
80  Q_PROPERTY(bool isInstalled READ isInstalled CONSTANT)
81  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
82  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
83  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
84  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
85  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
86  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
87  Q_PROPERTY(QString platform READ platform CONSTANT)
88  Q_PROPERTY(QString arch READ arch CONSTANT)
89  Q_PROPERTY(QString os READ os CONSTANT)
90  Q_PROPERTY(bool isCustomMainApplication READ isCustomMainApplication CONSTANT)
91  Q_PROPERTY(QString mainApplicationName READ mainApplicationName CONSTANT)
92  Q_PROPERTY(QString mainApplicationRepositoryUrl READ mainApplicationRepositoryUrl CONSTANT)
93  Q_PROPERTY(QString mainApplicationRepositoryRevision READ mainApplicationRepositoryRevision CONSTANT)
94  Q_PROPERTY(int mainApplicationMajorVersion READ mainApplicationMajorVersion CONSTANT)
95  Q_PROPERTY(int mainApplicationMinorVersion READ mainApplicationMinorVersion CONSTANT)
96  Q_PROPERTY(int mainApplicationPatchVersion READ mainApplicationPatchVersion CONSTANT)
97 
98 public:
99 
100  typedef QApplication Superclass;
101  qSlicerCoreApplication(int &argc, char **argv);
102  virtual ~qSlicerCoreApplication();
103 
105  static qSlicerCoreApplication* application();
106 
110  {
111  AA_DisablePython = 1000,
112  AA_EnableTesting
113  };
114 
116  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
117 
119  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
120 
137  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
138 
149  Q_INVOKABLE QProcessEnvironment environment() const;
150 
155  void setEnvironmentVariable(const QString& key, const QString& value);
156 
158  bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
159 
162  void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
163 
166  void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
167 
170  void parseArguments(bool& exitWhenDone);
171 
173  ExitNotRequested = -1,
174  ExitSuccess = EXIT_SUCCESS,
175  ExitFailure = EXIT_FAILURE
176  };
182  int returnCode()const;
183 
185  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
186 
188  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
189 
192  QString slicerHome() const;
193 
198  QString defaultScenePath() const;
199 
201  void setDefaultScenePath(const QString& path);
202 
209  QString slicerSharePath() const;
210 
213  bool isEmbeddedModule(const QString& moduleFileName)const;
214 
216  QString defaultTemporaryPath() const;
217 
219  QString temporaryPath() const;
220 
222  void setTemporaryPath(const QString& path);
223 
225  QString launcherExecutableFilePath()const;
226 
228  QString launcherSettingsFilePath()const;
229 
231  QString launcherRevisionSpecificUserSettingsFilePath()const;
232 
235  QString slicerDefaultSettingsFilePath()const;
236 
239  QString slicerUserSettingsFilePath()const;
240 
243  QString slicerRevisionUserSettingsFilePath()const;
244 
246  QString defaultExtensionsInstallPath() const;
247 
249  QString extensionsInstallPath() const;
250 
252  void setExtensionsInstallPath(const QString& path);
253 
254  void gatherExtensionsHistoryInformationOnStartup();
255 
258  QString intDir()const;
259 
261  bool isInstalled()const;
262 
266  QString releaseType()const;
267 
272  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
273 
275  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
276 
278  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
279 
281  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
282 
283 #ifdef Slicer_USE_PYTHONQT
284  qSlicerCorePythonManager* corePythonManager()const;
286 
289  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
290 
292  ctkPythonConsole* pythonConsole()const;
293 
298  void setPythonConsole(ctkPythonConsole* pythonConsole);
299 
300 #endif
301 
302 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
303  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
305 
308  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
309 #endif
310 
312  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
313 
315  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
316 
319  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
320 
322  qSlicerCoreCommandOptions* coreCommandOptions()const;
323 
326  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
327 
330  Q_INVOKABLE QSettings* defaultSettings()const;
331 
335  Q_INVOKABLE QSettings* userSettings()const;
336 
340  Q_INVOKABLE QSettings* settings()const;
341 
345  Q_INVOKABLE QSettings* revisionUserSettings()const;
346 
348  bool isCustomMainApplication()const;
349 
351  QString mainApplicationName()const;
352 
356  QString mainApplicationRepositoryUrl()const;
357 
361  QString mainApplicationRepositoryRevision()const;
362 
365  int mainApplicationMajorVersion() const;
366 
369  int mainApplicationMinorVersion() const;
370 
373  int mainApplicationPatchVersion() const;
374 
376  virtual QString copyrights()const;
377 
379  virtual QString acknowledgment()const;
380 
382  virtual QString libraries()const;
383 
386  QString repositoryUrl()const;
387 
390  QString repositoryBranch()const;
391 
394  QString repositoryRevision()const;
395 
396 
398  int majorVersion() const;
399 
401  int minorVersion() const;
402 
405  QString platform()const;
406 
409  QString arch()const;
410 
413  QString os()const;
414 
415 #ifdef Slicer_BUILD_DICOM_SUPPORT
416  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
419 
421  Q_INVOKABLE void setDICOMDatabase(ctkDICOMDatabase* dicomDatabase);
422 #endif
423 
424  static void loadTranslations(const QString& dir);
425 
426  static void loadLanguage();
427 
432  static bool loadCaCertificates(const QString& slicerHome);
433 
434  Q_INVOKABLE int registerResource(const QByteArray& data);
435 
438  Q_INVOKABLE void showConsoleMessage(QString message, bool error=true) const;
439 
440 public slots:
441 
444  static void restart();
445 
446  bool unregisterResource(int handle);
447 
448 protected:
449 
453  virtual void handlePreApplicationCommandLineArguments();
454 
457  virtual void setMRMLScene(vtkMRMLScene * scene);
458 
459 protected slots:
460 
464  virtual void handleCommandLineArguments();
465 
466  virtual void onSlicerApplicationLogicModified();
467  virtual void onUserInformationModified();
468  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
469  void processAppLogicModified();
470  void processAppLogicReadData();
471  void processAppLogicWriteData();
472 
474  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
475 
480  void requestInvokeEvent(vtkObject* caller, void* callData);
481 
485  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
486 
491  void invokeEvent();
492 
493 signals:
494  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
495 
498  void invokeEventRequested(unsigned int delay, void* caller,
499  unsigned long event, void* callData);
500 
501 protected:
502  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
503  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
504 
505 private:
506  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
507  Q_DISABLE_COPY(qSlicerCoreApplication);
508 };
509 
511 
512 #endif
Q_DECLARE_METATYPE(QList< QVariantMap >)
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:54
QScopedPointer< qSlicerCoreApplicationPrivate > d_ptr