54 savePrecisionLabel_(0),
57 saveDefaultButton_(0),
67 emit setSlotDescription(
"loadObject(QString)",tr(
"Load Object from stl file."),
68 QString(tr(
"Filename")).split(
","), QString(tr(
"Filename to load")).split(
","));
69 emit setSlotDescription(
"saveObject(int,QString)",tr(
"Save Object to an stl file."),
70 QString(tr(
"objectId,Filename")).split(
","), QString(tr(
"ID of an object to save, Filename")).split(
","));
71 emit setSlotDescription(
"saveObject(int,QString,bool)",tr(
"Save Object to an stl file with parameters."),
72 QString(tr(
"objectId,Filename,Binary")).split(
","), QString(tr(
"ID of an object to save, Filename,Save as binary?")).split(
","));
73 emit setSlotDescription(
"saveObject(int,QString,bool,std::streamsize)",tr(
"Save Object to an stl file with parameters."),
74 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(
","));
80 return QString( tr(
"Stereolithography files ( *.stl *.stla *.stlb )") );
86 return QString( tr(
"Stereolithography files ( *.stl *.stla *.stlb )") );
107 object->target(
true);
109 object->setFromFileName(_filename);
110 object->setName(object->
filename());
112 std::string filename = std::string( _filename.toUtf8() );
114 object->mesh()->request_face_normals();
116 bool loadNormals( (loadFaceNormal_ && loadFaceNormal_->isChecked()) ||
130 std::cerr <<
"Plugin FileSTL : Read error for stl mesh.\n";
131 emit deleteObject( object->
id() );
137 if (!loadNormals || !opt.face_has_normal())
138 object->
mesh()->update_normals();
140 if (object->
mesh()->has_vertex_normals())
141 object->
mesh()->update_vertex_normals();
142 if (object->
mesh()->has_halfedge_normals())
143 object->
mesh()->update_halfedge_normals();
148 emit openedFile( object->
id() );
153 emit log(
LOGERR,
"Error : Could not create new triangle mesh object.");
160 bool FileSTLPlugin::saveObject(
int _id, QString _filename)
164 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
168 std::string filename = std::string( _filename.toUtf8() );
172 object->setFromFileName(_filename);
173 object->setName(object->
filename());
179 std::streamsize precision = 6;
180 if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
182 if (!OpenFlipper::Options::nogui() && saveBinary_->isChecked())
185 if (!saveBinary_->isChecked())
186 precision = savePrecision_->value();
191 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
194 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
199 emit log(
LOGERR, tr(
"Unable to save (object is not a triangle mesh type)"));
206 bool FileSTLPlugin::saveObject(
int _id, QString _filename,
const bool _binary,
const std::streamsize _precision ){
209 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
213 std::string filename = std::string( _filename.toUtf8() );
217 object->setFromFileName(_filename);
218 object->setName(object->
filename());
228 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
231 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
236 emit log(
LOGERR, tr(
"Unable to save (object is not a triangle mesh type)"));
246 if (saveOptions_ == 0){
248 saveOptions_ =
new QWidget();
249 QVBoxLayout* layout =
new QVBoxLayout();
250 layout->setAlignment(Qt::AlignTop);
252 saveBinary_ =
new QCheckBox(
"Save Binary");
253 layout->addWidget(saveBinary_);
255 savePrecisionLabel_ =
new QLabel(
"Writer Precision");
256 layout->addWidget(savePrecisionLabel_);
258 savePrecision_ =
new QSpinBox();
259 savePrecision_->setMinimum(1);
260 savePrecision_->setMaximum(12);
261 savePrecision_->setValue(6);
262 layout->addWidget(savePrecision_);
264 saveDefaultButton_ =
new QPushButton(
"Make Default");
265 layout->addWidget(saveDefaultButton_);
267 saveOptions_->setLayout(layout);
269 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FileSTL/Save/Binary",
false ).toBool() );
271 connect(saveBinary_, SIGNAL(clicked(
bool)), savePrecision_, SLOT(setDisabled(
bool)));
272 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
283 if (loadOptions_ == 0){
285 loadOptions_ =
new QWidget();
286 QVBoxLayout* layout =
new QVBoxLayout();
287 layout->setAlignment(Qt::AlignTop);
289 loadFaceNormal_ =
new QCheckBox(
"Load Face Normals");
290 layout->addWidget(loadFaceNormal_);
292 loadFaceNormal_->setChecked(
OpenFlipperSettings().value(
"FileSTL/Load/FaceNormal",
true).toBool() );
294 loadDefaultButton_ =
new QPushButton(
"Make Default");
295 layout->addWidget(loadDefaultButton_);
297 loadOptions_->setLayout(layout);
299 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void initializePlugin()
Initialize Plugin.
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
Has (r) / store (w) face normals.
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
bool dataType(DataType _type) const
int loadObject(QString _filename)
Loads Object as triangle mesh.
MeshT * mesh()
return a pointer to the mesh
QWidget * loadOptionsWidget(QString)
QWidget * saveOptionsWidget(QString)
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Type for a MeshObject containing a triangle mesh.
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
QString filename() const
return the filename of the object
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
Set options for reader/writer modules.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
int objectCount()
Get the number of available objects.
#define DATA_TRIANGLE_MESH
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
FileSTLPlugin()
Constructor.