Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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 <QRegularExpression>
31#include <QString>
32#include <QVariantMap>
33
34// CTK includes
35#include <ctkPimpl.h>
36
37// QtCore includes
38#include <qSlicerIO.h>
39#include "qSlicerBaseQTCoreExport.h"
40
42class vtkMRMLNode;
45class vtkCollection;
46class vtkObject;
47class qSlicerCoreIOManagerPrivate;
53
59class Q_SLICER_BASE_QTCORE_EXPORT qSlicerCoreIOManager : public QObject
60{
61 Q_OBJECT;
64
65public:
66 qSlicerCoreIOManager(QObject* parent = nullptr);
68
71 Q_INVOKABLE vtkMRMLFileIOManager* fileIOManager() const;
72
74 Q_INVOKABLE qSlicerIO::IOFileType fileType(const QString& file) const;
76 Q_INVOKABLE QList<qSlicerIO::IOFileType> fileTypes(const QString& file) const;
77
79 Q_INVOKABLE qSlicerIO::IOFileType fileTypeFromDescription(const QString& fileDescription) const;
80
84 Q_INVOKABLE QStringList fileDescriptions(const QString& file) const;
85
88 Q_INVOKABLE QStringList fileDescriptionsByType(const qSlicerIO::IOFileType fileType) const;
89
91 Q_INVOKABLE qSlicerFileWriter* writer(vtkObject* object, const QString& extension = QString()) const;
92
94 Q_INVOKABLE qSlicerIO::IOFileType fileWriterFileType(vtkObject* object, const QString& extension = QString()) const;
95
96 Q_INVOKABLE QStringList fileWriterDescriptions(const qSlicerIO::IOFileType& fileType) const;
97 Q_INVOKABLE QStringList fileWriterExtensions(vtkObject* object) const;
100 Q_INVOKABLE QStringList allWritableFileExtensions() const;
103 Q_INVOKABLE QStringList allReadableFileExtensions() const;
104
108 qSlicerIOOptions* fileOptions(const QString& fileDescription) const;
109
113 qSlicerIOOptions* fileWriterOptions(vtkObject* object, const QString& extension) const;
114
121
126 Q_INVOKABLE static QRegularExpression fileNameRegularExpression(const QString& extension = QString());
127
129 Q_INVOKABLE static QString forceFileNameValidCharacters(const QString& filename);
130
136 Q_INVOKABLE QString forceFileNameMaxLength(const QString& filename, int extensionLength, int maxLength = -1);
137
142
147 Q_INVOKABLE QString extractKnownExtension(const QString& fileName, vtkObject* object);
148
153 Q_INVOKABLE QString stripKnownExtension(const QString& fileName, vtkObject* object);
154
167 Q_INVOKABLE virtual bool loadNodes(const qSlicerIO::IOFileType& fileType,
168 const qSlicerIO::IOProperties& parameters,
169 vtkCollection* loadedNodes = nullptr,
170 vtkMRMLMessageCollection* userMessages = nullptr);
171
176 Q_INVOKABLE virtual bool loadNodes(const QList<qSlicerIO::IOProperties>& files, vtkCollection* loadedNodes = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
177
182 Q_INVOKABLE vtkMRMLNode* loadNodesAndGetFirst(qSlicerIO::IOFileType fileType, const qSlicerIO::IOProperties& parameters, vtkMRMLMessageCollection* userMessages = nullptr);
183
188 Q_INVOKABLE bool loadScene(const QString& fileName, bool clear = true, vtkMRMLMessageCollection* userMessages = nullptr);
189
193 Q_INVOKABLE bool loadFile(const QString& fileName, vtkMRMLMessageCollection* userMessages = nullptr);
194
204 Q_INVOKABLE bool saveNodes(qSlicerIO::IOFileType fileType,
205 const qSlicerIO::IOProperties& parameters,
206 vtkMRMLMessageCollection* userMessages = nullptr,
207 vtkMRMLScene* scene = nullptr);
208
217 Q_INVOKABLE bool exportNodes(const QList<qSlicerIO::IOProperties>& parameterMaps, bool hardenTransforms, vtkMRMLMessageCollection* userMessages = nullptr);
218
223 Q_INVOKABLE bool exportNodes(const QStringList& nodeIDs,
224 const QStringList& fileNames,
225 const qSlicerIO::IOProperties& commonParameterMap,
226 bool hardenTransforms,
227 vtkMRMLMessageCollection* userMessages = nullptr);
228
234 Q_INVOKABLE bool saveScene(const QString& fileName, QImage screenShot, vtkMRMLMessageCollection* userMessages = nullptr);
235
242 Q_INVOKABLE void addDefaultStorageNodes();
243
246 Q_INVOKABLE void registerIO(qSlicerIO* io);
247
255 Q_INVOKABLE int registeredFileReaderCount(const qSlicerIO::IOFileType& fileType) const;
256 Q_INVOKABLE int registeredFileWriterCount(const qSlicerIO::IOFileType& fileType) const;
258
261
265 Q_INVOKABLE void emitNewFileLoaded(const QVariantMap& loadedFileParameters);
266
270 Q_INVOKABLE void emitFileSaved(const QVariantMap& savedFileParameters);
271
273 Q_INVOKABLE QString defaultSceneFileType() const;
274
288 Q_INVOKABLE bool examineFileInfoList(QFileInfoList& fileInfoList, QFileInfo& archetypeEntry, QString& readerDescription, qSlicerIO::IOProperties& ioProperties) const;
289
290public slots:
291
296
300
301signals:
302
308 void newFileLoaded(const qSlicerIO::IOProperties& loadedFileParameters);
309
314 void fileSaved(const qSlicerIO::IOProperties& savedFileParameters);
315
316public:
318 Q_INVOKABLE QList<qSlicerFileReader*> readers() const;
319
321 Q_INVOKABLE QList<qSlicerFileWriter*> writers() const;
323 Q_INVOKABLE QList<qSlicerFileWriter*> writers(const qSlicerIO::IOFileType& fileType) const;
324
326 Q_INVOKABLE QList<qSlicerFileReader*> readers(const qSlicerIO::IOFileType& fileType) const;
328 Q_INVOKABLE qSlicerFileReader* reader(const QString& ioDescription) const;
329
330protected:
338 virtual void endProgress(vtkMRMLOperationProgress* progress);
339
345
346protected:
347 QScopedPointer<qSlicerCoreIOManagerPrivate> d_ptr;
348
349private:
350 Q_DECLARE_PRIVATE(qSlicerCoreIOManager);
351 Q_DISABLE_COPY(qSlicerCoreIOManager);
352};
353
354#endif
Q_INVOKABLE qSlicerFileReader * reader(const QString &ioDescription) const
Returns the reader that has the specified description (such as "Volume")
Q_INVOKABLE QStringList fileWriterExtensions(vtkObject *object) const
virtual Q_INVOKABLE bool loadNodes(const qSlicerIO::IOFileType &fileType, const qSlicerIO::IOProperties &parameters, vtkCollection *loadedNodes=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
virtual void endProgress(vtkMRMLOperationProgress *progress)
Q_INVOKABLE QString completeSlicerWritableFileNameSuffix(vtkMRMLStorableNode *node) const
Q_INVOKABLE bool loadFile(const QString &fileName, vtkMRMLMessageCollection *userMessages=nullptr)
Q_INVOKABLE QString extractKnownExtension(const QString &fileName, vtkObject *object)
Q_INVOKABLE void emitFileSaved(const QVariantMap &savedFileParameters)
Q_INVOKABLE void registerIO(qSlicerIO *io)
Q_INVOKABLE QStringList allReadableFileExtensions() const
void newFileLoaded(const qSlicerIO::IOProperties &loadedFileParameters)
static Q_INVOKABLE QRegularExpression fileNameRegularExpression(const QString &extension=QString())
Q_INVOKABLE qSlicerFileWriter * writer(vtkObject *object, const QString &extension=QString()) const
Return best file writer for this object.
Q_INVOKABLE bool loadScene(const QString &fileName, bool clear=true, vtkMRMLMessageCollection *userMessages=nullptr)
Q_INVOKABLE qSlicerIO::IOFileType fileWriterFileType(vtkObject *object, const QString &extension=QString()) const
Return the file type of the best file writer for the input VTK object.
Q_INVOKABLE QList< qSlicerIO::IOFileType > fileTypes(const QString &file) const
Return all supported file types for reading a file.
Q_INVOKABLE qSlicerIO::IOFileType fileTypeFromDescription(const QString &fileDescription) const
Return the most likely file description (SegmentationFile, TextFile, ...) for reading a file.
Q_INVOKABLE QString stripKnownExtension(const QString &fileName, vtkObject *object)
Q_INVOKABLE QList< qSlicerFileWriter * > writers() const
Returns the list of registered writers.
Q_INVOKABLE vtkMRMLFileIOManager * fileIOManager() const
QScopedPointer< qSlicerCoreIOManagerPrivate > d_ptr
virtual void startProgress(vtkMRMLOperationProgress *progress)
Q_INVOKABLE QStringList fileDescriptionsByType(const qSlicerIO::IOFileType fileType) const
void setDefaultMaximumFileNameLength(int)
virtual void updateProgress(vtkMRMLOperationProgress *progress)
Q_INVOKABLE vtkMRMLNode * loadNodesAndGetFirst(qSlicerIO::IOFileType fileType, const qSlicerIO::IOProperties &parameters, vtkMRMLMessageCollection *userMessages=nullptr)
Q_INVOKABLE QStringList fileDescriptions(const QString &file) const
static Q_INVOKABLE vtkMRMLStorageNode * createAndAddDefaultStorageNode(vtkMRMLStorableNode *node)
}@
Q_INVOKABLE QList< qSlicerFileReader * > readers() const
Returns the list of registered readers.
void fileSaved(const qSlicerIO::IOProperties &savedFileParameters)
Q_INVOKABLE bool exportNodes(const QList< qSlicerIO::IOProperties > &parameterMaps, bool hardenTransforms, vtkMRMLMessageCollection *userMessages=nullptr)
qSlicerIOOptions * fileWriterOptions(vtkObject *object, const QString &extension) const
Q_INVOKABLE void emitNewFileLoaded(const QVariantMap &loadedFileParameters)
Q_INVOKABLE qSlicerIO::IOFileType fileType(const QString &file) const
Return the most likely file type (SegmentationFile, TextFile, ...) for reading a file.
qSlicerIOOptions * fileOptions(const QString &fileDescription) const
virtual qSlicerIOOptions * createGenericOptions(vtkMRMLFileIOHandler *ioHandler) const
Q_INVOKABLE bool examineFileInfoList(QFileInfoList &fileInfoList, QFileInfo &archetypeEntry, QString &readerDescription, qSlicerIO::IOProperties &ioProperties) const
Q_INVOKABLE QStringList fileWriterDescriptions(const qSlicerIO::IOFileType &fileType) const
void setDefaultSceneFileType(QString)
Q_INVOKABLE void addDefaultStorageNodes()
Q_INVOKABLE bool saveScene(const QString &fileName, QImage screenShot, vtkMRMLMessageCollection *userMessages=nullptr)
Q_INVOKABLE int registeredFileWriterCount(const qSlicerIO::IOFileType &fileType) const
qSlicerCoreIOManager(QObject *parent=nullptr)
Q_INVOKABLE QString forceFileNameMaxLength(const QString &filename, int extensionLength, int maxLength=-1)
static Q_INVOKABLE QString forceFileNameValidCharacters(const QString &filename)
Remove characters that are likely to cause problems in a filename.
Q_INVOKABLE int registeredFileReaderCount(const qSlicerIO::IOFileType &fileType) const
Q_INVOKABLE QStringList allWritableFileExtensions() const
Q_INVOKABLE bool saveNodes(qSlicerIO::IOFileType fileType, const qSlicerIO::IOProperties &parameters, vtkMRMLMessageCollection *userMessages=nullptr, vtkMRMLScene *scene=nullptr)
Abstract Superclass for all specific types of MRML nodes.
Progress of a long operation, such as loading files.
A set of MRML Nodes that supports serialization and undo/redo.
MRML node to represent a 3D surface model.
A superclass for other storage nodes.
QMap< QString, QVariant > QVariantMap