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

Plugin Collections for file, type and postprocessor plugins



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15803 383ad7c9-94d9-4d36-a494-682f7c89f535
parents
include (plugin)
openflipper_plugin ()
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include <QtGui>
#include <QFileInfo>
#include <QSettings>
#include "FileSTL.hh"
#include <iostream>
#include <ACG/GL/GLState.hh>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"
#include <OpenMesh/Core/IO/IOManager.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
/// Constructor
FileSTLPlugin::FileSTLPlugin() :
saveOptions_(0),
loadOptions_(0),
saveBinary_(0),
savePrecisionLabel_(0),
savePrecision_(0),
saveDefaultButton_(0),
loadDefaultButton_(0)
{
}
//-----------------------------------------------------------------------------------------------------
void FileSTLPlugin::initializePlugin() {
}
//-----------------------------------------------------------------------------------------------------
QString FileSTLPlugin::getLoadFilters() {
return QString( tr("Stereolithography files ( *.stl *.stla *.stlb )") );
};
//-----------------------------------------------------------------------------------------------------
QString FileSTLPlugin::getSaveFilters() {
return QString( tr("Stereolithography files ( *.stl *.stla *.stlb )") );
};
//-----------------------------------------------------------------------------------------------------
DataType FileSTLPlugin::supportedType() {
DataType type = DATA_TRIANGLE_MESH;
return type;
}
//-----------------------------------------------------------------------------------------------------
int FileSTLPlugin::loadObject(QString _filename) {
int id = -1;
emit addEmptyObject(DATA_TRIANGLE_MESH, id);
TriMeshObject* object(0);
if(PluginFunctions::getObject( id, object)) {
if (PluginFunctions::objectCount() == 1 )
object->target(true);
object->setFromFileName(_filename);
object->setName(object->filename());
std::string filename = std::string( _filename.toUtf8() );
object->mesh()->request_face_normals();
// load file
bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename );
if (!ok)
{
std::cerr << "Plugin FileSTL : Read error for stl mesh.\n";
emit deleteObject( object->id() );
return -1;
}
object->mesh()->update_normals();
object->update();
object->show();
emit openedFile( object->id() );
// Update viewport
PluginFunctions::viewAll();
return object->id();
} else {
emit log(LOGERR,"Error : Could not create new triangle mesh object.");
return -1;
}
};
//-----------------------------------------------------------------------------------------------------
bool FileSTLPlugin::saveObject(int _id, QString _filename)
{
BaseObjectData* object;
PluginFunctions::getObject(_id,object);
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;
std::streamsize precision = 6;
if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
if (!OpenFlipper::Options::nogui() && saveBinary_->isChecked())
opt += OpenMesh::IO::Options::Binary;
if (!saveBinary_->isChecked())
precision = savePrecision_->value();
}
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){
//generate widget
saveOptions_ = new QWidget();
QVBoxLayout* layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
saveBinary_ = new QCheckBox("Save Binary");
layout->addWidget(saveBinary_);
savePrecisionLabel_ = new QLabel("Writer Precision");
layout->addWidget(savePrecisionLabel_);
savePrecision_ = new QSpinBox();
savePrecision_->setMinimum(1);
savePrecision_->setMaximum(12);
savePrecision_->setValue(6);
layout->addWidget(savePrecision_);
saveDefaultButton_ = new QPushButton("Make Default");
layout->addWidget(saveDefaultButton_);
saveOptions_->setLayout(layout);
saveBinary_->setChecked( OpenFlipperSettings().value( "FileSTL/Save/Binary", false ).toBool() );
connect(saveBinary_, SIGNAL(clicked(bool)), savePrecision_, SLOT(setDisabled(bool)));
connect(saveDefaultButton_, SIGNAL(clicked()), this, SLOT(slotSaveDefault()));
}
return saveOptions_;
}
//-----------------------------------------------------------------------------------------------------
QWidget* FileSTLPlugin::loadOptionsWidget(QString /*_currentFilter*/) {
if (loadOptions_ == 0){
//generate widget
loadOptions_ = new QWidget();
QVBoxLayout* layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
loadDefaultButton_ = new QPushButton("Make Default");
layout->addWidget(loadDefaultButton_);
loadOptions_->setLayout(layout);
connect(loadDefaultButton_, SIGNAL(clicked()), this, SLOT(slotLoadDefault()));
}
return loadOptions_;
}
//-----------------------------------------------------------------------------------------------------
void FileSTLPlugin::slotLoadDefault() {
OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
}
//-----------------------------------------------------------------------------------------------------
void FileSTLPlugin::slotSaveDefault() {
OpenFlipperSettings().setValue( "FileSTL/Save/Binary", saveBinary_->isChecked() );
}
Q_EXPORT_PLUGIN2( filestlplugin , FileSTLPlugin );
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#ifndef FILESTLPLUGIN_HH
#define FILESTLPLUGIN_HH
#include <QObject>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/FileInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/TypeInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
class FileSTLPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface,
LoggingInterface, ScriptInterface
{
Q_OBJECT
Q_INTERFACES(FileInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ScriptInterface)
signals:
void openedFile( int _id );
void addEmptyObject( DataType _type, int& _id);
void load(QString _filename, DataType _type, int& _id);
void save(int _id , QString _filename );
void log(Logtype _type, QString _message);
void log(QString _message);
void updateView();
void deleteObject( int _id );
private slots:
void fileOpened( int /*_id*/ ){};
void noguiSupported( ) {} ;
void initializePlugin();
/// Slot called when user wants to save the given Load options as default
void slotLoadDefault();
/// Slot called when user wants to save the given Save options as default
void slotSaveDefault();
public :
FileSTLPlugin();
~FileSTLPlugin() {};
QString name() { return (QString("FileSTL")); };
QString description( ) { return (QString(tr("Load/Save STL-Files"))); };
DataType supportedType();
QString getSaveFilters();
QString getLoadFilters();
QWidget* saveOptionsWidget(QString /*_currentFilter*/);
QWidget* loadOptionsWidget(QString /*_currentFilter*/);
public slots:
/// Loads Object as triangle mesh
int loadObject(QString _filename);
bool saveObject(int _id, QString _filename);
QString version() { return QString("1.0"); };
private :
//Option Widgets
QWidget* saveOptions_;
QWidget* loadOptions_;
QCheckBox* saveBinary_;
QLabel* savePrecisionLabel_;
QSpinBox* savePrecision_;
QPushButton* saveDefaultButton_;
QPushButton* loadDefaultButton_;
};
#endif //FILESTLPLUGIN_HH
# Include Testing package
if(BUILD_TESTING)
include( ${CMAKE_SOURCE_DIR}/tests/testGenerators.cmake )
# ========================================================================
# ========================================================================
# Tests
# ========================================================================
# ========================================================================
run_single_object_file_mesh_test("filestl" "" "fileMeshTest.ofs" "Plugin-FileSTL")
endif()
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