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() ...@@ -94,6 +94,11 @@ void MeshConvertPlugin::pluginsInitialized()
// Integrate the new toolbar into OpenFlipper // Integrate the new toolbar into OpenFlipper
emit addToolbar( toolbar ); 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() MeshConvertPlugin::MeshConvertPlugin()
...@@ -106,18 +111,24 @@ MeshConvertPlugin::~MeshConvertPlugin() ...@@ -106,18 +111,24 @@ MeshConvertPlugin::~MeshConvertPlugin()
} }
void MeshConvertPlugin::convert(QAction* _action) int MeshConvertPlugin::convert(int _id, bool _toTriMesh)
{ {
std::vector<int> _ids; int newID = -1;
if(! PluginFunctions::getTargetIdentifiers( _ids ))
return;
BaseObject* obj;
PolyMesh* p; PolyMesh* p;
TriMesh* t; TriMesh* t;
for(std::vector<int>::iterator id = _ids.begin(); id != _ids.end(); ++id) if(_toTriMesh && PluginFunctions::getMesh(_id,p))
{ {
if((_action == bidirectionalConversion || _action == polyConversion) && TriMesh converted = static_cast<TriMesh>(*p);
PluginFunctions::getMesh(*id,t)) emit addEmptyObject(DATA_TRIANGLE_MESH, newID);
if(PluginFunctions::getMesh(newID,t))
{
*t = converted;
emit updatedObject(newID);
}
}
else
{
if( PluginFunctions::getMesh(_id,t))
{ {
PolyMesh converted = static_cast<PolyMesh>(*t); PolyMesh converted = static_cast<PolyMesh>(*t);
int newID = -1; int newID = -1;
...@@ -128,17 +139,24 @@ void MeshConvertPlugin::convert(QAction* _action) ...@@ -128,17 +139,24 @@ void MeshConvertPlugin::convert(QAction* _action)
emit updatedObject(newID); 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)
{
if((_action == bidirectionalConversion || _action == polyConversion))
{
convert(*id,false);
}
if((_action == bidirectionalConversion || _action == triConversion))
{ {
TriMesh converted = static_cast<TriMesh>(*p); convert(*id,true);
int newID = -1;
emit addEmptyObject(DATA_TRIANGLE_MESH, newID);
if(PluginFunctions::getMesh(newID,t))
{
*t = converted;
emit updatedObject(newID);
}
} }
} }
} }
......
...@@ -53,10 +53,9 @@ ...@@ -53,10 +53,9 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh> #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh> #include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh> #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
//class QAction; class MeshConvertPlugin: public QObject, BaseInterface, LoggingInterface, LoadSaveInterface, ScriptInterface, ToolbarInterface {
class MeshConvertPlugin: public QObject, BaseInterface, LoggingInterface, LoadSaveInterface, ToolbarInterface {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BaseInterface) Q_INTERFACES(BaseInterface)
Q_INTERFACES(LoggingInterface) Q_INTERFACES(LoggingInterface)
...@@ -83,6 +82,10 @@ signals: ...@@ -83,6 +82,10 @@ signals:
// BaseInterface // BaseInterface
void updatedObject(int _objectId); void updatedObject(int _objectId);
// ScriptInterface
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
public: public:
MeshConvertPlugin(); MeshConvertPlugin();
~MeshConvertPlugin(); ~MeshConvertPlugin();
...@@ -108,8 +111,19 @@ private: ...@@ -108,8 +111,19 @@ private:
public slots: public slots:
/**
* @brief convert Converts trimesh to poly and vice versa depending on the Action that was called.
*/
void convert(QAction*); 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"); }; 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