Developer Documentation

File Interface

# Functionality

This interface class has to be fully implemented. When you want to support save and load for an object type you have to implement all functions in this class in a file plugin. The plugin has to be named Plugin-File<FileExtension>. The plugins are loaded directly after the Type Plugins.

OpenFlipper manages loading and saving of files from the core.

# Load/Save filters and Type Support

In these functions you have to return filters for your supported type. Use the standard format of Qt and return your filters within the functions FileInterface::getLoadFilters() and FileInterface::getSaveFilters(). OpenFlipper will decide based on the filters, if your plugin is used to handle a load or save request. Additionally you have to define, which DataTypes your plugin supports via FileInterface::supportedType().

// File types you support when loading files
QString ExamplePlugin::getLoadFilters() {
return QString( tr("Your FileType ( *.ext )") );
}
// File types you support when saving files
QString ExamplePlugin::getSaveFilters() {
return QString( tr("Your FileType ( *.ext )") );
}
// Data types you support in your plugin
DataType ExamplePlugin::supportedType() {
DataType type = DATA_POLY_MESH | DATA_TRIANGLE_MESH | DATA_GROUP;
return type;
}

# Widgets

When an object is loaded or saved via your file plugin, you can present an additional dialog, used to control your reader/writer. You have to implement the following functions. If you don't need such a widget, just return a 0.

// In your plugin initialization
void ExamplePlugin::pluginsInitialized() {
// Global variable:
// QWidget* saveOptionsWidget_;
// Create widget
saveOptionsWidget_ = new QWidget(0);
// Setup widget afterwards
// Global variable:
// QWidget* loadOptionsWidget_;
// Create widget
loadOptionsWidget_ = new QWidget(0);
// Setup widget afterwards
}
// Return your widget for save options
QWidget* ExamplePlugin::saveOptionsWidget(QString _currentFilter) {
// Modify widget based on the filter
// ...
// Return widget
return saveOptionsWidget_;
}
// Return your widget for load options
QWidget* ExamplePlugin::loadOptionsWidget(QString _currentFilter) {
// Modify widget based on the filter
// ...
// Return widget
return loadOptionsWidget_;
}

# Loading Files

The FileInterface defines two functions for loading files. The first one ( FileInterface::loadObject(QString _filename) ) has to be implemented. It has to load the data from the given file. The return value of this function has to be the id of the new object. Additionally you have to

emit FileInterface::openedFile( int _id );

with the id of every object you loaded from the file.

If the file contains multiple objects, create a GroupObject and add all loaded objects to that group. Than return the id of the group here. Don't forget the FileInterface::openedFile() signal for every newly loaded object from the file.

One function that can be implemented is FileInterface::loadObject(QString _filename, DataType _type). This function gets a DataType along with the filename. This can be used to force a specific DataType when loading objects. E.g. A plugin loading obj files which handles triangle and polygonal meshes which can than be forced to triangulate every input data.

# Saving Files

The FileInterface defines two functions for loading files. The first one ( FileInterface::saveObject(int _id, QString _filename) ) has to be implemented. It has to save the object with the given id to the file specified by the filename. The return value of this function has to be true if it succeeded, otherwise false. OpenFlipper will choose your plugin to save the data if two prerequisites are fulfilled. Your FileInterface::supportedTypes() has to support the DataType of the object and your save filters have to contain the extension of the file to use. These checks are done within OpenFlipper such that you only get information that can be handled by the plugin.

Additionally there is a function FileInterface::saveObjects(IdList _ids, QString _filename) which does the same as the above but saves a set of objects to a file.

# Usage

To use the FileInterface:

- include FileInterface.hh in your plugins header file
- derive your plugin from the class FileInterface
- add Q_INTERFACES(FileInterface) to your plugin class
- And implement the required slots and functions

TODO: Deprecated here? In TypeInterface? virtual int addEmpty() { return -1; };