itom 2.2.1
ito::IOHelper Class Reference

This class contains several static methods to load or save various file formats. More...

List of all members.

Public Types

enum  IOFilter {
  IOInput = 0x001, IOOutput = 0x002, IOPlugin = 0x004, IOAllFiles = 0x008,
  IOWorkspace = 0x010, IOMimeDataObject = 0x020, IOMimePointCloud = 0x040, IOMimePolygonMesh = 0x080,
  IOMimeAll = IOMimeDataObject | IOMimePointCloud | IOMimePolygonMesh
}
enum  SearchFolder {
  SFResources = 0x001, SFDirect = 0x002, SFCurrent = 0x004, SFAppDir = 0x008,
  SFAppDirQItom = 0x010, SFAll = SFResources | SFDirect | SFCurrent | SFAppDir | SFAppDirQItom
}

Static Public Member Functions

static RetVal openGeneralFile (const QString &generalFileName, bool openUnknownsWithExternalApp=true, bool showMessages=false, QWidget *parent=NULL, const char *errorSlotMemberOfParent=NULL, bool globalNotLocalWorkspace=true)
 method to load any supported file
static RetVal uiExportPyWorkspaceVars (bool globalNotLocal, const QStringList &varNames, QVector< int > compatibleParamBaseTypes, QString defaultPath=QString::Null(), QWidget *parent=NULL)
 export one or more variables from a python workspace
static RetVal exportPyWorkspaceVars (const QString &filename, bool globalNotLocal, const QStringList &varNames)
 export one or more variables from a python workspace to an idc or mat file
static RetVal uiImportPyWorkspaceVars (bool globalNotLocal, const IOFilters &IOfilters, QString defaultPath=QString::Null(), QWidget *parent=NULL)
 open a file load dialog and let the user selected a file that is opened and load to a python workspace
static RetVal importPyWorkspaceVars (const QString &filename, bool globalNotLocal)
 import an idc or mat file and load the content to a python workspace
static RetVal openPythonScript (const QString &filename)
 open a given python file in a script editor window
static RetVal uiOpenFileWithFilter (const ito::AddInAlgo::FilterDef *filter, const QString &filename, QWidget *parent=NULL, bool globalNotLocal=true)
 open a file using a filter method from an algorithm plugin and shows an import dialog
static RetVal uiSaveFileWithFilter (QSharedPointer< ito::ParamBase > &value, const QString &filename, QWidget *parent=NULL)
 save a file using a filter method from an algorithm plugin and shows an export dialog
static RetVal openUIFile (const QString &filename, QWidget *parent=NULL, const char *errorSlotMemberOfParent=NULL)
 open ui file in an instance of QtDesigner
static QString getFileFilters (const IOFilters &IOfilters, QStringList *allPatterns=NULL)
 Returns a list of all file endings that correspond to itom.
static bool fileFitsToFileFilters (const QString &filename, const IOFilters &IOfilters)
 Checks if a file fits to a filter.
static void elideFilepathMiddle (QString &path, int pixelLength)
 Shortens paths so that menus can display them without becoming too big.
static QIcon searchIcon (const QString &filename, const SearchFolders &searchFolders=SFAll, const QIcon &fallbackIcon=QIcon())
 search an icon file in different locations, open and return it

Private Member Functions

 ~IOHelper ()
 IOHelper (const IOHelper &)

Detailed Description

This class contains several static methods to load or save various file formats.

The methods in this class can be used to save or load data objects, point clouds or polygonal meshes to or from various file formats. The algorithms for most file formats are not directly supported by this class, but algorithm plugins are scanned and checked if they support loading or saving from or to different formats. If so, the specific method in the plugin is called by methods defined in this class.

Most methods can be operated with or without GUI support, hence either message boxes are displayed or the communication is done by RetVal only.


Member Enumeration Documentation

IOFilter enumeration This enum contains flags to filter out input/output algorithms for various objects

Enumerator:
IOInput 

consider algorithms for file input

IOOutput 

consider algorithms for file output

IOPlugin 

consider algorithms provided by plugins

IOAllFiles 

add the "All Files (*.*)" filter

IOWorkspace 

only consider filters which can be imported or exported from python workspace

IOMimeDataObject 

consider algorithms that allow saving or loading data objects

IOMimePointCloud 

consider algorithms that allow saving or loading point clouds

IOMimePolygonMesh 

consider algorithms that allow saving or loading polygonal meshes

IOMimeAll 

or-combination of IOMimeDataObject, IOMimePointCloud and IOMimePolygonMesh

SearchFolder enumeration This enumeration contains values to describe specific directories that are searched for files (e.g. icons)

Enumerator:
SFResources 

search the resource files for the file

SFDirect 

consider the file as absolute file path

SFCurrent 

look for the given file in the current directory

SFAppDir 

look for the file in the application directory of itom

SFAppDirQItom 

look for the file in the Qitom subdirectory of the application directory

SFAll 

or-combination of all available search folders


Constructor & Destructor Documentation

ito::IOHelper::~IOHelper ( ) [inline, private]

private constructor since this class only contains static method and no instance must be created

ito::IOHelper::IOHelper ( const IOHelper ) [inline, private]

private destructor


Member Function Documentation

void ito::IOHelper::elideFilepathMiddle ( QString &  path,
int  pixelLength 
) [static]

Shortens paths so that menus can display them without becoming too big.

This functio is used to shorten paths so they fit into a menu or something compareable.

Example: D:/testdir1/testdir2/file.py becomes D:/...ir2/file.py

If the pixelLength is shorter than the filename a minimum is returned: D:/...file.py Even if the minimum is longer than the pixelLength.

Parameters:
pathThe path that is supposed to be shortened
pixelLengthThe length the path has to have after shortening
RetVal ito::IOHelper::exportPyWorkspaceVars ( const QString &  filename,
bool  globalNotLocal,
const QStringList &  varNames 
) [static]

export one or more variables from a python workspace to an idc or mat file

This method exports one or more variables from the global or local python workspace to a idc (itom data collection) or mat (Matlab) container file. Other file suffixes will return an error. For the export, the slots pickleVariables (idc) or saveMatlabVariables (mat), defined in class PythonEngine, are invoked. Mat is only supported if the Python package Scipy is available. The idc format is written via the Python module pickle.

Parameters:
filenameis the filename to the idc or mat file
globalNotLocaldefines if the variables are exported from the global (true) or local (false) workspace varNames is a list if one or multiple variable names within the workspace. These can be single variable names (direct child of local or global workspace, or a full item name to any subitem as it is used in workspaceWidget)
Returns:
success of the export as RetVal
See also:
uiExportPyWorkspaceVars
bool ito::IOHelper::fileFitsToFileFilters ( const QString &  filename,
const IOFilters &  IOfilters 
) [static]

Checks if a file fits to a filter.

This function checks if a fileending of a file fits to a given set of filters.

Parameters:
filenamepass the filename as a QString
IOfilterspass the filterset that the filename shopuld be checked against
Returns:
returns true if the file fits to the filters, else false is returned
QString ito::IOHelper::getFileFilters ( const IOFilters &  IOfilters,
QStringList *  allPatterns = NULL 
) [static]

Returns a list of all file endings that correspond to itom.

This function returns a QString that contains a semicolon separated list of all fileendings that were passed by the iofilters parameter

Parameters:
IOfiltersfilters that contain the filenendings
allPatternsPointer to QStringList (standard = 0)
Returns:
returns a QString with fileendings (semicolon separated)
RetVal ito::IOHelper::importPyWorkspaceVars ( const QString &  filename,
bool  globalNotLocal 
) [static]

import an idc or mat file and load the content to a python workspace

Import an idc (itom data collection) or mat (Matlab) ocntainer to the global or local python workspace. This is done by an invokation of the slot unpickleVariables or loadMatlabVariables of the class PythonEngine.

Parameters:
filenameis the filename with a suffix idc or mat (only supported if Scipy is available)
globalNotLocaldefines if the file is loaded to the global (true) or local (false) workspace
Returns:
success of the import as RetVal
See also:
unpickleVariables, loadMatlabVariables
RetVal ito::IOHelper::openGeneralFile ( const QString &  generalFileName,
bool  openUnknownsWithExternalApp = true,
bool  showMessages = false,
QWidget *  parent = NULL,
const char *  errorSlotMemberOfParent = NULL,
bool  globalNotLocalWorkspace = true 
) [static]

method to load any supported file

This method tries to load any given file that is directly or indirectly supported. Indirect support means that algorithm plugins are checked for their support for the given file format. If there is a corresponding method found, it is used to open the file.

Possible file formats are:

.py -> open the python file in a script editor .idc -> loads the content of the 'itom data collection' file to the global or local python workspace .mat -> load the content of the Matlab file to the global or local python workspace using Scipy (only if the package Scipy is available) .ui -> open the ui file in the QtDesigner application else -> tries to find at least algorithm that supports this file ending and can load it to a data object, point cloud or polygonal mesh (to global or local workspace)

If two or more algorithms pretend to be able to load the file format, a dialog appears where the user can select the desired filter.

Parameters:
generalFileNameis the file name to load. If the file name is not absolute, it is considered to be relative to the current directory.
openUnknownsWithExternalAppis a boolean variable that indicates if an unsupported or unknown file format is opened with the external application that is officially connected with this file format
showMessagesif true, an error or warning during the execution of this method will be displayed in a message box.
parentis the widget this method should be related to. Dialogs or messages are then displayed using this parent.
errorSlotMemberOfParentis only considered for ui-files. Pass a SLOT(myMethod(QProcess::ProcessError)) description such that errors occurred in the QtDesigner will call the given slot. Else pass NULL.
globalNotLocalWorkspaceis only considered when files are opened that load data objects, point clouds or polygonal meshes to the Python workspace. If true, the object is loaded to the global workspace, else to the local (only allowed if a local workspace is currently available)
Returns:
success of loading as RetVal
See also:
openPythonScript, importPyWorkspaceVars, openUIFile, uiOpenFileWithFilter
RetVal ito::IOHelper::openPythonScript ( const QString &  filename) [static]

open a given python file in a script editor window

Open the given python file (suffix *.py) using the slot openScript of the class ScriptEditorOrganizer.

Parameters:
filenameis the filename to the py file
Returns:
retOk in case of success and retError in case of an error or timeout.
See also:
openScript
RetVal ito::IOHelper::openUIFile ( const QString &  filename,
QWidget *  parent = NULL,
const char *  errorSlotMemberOfParent = NULL 
) [static]

open ui file in an instance of QtDesigner

Tries to open the given ui file in a new or already opened instance of QtDesigner. The designer folder of itom is passed as plugin path to the QtDesigner such that itom designer plugins are also considered as widgets in the QtDesigner application.

It is possible to pass a slot with a single argument of type QProcess::ProcessError. If this slot is given, it is connected to the error signal of the QtDesigner process such that error during the startup... of QtDesigner can be appropriately handled.

Parameters:
filenameis the filename to the ui file
parentis the widget where the slot given by errorSlotMemberOfParent is defined
errorSlotMemberOfParentis SLOT(myMethod(QProcess::ProcessError)) description such that errors occurred in the QtDesigner will call the given slot. Else pass NULL.
Returns:
retOk in case of success and retError in case of an error or timeout.
QIcon ito::IOHelper::searchIcon ( const QString &  filename,
const SearchFolders &  searchFolders = SFAll,
const QIcon &  fallbackIcon = QIcon() 
) [static]

search an icon file in different locations, open and return it

Parameters:
filenameis the relative or absolute filename of the icon
searchFoldersis a bitmask that defines the locations that are searched for the filename
fallbackIconlet you define an alternative icon that is returned if filename is not found in any location
Returns:
loaded icon or invalid QIcon
RetVal ito::IOHelper::uiExportPyWorkspaceVars ( bool  globalNotLocal,
const QStringList &  varNames,
QVector< int >  compatibleParamBaseTypes,
QString  defaultPath = QString::Null(),
QWidget *  parent = NULL 
) [static]

export one or more variables from a python workspace

This method allows exporting one or more variables from the global or local python workspace to a user defined file. A file save dialog is shown to the user in order to select the desired file name. Depending on the type of the given variables, the dialog only allows inserting supported file formats.

One or multiple variables can be saved in idc (itom data collection) or mat (Matlab) containers using the method exportPyWorkspaceVars. Single variables can also be exported to suitable file formats using the method uiSaveFileWithFilter. This finally uses a suitable filter method from an algorithm plugin.

In case of an export based on a plugin filter, the data related to the variable name is obtained from the workspace by invoking the slot getParamsFromWorkspace in the class PythonEngine.

Parameters:
globalNotLocaldefines if the variables are exported from the global (true) or local (false) workspace
varNamesis a list if one or multiple variable names within the workspace. These can be single variable names (direct child of local or global workspace, or a full item name to any subitem as it is used in workspaceWidget)
compatibleParamBaseTypesis a vector of the same size than varNames. A value can be ito::ParamBase::DObjPtr, ito::ParamBase::PointCloudPtr or ito::ParamBase::PolygonMeshPtr to describe the type of the variable or 0 if the variable covers another object. This information is used to set the filters in the file save dialog.
defaultPathis the default path that is pre-set in the file save dialog.
parentis the parent widget of the file save dialog.
Returns:
success of the export as RetVal
See also:
exportPyWorkspaceVars, uiSaveFileWithFilter, getParamsFromWorkspace
RetVal ito::IOHelper::uiImportPyWorkspaceVars ( bool  globalNotLocal,
const IOFilters &  IOfilters,
QString  defaultPath = QString::Null(),
QWidget *  parent = NULL 
) [static]

open a file load dialog and let the user selected a file that is opened and load to a python workspace

This method opens a file load dialog and let the user selected a file. The file filters can be adjusted, such that for instance only file formats that contain data objects, point clouds and/or polygonal meshes are allowed. The selected file is then opened using openGeneralFile. If loading the file using a plugin filter requires further mandatory or optional parameters, a generic parameter input dialog is shown, too.

Parameters:
globalNotLocaldefines if the variables are loaded to the global (true) or local (false) workspace
IOfiltersis an or combination of IOFilter to adjust the supported file formats.
defaultPathis the default path that is pre-set in the file load dialog.
parentis the parent widget of the file load dialog.
Returns:
success of the import as RetVal
See also:
openGeneralFile
RetVal ito::IOHelper::uiOpenFileWithFilter ( const ito::AddInAlgo::FilterDef filter,
const QString &  filename,
QWidget *  parent = NULL,
bool  globalNotLocal = true 
) [static]

open a file using a filter method from an algorithm plugin and shows an import dialog

This method tries to open a given file using a given filter method from an algorithm plugin. If the file could be successfully loaded (to a data object, point cloud or polygonal mesh), it is imported to the global or local python workspace. The given filter method must support one of the filter interfaces ito::AddInAlgo::iReadDataObject, ito::AddInAlgo::iReadPointCloud or ito::AddInAlgo::iReadPolygonMesh.

The load and preview of the file as well as an input mask for the variable name of the imported data is done by a dialog of class DialogOpenFileWithFilter. This dialog let the user also indicate required mandatory or optional parameters for the load. The variable name can also be validated and checked for duplicates.

Parameters:
filteris a pointer to the ito::AddInAlgo::FilterDef structures that indicates the desired plugin filter method.
filenameis the name of the file
parentis the parent widget of the load and preview dialog.
globalNotLocaldefines if the file should be loaded to the global (true) or local python workspace (false)
Returns:
success of the import as RetVal
See also:
putParamsToWorkspace, uiSaveFileWithFilter, DialogOpenFileWithFilter
RetVal ito::IOHelper::uiSaveFileWithFilter ( QSharedPointer< ito::ParamBase > &  value,
const QString &  filename,
QWidget *  parent = NULL 
) [static]

save a file using a filter method from an algorithm plugin and shows an export dialog

This method tries to save a given data object, point cloud or polygonal mesh using a given filter method from an algorithm plugin. The given filter method must support one of the filter interfaces ito::AddInAlgo::iWriteDataObject, ito::AddInAlgo::iWritePointCloud or ito::AddInAlgo::iWritePolygonMesh.

If the export requires further mandatory or optional parameters, an export dialog (class DialogSaveFileWithFilter) is shown.

Parameters:
valueis the export object as shared pointer of ParamBase. Only the types ito::ParamBase::DObjPtr, ito::ParamBase::PointCloudPtr and ito::ParamBase::PolygonMeshPtr are supported.
filenameis the name of the file
parentis the parent widget of the possible export dialog.
Returns:
success of the export as RetVal
See also:
DialogSaveFileWithFilter, uiOpenFileWithFilter

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends