diff --git a/MeshConvert.cc b/MeshConvert.cc index e0b825f946440e54c652185b9c34fafd24228bfd..1f47f28d74dba8c9284193d74624910ec64f52a3 100644 --- a/MeshConvert.cc +++ b/MeshConvert.cc @@ -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 _ids; - if(! PluginFunctions::getTargetIdentifiers( _ids )) - return; - BaseObject* obj; + int newID = -1; PolyMesh* p; TriMesh* t; - for(std::vector::iterator id = _ids.begin(); id != _ids.end(); ++id) + if(_toTriMesh && PluginFunctions::getMesh(_id,p)) { - if((_action == bidirectionalConversion || _action == polyConversion) && - PluginFunctions::getMesh(*id,t)) + TriMesh converted = static_cast(*p); + 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(*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 _ids; + if(! PluginFunctions::getTargetIdentifiers( _ids )) + return; + for(std::vector::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(*p); - int newID = -1; - emit addEmptyObject(DATA_TRIANGLE_MESH, newID); - if(PluginFunctions::getMesh(newID,t)) - { - *t = converted; - emit updatedObject(newID); - } + convert(*id,true); } } } diff --git a/MeshConvert.hh b/MeshConvert.hh index 6c5bd14cbe03c8fdbbde1071084f1d69903d2baf..13347b8364e4b958a7ef453bc71b5ab579d57dc7 100644 --- a/MeshConvert.hh +++ b/MeshConvert.hh @@ -53,10 +53,9 @@ #include #include #include +#include -//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"); }; };