Slicer  5.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerCoreIOManager.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 __qSlicerCoreIOManager_h
22 #define __qSlicerCoreIOManager_h
23 
24 // Qt includes
25 #include <QFileInfo>
26 #include <QImage>
27 #include <QList>
28 #include <QMap>
29 #include <QObject>
30 #include <QString>
31 #include <QVariantMap>
32 
33 // CTK includes
34 #include <ctkPimpl.h>
35 
36 // QtCore includes
37 #include <qSlicerIO.h>
38 #include "qSlicerBaseQTCoreExport.h"
39 
41 class vtkMRMLNode;
43 class vtkMRMLStorageNode;
44 class vtkCollection;
45 class vtkObject;
46 class qSlicerCoreIOManagerPrivate;
47 class qSlicerFileReader;
48 class qSlicerFileWriter;
49 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreIOManager:public QObject
50 {
51  Q_OBJECT;
52  Q_PROPERTY(QString defaultSceneFileType READ defaultSceneFileType WRITE setDefaultSceneFileType)
53 
54 public:
55  qSlicerCoreIOManager(QObject* parent = nullptr);
56  ~qSlicerCoreIOManager() override;
57 
59  Q_INVOKABLE qSlicerIO::IOFileType fileType(const QString& file)const;
60  Q_INVOKABLE QList<qSlicerIO::IOFileType> fileTypes(const QString& file)const;
61  Q_INVOKABLE qSlicerIO::IOFileType fileTypeFromDescription(const QString& fileDescription)const;
62 
66  Q_INVOKABLE QStringList fileDescriptions(const QString& file)const;
67  QStringList fileDescriptionsByType(const qSlicerIO::IOFileType fileType)const;
68 
70  Q_INVOKABLE qSlicerIO::IOFileType fileWriterFileType(vtkObject* object, const QString& format=QString())const;
71 
72  Q_INVOKABLE QStringList fileWriterDescriptions(const qSlicerIO::IOFileType& fileType)const;
73  Q_INVOKABLE QStringList fileWriterExtensions(vtkObject* object)const;
76  Q_INVOKABLE QStringList allWritableFileExtensions()const;
79  Q_INVOKABLE QStringList allReadableFileExtensions()const;
80 
82  qSlicerIOOptions* fileOptions(const QString& fileDescription)const;
83  qSlicerIOOptions* fileWriterOptions(vtkObject* object, const QString& extension)const;
84 
90  Q_INVOKABLE QString completeSlicerWritableFileNameSuffix(vtkMRMLStorableNode *node)const;
91 
96  Q_INVOKABLE static QRegExp fileNameRegExp(const QString& extension = QString());
97 
99  Q_INVOKABLE static QString forceFileNameValidCharacters(const QString& filename);
100 
105  Q_INVOKABLE QString extractKnownExtension(const QString& fileName, vtkObject* object);
106 
111  Q_INVOKABLE QString stripKnownExtension(const QString& fileName, vtkObject* object);
112 
124  Q_INVOKABLE virtual bool loadNodes(const qSlicerIO::IOFileType& fileType,
125  const qSlicerIO::IOProperties& parameters,
126  vtkCollection* loadedNodes = nullptr,
127  vtkMRMLMessageCollection* userMessages = nullptr);
128 
132  virtual bool loadNodes(const QList<qSlicerIO::IOProperties>& files,
133  vtkCollection* loadedNodes = nullptr,
134  vtkMRMLMessageCollection* userMessages = nullptr);
135 
140  vtkMRMLNode* loadNodesAndGetFirst(qSlicerIO::IOFileType fileType,
141  const qSlicerIO::IOProperties& parameters,
142  vtkMRMLMessageCollection* userMessages = nullptr);
143 
148  Q_INVOKABLE bool loadScene(const QString& fileName, bool clear = true,
149  vtkMRMLMessageCollection* userMessages = nullptr);
150 
154  Q_INVOKABLE bool loadFile(const QString& fileName, vtkMRMLMessageCollection* userMessages = nullptr);
155 
165  Q_INVOKABLE bool saveNodes(qSlicerIO::IOFileType fileType,
166  const qSlicerIO::IOProperties& parameters,
167  vtkMRMLMessageCollection* userMessages=nullptr,
168  vtkMRMLScene* scene=nullptr
169  );
170 
179  Q_INVOKABLE bool exportNodes(
180  const QList<qSlicerIO::IOProperties>& parameterMaps,
181  bool hardenTransforms,
182  vtkMRMLMessageCollection* userMessages=nullptr
183  );
184 
189  Q_INVOKABLE bool exportNodes(
190  const QStringList& nodeIDs,
191  const QStringList& fileNames,
192  const qSlicerIO::IOProperties& commonParameterMap,
193  bool hardenTransforms,
194  vtkMRMLMessageCollection* userMessages = nullptr
195  );
196 
202  Q_INVOKABLE bool saveScene(const QString& fileName, QImage screenShot,
203  vtkMRMLMessageCollection* userMessages=nullptr);
204 
211  Q_INVOKABLE void addDefaultStorageNodes();
212 
215  void registerIO(qSlicerIO* io);
216 
218  Q_INVOKABLE static vtkMRMLStorageNode* createAndAddDefaultStorageNode(vtkMRMLStorableNode* node);
219 
223  Q_INVOKABLE void emitNewFileLoaded(const QVariantMap& loadedFileParameters);
224 
228  Q_INVOKABLE void emitFileSaved(const QVariantMap& savedFileParameters);
229 
231  Q_INVOKABLE QString defaultSceneFileType()const;
232 
246  Q_INVOKABLE bool examineFileInfoList(QFileInfoList &fileInfoList, QFileInfo &archetypeEntry, QString &readerDescription, qSlicerIO::IOProperties &ioProperties)const;
247 
248 public slots:
249 
253  void setDefaultSceneFileType(QString);
254 
255 signals:
256 
262  void newFileLoaded(const qSlicerIO::IOProperties& loadedFileParameters);
263 
268  void fileSaved(const qSlicerIO::IOProperties& savedFileParameters);
269 
270 protected:
271 
273  const QList<qSlicerFileReader*>& readers()const;
274 
276  const QList<qSlicerFileWriter*>& writers()const;
278  QList<qSlicerFileWriter*> writers(const qSlicerIO::IOFileType& fileType)const;
279 
281  QList<qSlicerFileReader*> readers(const qSlicerIO::IOFileType& fileType)const;
282  qSlicerFileReader* reader(const QString& ioDescription)const;
283 
284 protected:
285  QScopedPointer<qSlicerCoreIOManagerPrivate> d_ptr;
286 
287 private:
288  Q_DECLARE_PRIVATE(qSlicerCoreIOManager);
289  Q_DISABLE_COPY(qSlicerCoreIOManager);
290 };
291 
292 #endif
293 
QScopedPointer< qSlicerCoreIOManagerPrivate > d_ptr
MRML node to represent a 3D surface model.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
A superclass for other storage nodes.
Base class for qSlicerFileReader and qSlicerFileWriter.
Definition: qSlicerIO.h:41
QString IOFileType
Definition: qSlicerIO.h:52
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167