Commit cd153c01 authored by Jan Möbius's avatar Jan Möbius

Add Scripting support to write binary STL files

closes #1
parent 3f881727
......@@ -68,11 +68,20 @@ FileSTLPlugin::FileSTLPlugin() :
loadDefaultButton_(0)
{
}
//-----------------------------------------------------------------------------------------------------
void FileSTLPlugin::initializePlugin() {
emit setSlotDescription("loadObject(QString)",tr("Load Object from stl file."),
QString(tr("Filename")).split(","), QString(tr("Filename to load")).split(","));
emit setSlotDescription("saveObject(int,QString)",tr("Save Object to an stl file."),
QString(tr("objectId,Filename")).split(","), QString(tr("ID of an object to save, Filename")).split(","));
emit setSlotDescription("saveObject(int,QString,bool)",tr("Save Object to an stl file with parameters."),
QString(tr("objectId,Filename,Binary")).split(","), QString(tr("ID of an object to save, Filename,Save as binary?")).split(","));
emit setSlotDescription("saveObject(int,QString,bool,std::streamsize)",tr("Save Object to an stl file with parameters."),
QString(tr("objectId,Filename,Binary,Precision")).split(","), QString(tr("ID of an object to save, Filename,Save as binary?, Number of digits (6 is usually the default)")).split(","));
}
//-----------------------------------------------------------------------------------------------------
......@@ -195,6 +204,7 @@ bool FileSTLPlugin::saveObject(int _id, QString _filename)
emit log(LOGERR, tr("Unable to save ") + _filename );
return false;
}
} else {
emit log(LOGERR, tr("Unable to save (object is not a triangle mesh type)"));
return false;
......@@ -203,6 +213,44 @@ bool FileSTLPlugin::saveObject(int _id, QString _filename)
//-----------------------------------------------------------------------------------------------------
bool FileSTLPlugin::saveObject(int _id, QString _filename, const bool _binary, const std::streamsize _precision ){
BaseObjectData* object;
if ( !PluginFunctions::getObject(_id,object) ) {
emit log(LOGERR, tr("saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
return false;
}
std::string filename = std::string( _filename.toUtf8() );
if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
object->setFromFileName(_filename);
object->setName(object->filename());
TriMeshObject* triObj = dynamic_cast<TriMeshObject* >( object );
OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
if (_binary)
opt += OpenMesh::IO::Options::Binary;
if (OpenMesh::IO::write_mesh(*triObj->mesh(), filename.c_str(), opt, _precision) ) {
emit log(LOGINFO, tr("Saved object to ") + _filename );
return true;
} else {
emit log(LOGERR, tr("Unable to save ") + _filename );
return false;
}
} else {
emit log(LOGERR, tr("Unable to save (object is not a triangle mesh type)"));
return false;
}
}
//-----------------------------------------------------------------------------------------------------
QWidget* FileSTLPlugin::saveOptionsWidget(QString /*_currentFilter*/) {
if (saveOptions_ == 0){
......
......@@ -93,6 +93,9 @@ class FileSTLPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
void deleteObject( int _id );
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
private slots:
void fileOpened( int /*_id*/ ){};
......@@ -131,6 +134,17 @@ class FileSTLPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
bool saveObject(int _id, QString _filename);
/** \brief Scripting function to set binary mode and precision
*
* @param _id Object that should be saved
* @param _filename Filename of the STL file
* @param _binary Binary mode? Defaults to false
* @param _precision Precision of values (Defaults to 6)
* @return Successful write?
*/
bool saveObject(int _id, QString _filename, const bool _binary , const std::streamsize _precision = 6 );
QString version() { return QString("1.0"); };
private :
......
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