Slicer  4.13
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 <QVariantMap>
31 
32 // CTK includes
33 #include <ctkPimpl.h>
34 
35 // QtCore includes
36 #include <qSlicerIO.h>
37 #include "qSlicerBaseQTCoreExport.h"
38 
40 class vtkMRMLNode;
42 class vtkMRMLStorageNode;
43 class vtkCollection;
44 class vtkObject;
45 class qSlicerCoreIOManagerPrivate;
46 class qSlicerFileReader;
47 class qSlicerFileWriter;
48 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreIOManager:public QObject
49 {
50  Q_OBJECT;
51  Q_PROPERTY(QString defaultSceneFileType READ defaultSceneFileType WRITE setDefaultSceneFileType)
52 
53 public:
54  qSlicerCoreIOManager(QObject* parent = nullptr);
55  ~qSlicerCoreIOManager() override;
56 
58  Q_INVOKABLE qSlicerIO::IOFileType fileType(const QString& file)const;
59  Q_INVOKABLE QList<qSlicerIO::IOFileType> fileTypes(const QString& file)const;
60  Q_INVOKABLE qSlicerIO::IOFileType fileTypeFromDescription(const QString& fileDescription)const;
61 
65  Q_INVOKABLE QStringList fileDescriptions(const QString& file)const;
66  QStringList fileDescriptionsByType(const qSlicerIO::IOFileType fileType)const;
67 
69  Q_INVOKABLE qSlicerIO::IOFileType fileWriterFileType(vtkObject* object, const QString& format=QString())const;
70 
71  Q_INVOKABLE QStringList fileWriterDescriptions(const qSlicerIO::IOFileType& fileType)const;
72  Q_INVOKABLE QStringList fileWriterExtensions(vtkObject* object)const;
75  Q_INVOKABLE QStringList allWritableFileExtensions()const;
78  Q_INVOKABLE QStringList allReadableFileExtensions()const;
79 
81  qSlicerIOOptions* fileOptions(const QString& fileDescription)const;
82  qSlicerIOOptions* fileWriterOptions(vtkObject* object, const QString& extension)const;
83 
89  Q_INVOKABLE QString completeSlicerWritableFileNameSuffix(vtkMRMLStorableNode *node)const;
90 
102  Q_INVOKABLE virtual bool loadNodes(const qSlicerIO::IOFileType& fileType,
103  const qSlicerIO::IOProperties& parameters,
104  vtkCollection* loadedNodes = nullptr,
105  vtkMRMLMessageCollection* userMessages = nullptr);
106 
110  virtual bool loadNodes(const QList<qSlicerIO::IOProperties>& files,
111  vtkCollection* loadedNodes = nullptr,
112  vtkMRMLMessageCollection* userMessages = nullptr);
113 
118  vtkMRMLNode* loadNodesAndGetFirst(qSlicerIO::IOFileType fileType,
119  const qSlicerIO::IOProperties& parameters,
120  vtkMRMLMessageCollection* userMessages = nullptr);
121 
126  Q_INVOKABLE bool loadScene(const QString& fileName, bool clear = true,
127  vtkMRMLMessageCollection* userMessages = nullptr);
128 
132  Q_INVOKABLE bool loadFile(const QString& fileName, vtkMRMLMessageCollection* userMessages = nullptr);
133 
142  Q_INVOKABLE bool saveNodes(qSlicerIO::IOFileType fileType,
143  const qSlicerIO::IOProperties& parameters,
144  vtkMRMLMessageCollection* userMessages=nullptr);
145 
151  Q_INVOKABLE bool saveScene(const QString& fileName, QImage screenShot,
152  vtkMRMLMessageCollection* userMessages=nullptr);
153 
160  Q_INVOKABLE void addDefaultStorageNodes();
161 
164  void registerIO(qSlicerIO* io);
165 
167  Q_INVOKABLE static vtkMRMLStorageNode* createAndAddDefaultStorageNode(vtkMRMLStorableNode* node);
168 
172  Q_INVOKABLE void emitNewFileLoaded(const QVariantMap& loadedFileParameters);
173 
175  Q_INVOKABLE QString defaultSceneFileType()const;
176 
190  Q_INVOKABLE bool examineFileInfoList(QFileInfoList &fileInfoList, QFileInfo &archetypeEntry, QString &readerDescription, qSlicerIO::IOProperties &ioProperties)const;
191 
192 public slots:
193 
197  void setDefaultSceneFileType(QString);
198 
199 signals:
200 
206  void newFileLoaded(const qSlicerIO::IOProperties& loadedFileParameters);
207 
208 protected:
209 
211  const QList<qSlicerFileReader*>& readers()const;
212 
214  const QList<qSlicerFileWriter*>& writers()const;
216  QList<qSlicerFileWriter*> writers(const qSlicerIO::IOFileType& fileType)const;
217 
219  QList<qSlicerFileReader*> readers(const qSlicerIO::IOFileType& fileType)const;
220  qSlicerFileReader* reader(const QString& ioDescription)const;
221 
222 protected:
223  QScopedPointer<qSlicerCoreIOManagerPrivate> d_ptr;
224 
225 private:
226  Q_DECLARE_PRIVATE(qSlicerCoreIOManager);
227  Q_DISABLE_COPY(qSlicerCoreIOManager);
228 };
229 
230 #endif
231 
QScopedPointer< qSlicerCoreIOManagerPrivate > d_ptr
MRML node to represent a 3D surface model.
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