Slicer  4.8
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(bool isRelease READ isRelease CONSTANT)
82  Q_PROPERTY(QString releaseType READ releaseType CONSTANT)
83  Q_PROPERTY(QString repositoryUrl READ repositoryUrl CONSTANT)
84  Q_PROPERTY(QString repositoryBranch READ repositoryBranch CONSTANT)
85  Q_PROPERTY(QString repositoryRevision READ repositoryRevision CONSTANT)
86  Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
87  Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
88  Q_PROPERTY(QString platform READ platform CONSTANT)
89  Q_PROPERTY(QString arch READ arch CONSTANT)
90  Q_PROPERTY(QString os READ os CONSTANT)
91 public:
92 
93  typedef QApplication Superclass;
94  qSlicerCoreApplication(int &argc, char **argv);
95  virtual ~qSlicerCoreApplication();
96 
98  static qSlicerCoreApplication* application();
99 
103  {
104  AA_DisablePython = 1000,
105  AA_EnableTesting
106  };
107 
109  static void setAttribute(qSlicerCoreApplication::ApplicationAttribute attribute, bool on = true);
110 
112  static bool testAttribute(qSlicerCoreApplication::ApplicationAttribute attribute);
113 
130  Q_INVOKABLE QProcessEnvironment startupEnvironment() const;
131 
142  Q_INVOKABLE QProcessEnvironment environment() const;
143 
148  void setEnvironmentVariable(const QString& key, const QString& value);
149 
151  bool isEnvironmentVariableValueSet(const QString& key, const QString& value);
152 
155  void prependEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
156 
159  void appendEnvironmentVariable(const QString& key, const QString& value, QChar separator = ';');
160 
163  void parseArguments(bool& exitWhenDone);
164 
166  ExitNotRequested = -1,
167  ExitSuccess = EXIT_SUCCESS,
168  ExitFailure = EXIT_FAILURE
169  };
175  int returnCode()const;
176 
178  Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
179 
181  Q_INVOKABLE vtkSlicerApplicationLogic* applicationLogic() const;
182 
185  QString slicerHome() const;
186 
191  QString defaultScenePath() const;
192 
194  void setDefaultScenePath(const QString& path);
195 
202  QString slicerSharePath() const;
203 
206  bool isEmbeddedModule(const QString& moduleFileName)const;
207 
209  QString defaultTemporaryPath() const;
210 
212  QString temporaryPath() const;
213 
215  void setTemporaryPath(const QString& path);
216 
218  QString launcherExecutableFilePath()const;
219 
221  QString launcherSettingsFilePath()const;
222 
224  QString launcherRevisionSpecificUserSettingsFilePath()const;
225 
228  QString slicerDefaultSettingsFilePath()const;
229 
232  QString slicerUserSettingsFilePath()const;
233 
236  QString slicerRevisionUserSettingsFilePath()const;
237 
239  QString defaultExtensionsInstallPath() const;
240 
242  QString extensionsInstallPath() const;
243 
245  void setExtensionsInstallPath(const QString& path);
246 
249  QString intDir()const;
250 
252  bool isInstalled()const;
253 
257  QString releaseType()const;
258 
264  bool isRelease()const;
265 
270  Q_INVOKABLE void addModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
271 
273  Q_INVOKABLE void removeModuleAssociatedNodeType(const QString& nodeClassName, const QString& moduleName);
274 
276  Q_INVOKABLE QStringList modulesAssociatedWithNodeType(const QString& nodeClassName) const;
277 
279  Q_INVOKABLE QStringList allModuleAssociatedNodeTypes() const;
280 
281 #ifdef Slicer_USE_PYTHONQT
282  qSlicerCorePythonManager* corePythonManager()const;
284 
287  void setCorePythonManager(qSlicerCorePythonManager* pythonManager);
288 
290  ctkPythonConsole* pythonConsole()const;
291 
296  void setPythonConsole(ctkPythonConsole* pythonConsole);
297 
298 #endif
299 
300 #ifdef Slicer_BUILD_EXTENSIONMANAGER_SUPPORT
301  Q_INVOKABLE qSlicerExtensionsManagerModel* extensionsManagerModel()const;
303 
306  void setExtensionsManagerModel(qSlicerExtensionsManagerModel* model);
307 #endif
308 
310  Q_INVOKABLE qSlicerModuleManager* moduleManager()const;
311 
313  Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
314 
317  void setCoreIOManager(qSlicerCoreIOManager* ioManager);
318 
320  qSlicerCoreCommandOptions* coreCommandOptions()const;
321 
324  void setCoreCommandOptions(qSlicerCoreCommandOptions* options);
325 
328  Q_INVOKABLE QSettings* defaultSettings()const;
329 
333  Q_INVOKABLE QSettings* userSettings()const;
334 
338  Q_INVOKABLE QSettings* settings()const;
339 
343  Q_INVOKABLE QSettings* revisionUserSettings()const;
344 
346  virtual QString copyrights()const;
347 
349  virtual QString acknowledgment()const;
350 
352  virtual QString libraries()const;
353 
356  QString repositoryUrl()const;
357 
360  QString repositoryBranch()const;
361 
364  QString repositoryRevision()const;
365 
367  int majorVersion() const;
368 
370  int minorVersion() const;
371 
374  QString platform()const;
375 
378  QString arch()const;
379 
382  QString os()const;
383 
384 #ifdef Slicer_BUILD_DICOM_SUPPORT
385  Q_INVOKABLE ctkDICOMDatabase* dicomDatabase() const;
388 
390  Q_INVOKABLE void setDICOMDatabase(ctkDICOMDatabase* dicomDatabase);
391 #endif
392 
393  static void loadTranslations(const QString& dir);
394 
395  static void loadLanguage();
396 
401  static bool loadCaCertificates(const QString& slicerHome);
402 
403  Q_INVOKABLE int registerResource(const QByteArray& data);
404 
405 public slots:
406 
409  static void restart();
410 
411  bool unregisterResource(int handle);
412 
413 protected:
415  virtual void handlePreApplicationCommandLineArguments();
416 
419  virtual void setMRMLScene(vtkMRMLScene * scene);
420 
421 protected slots:
422 
424  virtual void handleCommandLineArguments();
425  virtual void onSlicerApplicationLogicModified();
426  void onSlicerApplicationLogicRequest(vtkObject*, void* , unsigned long);
427  void processAppLogicModified();
428  void processAppLogicReadData();
429  void processAppLogicWriteData();
430 
432  void terminate(int exitCode = qSlicerCoreApplication::ExitSuccess);
433 
438  void requestInvokeEvent(vtkObject* caller, void* callData);
439 
443  void scheduleInvokeEvent(unsigned int delay, void* caller, unsigned long event, void* callData);
444 
449  void invokeEvent();
450 
451 signals:
452  void mrmlSceneChanged(vtkMRMLScene* mrmlScene);
453 
456  void invokeEventRequested(unsigned int delay, void* caller,
457  unsigned long event, void* callData);
458 
459 protected:
460  qSlicerCoreApplication(qSlicerCoreApplicationPrivate* pimpl, int &argc, char **argv);
461  QScopedPointer<qSlicerCoreApplicationPrivate> d_ptr;
462 
463 private:
464  Q_DECLARE_PRIVATE(qSlicerCoreApplication);
465  Q_DISABLE_COPY(qSlicerCoreApplication);
466 };
467 
469 
470 #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