Commit 56ed5df2 authored by jcfr's avatar jcfr
Browse files

ENH: Expose IO manager methods to python

Method ioManager, coreIOManager, fileType and loadNodes are now
callable from python.

Constant in qSlicerIO are also exposed

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15418 3bd1e089-480b-0410-8dfb-8563597acbee
parent 64273c25
import vtk, qt, ctk
import slicer
#
# General
#
def quit():
exit()
......@@ -16,7 +20,56 @@ def mainWindow():
if w.objectName == _objectName: return w
print "Failed to obtain reference to '%s'" % _objectName
return None
#
# IO
#
def loadColorTable(filename):
filetype = slicer.qSlicerIO.ColorTableFile
properties = {}
return app().coreIOManager().loadNodes(filetype, properties)
def loadDTI(filename):
filetype = slicer.qSlicerIO.DTIFile
properties = {}
return app().coreIOManager().loadNodes(filetype, properties)
def loadFiducialList(filename):
filetype = slicer.qSlicerIO.FiducialListFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
def loadModel(filename):
filetype = slicer.qSlicerIO.ModelFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
def loadScalarOverlay(filename):
filetype = slicer.qSlicerIO.ScalarOverlayFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
# /home/jchris/Projects/Slicer3-Data/spl_pnl_brain_atlas_2007_slicer3/atlas-2007.mrml
def loadScene(filename, clear = True):
filetype = slicer.qSlicerIO.SceneFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
def loadTransform(filename):
filetype = slicer.qSlicerIO.TransformFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
def loadVolume(filename):
filetype = slicer.qSlicerIO.VolumeFile
properties = {'fileName':filename}
return app().coreIOManager().loadNodes(filetype, properties)
#
# Module
#
def selectModule(module):
moduleName = module
if not isinstance(module, basestring):
......@@ -45,6 +98,11 @@ def getModuleGui(moduleName):
return None
return widgetRepr
#
# MRML
#
def getNodes():
nodes = {}
scene = slicer.mrmlScene
......@@ -55,8 +113,9 @@ def getNodes():
return nodes
#
# __InternalInstance
# Internal
#
class _Internal():
def __init__(self):
import imp
......
......@@ -138,9 +138,8 @@ public:
/// Get the module manager
qSlicerModuleManager* moduleManager()const;
///
/// Get the IO manager
qSlicerCoreIOManager* coreIOManager()const;
Q_INVOKABLE qSlicerCoreIOManager* coreIOManager()const;
/// Set the IO manager
/// Note that qSlicerCoreApplication takes ownership of the object
......
......@@ -223,7 +223,7 @@ vtkMRMLNode* qSlicerCoreIOManager::loadNodesAndGetFirst(
}
//-----------------------------------------------------------------------------
bool qSlicerCoreIOManager::saveNodes(qSlicerIO::IOFileType fileType,
bool qSlicerCoreIOManager::saveNodes(qSlicerIO::IOFileType fileType,
const qSlicerIO::IOProperties& parameters)
{
Q_D(qSlicerCoreIOManager);
......
......@@ -44,24 +44,19 @@ public:
qSlicerCoreIOManager(QObject* parent = 0);
virtual ~qSlicerCoreIOManager();
///
/// Return the file type associated with a \a file
qSlicerIO::IOFileType fileType(const QString& file)const;
Q_INVOKABLE qSlicerIO::IOFileType fileType(const QString& file)const;
///
/// Return the file description associated with a \a file
/// Usually the description is a short text of one or two words
QString fileDescription(const QString& file)const;
///
/// Return the file option associated with a \a file
inline qSlicerIOOptions* fileOptions(const QString& file)const;
///
/// Return the file option associated with a \a file type
qSlicerIOOptions* fileOptions(const qSlicerIO::IOFileType& fileType)const;
///
/// Load a list of nodes corresponding to \a fileType. A given \a fileType corresponds
/// to a specific reader qSlicerIO.
/// A map of qvariant allows to specify which \a parameters should be passed to the reader.
......@@ -72,15 +67,14 @@ public:
/// More specific parameters could also be set. For example, the volume reader qSlicerVolumesIO
/// could also be called with the following parameters: LabelMap (bool), Center (bool)
///
/// Note: Make also sure the case of parameter name is respected
/// \note Make also sure the case of parameter name is respected
///
/// \sa qSlicerIO::IOProperties, qSlicerIO::IOFileType
bool loadNodes(const qSlicerIO::IOFileType& fileType,
const qSlicerIO::IOProperties& parameters,
vtkCollection* loadedNodes = 0);
Q_INVOKABLE bool loadNodes(const qSlicerIO::IOFileType& fileType,
const qSlicerIO::IOProperties& parameters,
vtkCollection* loadedNodes = 0);
///
/// Load a list of node corresponding to \a fileType and return the first loaded node.
/// This function is provided for convenience and is equivalent to call loadNodes
/// with a vtkCollection parameter and retrieve the first element.
......@@ -88,30 +82,26 @@ public:
const qSlicerIO::IOProperties& parameters);
///
/// Load/import a scene corresponding to \a fileName
/// This function is provided for convenience and is equivalent to call
/// loadNodes function with qSlicerIO::SceneFile
bool loadScene(const QString& fileName, bool clear = true);
///
/// attributes are typically:
/// Attributes are typically:
/// All: fileName[s]
/// Volume: LabelMap:bool, Center:bool, fileNames:QList<QString>...
bool saveNodes(qSlicerIO::IOFileType fileType,
const qSlicerIO::IOProperties& parameters);
///
/// Register the reader/writer \a io
/// Note also that the IOManager takes ownership of \a io
void registerIO(qSlicerIO* io);
protected:
///
/// Returns the list of registered readers/writers
const QList<qSlicerIO*>& ios()const;
///
/// Returns the list of registered readers or writers associated with \a fileType
QList<qSlicerIO*> ios(const qSlicerIO::IOFileType& fileType)const;
......
......@@ -46,6 +46,8 @@ qSlicerIO::qSlicerIO(QObject* _parent)
:QObject(_parent)
, d_ptr(new qSlicerIOPrivate)
{
qRegisterMetaType<qSlicerIO::IOFileType>("qSlicerIO::IOFileType");
qRegisterMetaType<qSlicerIO::IOProperties>("qSlicerIO::IOProperties");
}
//----------------------------------------------------------------------------
......
......@@ -41,11 +41,13 @@ class qSlicerIOPrivate;
class Q_SLICER_BASE_QTCORE_EXPORT qSlicerIO : public QObject
{
Q_OBJECT
Q_ENUMS(IOFileTypes)
public:
explicit qSlicerIO(QObject* parent = 0);
virtual ~qSlicerIO();
typedef int IOFileType;
typedef int IOFileType;
enum IOFileTypes
{
NoFile = 0,
......@@ -99,4 +101,7 @@ private:
Q_DISABLE_COPY(qSlicerIO);
};
Q_DECLARE_METATYPE(qSlicerIO::IOFileType)
Q_DECLARE_METATYPE(qSlicerIO::IOProperties)
#endif
......@@ -63,7 +63,7 @@ public:
qSlicerCommandOptions* commandOptions();
/// Get IO Manager
qSlicerIOManager* ioManager();
Q_INVOKABLE qSlicerIOManager* ioManager();
#ifdef Slicer_USE_PYTHONQT
/// Get Python Manager
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment