itom
|
This class contains several static methods to load or save various file formats. More...
Classes | |
struct | CharsetEncodingItem |
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(), 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(), 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, QWidget *parent=NULL) |
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 | |
static QString | getAllItomFilesName () |
static QList< CharsetEncodingItem > | getSupportedScriptEncodings () |
return a list of default encodings, that are officially supported by Qt (as well as Python). | |
static CharsetEncodingItem | getDefaultScriptEncoding () |
static CharsetEncodingItem | getEncodingFromAlias (const QString &alias, bool *found=nullptr) |
Private Member Functions | |
~IOHelper () | |
IOHelper (const IOHelper &) | |
Static Private Attributes | |
static QString | allItomFilesName = QObject::tr("Itom Files") |
name of set of all itom files (used in file open dialog or file system dialog) | |
static QList< CharsetEncodingItem > | supportedScriptEncodings |
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.
IOFilter enumeration This enum contains flags to filter out input/output algorithms for various objects
SearchFolder enumeration This enumeration contains values to describe specific directories that are searched for files (e.g. icons)
|
inlineprivate |
private constructor since this class only contains static method and no instance must be created
|
inlineprivate |
private destructor
|
static |
Shortens paths so that menus can display them without becoming too big.
This function is used to shorten paths so they fit into a menu or something comparable.
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.
path | The path that is supposed to be shortened |
pixelLength | The length the path has to have after shortening |
|
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.
filename | is the filename to the idc or mat file |
globalNotLocal | defines 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) |
|
static |
Checks if a file fits to a filter.
This function checks if a file ending of a file fits to a given set of filters.
filename | pass the filename as a QString |
IOfilters | pass the filterset that the filename should be checked against |
|
inlinestatic |
name of file filter that bundles are readable files of itom, usually 'Itom Files'.
|
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
IOfilters | filters that contain the filenendings |
allPatterns | Pointer to QStringList (standard = 0) |
|
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 invocation of the slot unpickleVariables or loadMatlabVariables of the class PythonEngine.
filename | is the filename with a suffix idc or mat (only supported if Scipy is available) |
globalNotLocal | defines if the file is loaded to the global (true) or local (false) workspace |
|
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.
generalFileName | is the file name to load. If the file name is not absolute, it is considered to be relative to the current directory. |
openUnknownsWithExternalApp | is 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 |
showMessages | if true, an error or warning during the execution of this method will be displayed in a message box. |
parent | is the widget this method should be related to. Dialogs or messages are then displayed using this parent. |
errorSlotMemberOfParent | is 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. |
globalNotLocalWorkspace | is 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) |
|
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.
filename | is the filename to the py file |
|
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.
filename | is the filename to the ui file |
parent | is the widget where the slot given by errorSlotMemberOfParent is defined |
errorSlotMemberOfParent | is SLOT(myMethod(QProcess::ProcessError)) description such that errors occurred in the QtDesigner will call the given slot. Else pass NULL. |
|
static |
search an icon file in different locations, open and return it
filename | is the relative or absolute filename of the icon |
searchFolders | is a bitmask that defines the locations that are searched for the filename |
fallbackIcon | let you define an alternative icon that is returned if filename is not found in any location |
|
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.
globalNotLocal | defines 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) |
compatibleParamBaseTypes | is 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. |
defaultPath | is the default path that is pre-set in the file save dialog. |
parent | is the parent widget of the file save dialog. |
|
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.
globalNotLocal | defines if the variables are loaded to the global (true) or local (false) workspace |
IOfilters | is an or combination of IOFilter to adjust the supported file formats. |
defaultPath | is the default path that is pre-set in the file load dialog. |
parent | is the parent widget of the file load dialog. |
|
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.
filter | is a pointer to the ito::AddInAlgo::FilterDef structures that indicates the desired plugin filter method. |
filename | is the name of the file |
parent | is the parent widget of the load and preview dialog. |
globalNotLocal | defines if the file should be loaded to the global (true) or local python workspace (false) |
|
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.
value | is the export object as shared pointer of ParamBase. Only the types ito::ParamBase::DObjPtr, ito::ParamBase::PointCloudPtr and ito::ParamBase::PolygonMeshPtr are supported. |
filename | is the name of the file |
parent | is the parent widget of the possible export dialog. |
|
staticprivate |
the list of all officially supported encodings for Python scripts This will be filled by the first call to IOHelper::getSupportedScriptEncodings