Commit e03a75e0 authored by Martin Schultz's avatar Martin Schultz

added scripting interface to MeshConversion Plugin

parent c8fd7495
......@@ -94,6 +94,11 @@ void MeshConvertPlugin::pluginsInitialized()
// Integrate the new toolbar into OpenFlipper
emit addToolbar( toolbar );
//populate scripting function
emit setSlotDescription("convert(int,bool)", "Convert a mesh to PolyMesh or to TriMesh. returns the ID of the new mesh or -1 in case of error. The old mesh remains unchanged.",
QString("object_id,toTriMesh").split(","),
QString(" id of an object to convert, flag to convert to a TriMesh, if not set creates a new PolyMesh").split(","));
}
MeshConvertPlugin::MeshConvertPlugin()
......@@ -106,18 +111,24 @@ MeshConvertPlugin::~MeshConvertPlugin()
}
void MeshConvertPlugin::convert(QAction* _action)
int MeshConvertPlugin::convert(int _id, bool _toTriMesh)
{
std::vector<int> _ids;
if(! PluginFunctions::getTargetIdentifiers( _ids ))
return;
BaseObject* obj;
int newID = -1;
PolyMesh* p;
TriMesh* t;
for(std::vector<int>::iterator id = _ids.begin(); id != _ids.end(); ++id)
if(_toTriMesh && PluginFunctions::getMesh(_id,p))
{
TriMesh converted = static_cast<TriMesh>(*p);
emit addEmptyObject(DATA_TRIANGLE_MESH, newID);
if(PluginFunctions::getMesh(newID,t))
{
*t = converted;
emit updatedObject(newID);
}
}
else
{
if((_action == bidirectionalConversion || _action == polyConversion) &&
PluginFunctions::getMesh(*id,t))
if( PluginFunctions::getMesh(_id,t))
{
PolyMesh converted = static_cast<PolyMesh>(*t);
int newID = -1;
......@@ -128,17 +139,24 @@ void MeshConvertPlugin::convert(QAction* _action)
emit updatedObject(newID);
}
}
if((_action == bidirectionalConversion || _action == triConversion) &&
PluginFunctions::getMesh(*id,p))
}
return newID;
}
void MeshConvertPlugin::convert(QAction* _action)
{
std::vector<int> _ids;
if(! PluginFunctions::getTargetIdentifiers( _ids ))
return;
for(std::vector<int>::iterator id = _ids.begin(); id != _ids.end(); ++id)
{
TriMesh converted = static_cast<TriMesh>(*p);
int newID = -1;
emit addEmptyObject(DATA_TRIANGLE_MESH, newID);
if(PluginFunctions::getMesh(newID,t))
if((_action == bidirectionalConversion || _action == polyConversion))
{
*t = converted;
emit updatedObject(newID);
convert(*id,false);
}
if((_action == bidirectionalConversion || _action == triConversion))
{
convert(*id,true);
}
}
}
......
......@@ -53,10 +53,9 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
//class QAction;
class MeshConvertPlugin: public QObject, BaseInterface, LoggingInterface, LoadSaveInterface, ToolbarInterface {
class MeshConvertPlugin: public QObject, BaseInterface, LoggingInterface, LoadSaveInterface, ScriptInterface, ToolbarInterface {
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(LoggingInterface)
......@@ -83,6 +82,10 @@ signals:
// BaseInterface
void updatedObject(int _objectId);
// ScriptInterface
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
public:
MeshConvertPlugin();
~MeshConvertPlugin();
......@@ -108,8 +111,19 @@ private:
public slots:
/**
* @brief convert Converts trimesh to poly and vice versa depending on the Action that was called.
*/
void convert(QAction*);
/**
* @brief convert Convert a mesh to PolyMesh or to TriMesh. The old mesh remains unchanged.
* @param _id Object_ID to determine which object shall be converted.
* @param _toTriMesh Flag to indicate conversion to TriMesh or Polymesh if set to false.
* @return the ID of the new mesh or -1 in case of error.
*/
int convert(int _id, bool _toTriMesh);
QString version() { return QString("1.0"); };
};
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