Replace IO API to be able to load/save several items at a time

This commit is contained in:
Maxime Gimeno 2019-05-13 16:11:15 +02:00
parent 04c5313a1c
commit 56c99d8a23
18 changed files with 565 additions and 280 deletions

View File

@ -41,7 +41,7 @@
#include <QTime> #include <QTime>
#include <QWidgetAction> #include <QWidgetAction>
#include <QJsonArray> #include <QJsonArray>
#include <QSequentialIterable>
#ifdef QT_SCRIPT_LIB #ifdef QT_SCRIPT_LIB
# include <QScriptValue> # include <QScriptValue>
# ifdef QT_SCRIPTTOOLS_LIB # ifdef QT_SCRIPTTOOLS_LIB
@ -998,20 +998,33 @@ void MainWindow::reloadItem() {
CGAL::Three::Polyhedron_demo_io_plugin_interface* fileloader = findLoader(loader_name); CGAL::Three::Polyhedron_demo_io_plugin_interface* fileloader = findLoader(loader_name);
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
bool ok;
CGAL::Three::Scene_item* new_item = loadItem(fileinfo, fileloader); QList<Scene_item*> new_items = loadItem(fileinfo, fileloader, ok, false);
if(!new_item) if(!ok)
return; return;
new_item->setName(item->name()); QVariant varian = item->property("load_mates");
new_item->setColor(item->color()); if (!varian.canConvert<QVariantList>())
new_item->setRenderingMode(item->renderingMode()); qDebug()<<"Well, that's gonna be a problem !";
new_item->setVisible(item->visible()); QSequentialIterable iterable = varian.value<QSequentialIterable>();
Scene_item_with_properties *property_item = dynamic_cast<Scene_item_with_properties*>(new_item); // Can use foreach:
scene->replaceItem(scene->item_id(item), new_item, true); int mate_id = 0;
if(property_item) Q_FOREACH(const QVariant &v, iterable)
property_item->copyProperties(item); {
new_item->invalidateOpenGLBuffers(); Scene_item* mate = v.value<Scene_item*>();
item->deleteLater(); Scene_item* new_item = new_items[mate_id];
if(!new_item)
qDebug()<<"That too, is gonna be a problem...";
new_item->setName(mate->name());
new_item->setColor(mate->color());
new_item->setRenderingMode(mate->renderingMode());
new_item->setVisible(mate->visible());
Scene_item_with_properties *property_item = dynamic_cast<Scene_item_with_properties*>(new_item);
scene->replaceItem(scene->item_id(mate), new_item, true);
if(property_item)
property_item->copyProperties(mate);
new_item->invalidateOpenGLBuffers();
mate->deleteLater();
}
} }
} }
@ -1105,7 +1118,7 @@ void MainWindow::open(QString filename)
// collect all io_plugins and offer them to load if the file extension match one name filter // collect all io_plugins and offer them to load if the file extension match one name filter
// also collect all available plugin in case of a no extension match // also collect all available plugin in case of a no extension match
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) { Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) {
if ( !io_plugin->canLoad() ) continue; if ( !io_plugin->canLoad(fileinfo) ) continue;
all_items << io_plugin->name(); all_items << io_plugin->name();
if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) ) if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) )
{ {
@ -1148,71 +1161,70 @@ void MainWindow::open(QString filename)
settings.setValue("OFF open directory", settings.setValue("OFF open directory",
fileinfo.absoluteDir().absolutePath()); fileinfo.absoluteDir().absolutePath());
CGAL::Three::Scene_item* scene_item = loadItem(fileinfo, findLoader(load_pair.first)); loadItem(fileinfo, findLoader(load_pair.first), ok);
if(!scene_item) if(!ok)
return; return;
this->addToRecentFiles(fileinfo.absoluteFilePath()); this->addToRecentFiles(fileinfo.absoluteFilePath());
selectSceneItem(scene->addItem(scene_item));
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(scene_item);
if(group)
scene->redraw_model();
updateViewersBboxes(true); updateViewersBboxes(true);
} }
bool MainWindow::open(QString filename, QString loader_name) { bool MainWindow::open(QString filename, QString loader_name) {
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
boost::optional<CGAL::Three::Scene_item*> item_opt; boost::optional<bool> item_opt;
CGAL::Three::Scene_item* item = 0; CGAL::Three::Scene_item* item = 0;
try { try {
item_opt = wrap_a_call_to_cpp item_opt = wrap_a_call_to_cpp
([this, fileinfo, loader_name]() ([this, fileinfo, loader_name]()
{ {
return loadItem(fileinfo, findLoader(loader_name)); bool ok;
loadItem(fileinfo, findLoader(loader_name), ok);
return ok;
}, },
this, __FILE__, __LINE__ this, __FILE__, __LINE__
); );
if(!item_opt) return false; if(!item_opt) return false;
else item = *item_opt; //else item = *item_opt;
} }
catch(std::logic_error& e) { catch(std::logic_error& e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
return false; return false;
} }
selectSceneItem(scene->addItem(item));
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
scene->redraw_model();
return true; return true;
} }
CGAL::Three::Scene_item* MainWindow::loadItem(QFileInfo fileinfo, CGAL::Three::Polyhedron_demo_io_plugin_interface* loader) { QList<Scene_item*> MainWindow::loadItem(QFileInfo fileinfo,
CGAL::Three::Scene_item* item = NULL; CGAL::Three::Polyhedron_demo_io_plugin_interface* loader,
bool &ok,
bool add_to_scene) {
if(!fileinfo.isFile() || !fileinfo.isReadable()) { if(!fileinfo.isFile() || !fileinfo.isReadable()) {
QMessageBox::warning(this, tr("Error"), QMessageBox::warning(this, tr("Error"),
QString("File %1 is not a readable file.") QString("File %1 is not a readable file.")
.arg(fileinfo.absoluteFilePath())); .arg(fileinfo.absoluteFilePath()));
} }
QApplication::setOverrideCursor(Qt::WaitCursor); CGAL::Three::Three::CursorScopeGuard guard(QCursor(Qt::WaitCursor));
QList<Scene_item*> result = loader->load(fileinfo, ok, add_to_scene);
item = loader->load(fileinfo); selectSceneItem(scene->item_id(result.back()));
QApplication::restoreOverrideCursor(); if(!ok)
if(!item) { {
QApplication::restoreOverrideCursor();
QMessageBox::warning(this, tr("Error"), QMessageBox::warning(this, tr("Error"),
QString("Could not load item from file %1 using plugin %2") QString("Could not load item from file %1 using plugin %2")
.arg(fileinfo.absoluteFilePath()).arg(loader->name())); .arg(fileinfo.absoluteFilePath()).arg(loader->name()));
return 0; return QList<Scene_item*>();
} }
for(Scene_item* item : result)
item->setProperty("source filename", fileinfo.absoluteFilePath()); {
item->setProperty("loader_name", loader->name()); CGAL::Three::Scene_group_item* group =
return item; qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
scene->redraw_model();
item->setProperty("source filename", fileinfo.absoluteFilePath());
item->setProperty("loader_name", loader->name());
item->setProperty("load_mates",QVariant::fromValue(result));
}
return result;
} }
@ -1831,7 +1843,7 @@ void MainWindow::on_actionLoad_triggered()
typedef QMap<QString, CGAL::Three::Polyhedron_demo_io_plugin_interface*> FilterPluginMap; typedef QMap<QString, CGAL::Three::Polyhedron_demo_io_plugin_interface*> FilterPluginMap;
FilterPluginMap filterPluginMap; FilterPluginMap filterPluginMap;
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
QStringList split_filters = plugin->loadNameFilters().split(";;"); QStringList split_filters = plugin->loadNameFilters().split(";;");
Q_FOREACH(const QString& filter, split_filters) { Q_FOREACH(const QString& filter, split_filters) {
FilterPluginMap::iterator it = filterPluginMap.find(filter); FilterPluginMap::iterator it = filterPluginMap.find(filter);
@ -1881,14 +1893,21 @@ void MainWindow::on_actionLoad_triggered()
CGAL::Three::Scene_item* item = NULL; CGAL::Three::Scene_item* item = NULL;
if(selectedPlugin) { if(selectedPlugin) {
QFileInfo info(filename); QFileInfo info(filename);
item = loadItem(info, selectedPlugin); bool ok;
item->setColor(colors_[++nb_item]); QList<Scene_item*> result = loadItem(info, selectedPlugin, ok);
Scene::Item_id index = scene->addItem(item); if(!ok)
selectSceneItem(index); continue;
CGAL::Three::Scene_group_item* group = for(Scene_item* item : result)
qobject_cast<CGAL::Three::Scene_group_item*>(item); {
if(group) ++nb_item;
scene->redraw_model(); item->setColor(colors_[nb_item]);
Scene::Item_id index = scene->addItem(item);
selectSceneItem(index);
CGAL::Three::Scene_group_item* group =
qobject_cast<CGAL::Three::Scene_group_item*>(item);
if(group)
scene->redraw_model();
}
this->addToRecentFiles(filename); this->addToRecentFiles(filename);
} else { } else {
int scene_size = scene->numberOfEntries(); int scene_size = scene->numberOfEntries();
@ -1901,15 +1920,19 @@ void MainWindow::on_actionLoad_triggered()
void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionSaveAs_triggered()
{ {
Scene_item* item = NULL; QList<Scene_item*> to_save;
for(Scene::Item_id id : scene->selectionIndices())
Q_FOREACH(Scene::Item_id id, scene->selectionIndices())
{ {
item = scene->item(id); Scene_item* item = scene->item(id);
to_save.append(item);
}
while(!to_save.empty())
{
Scene_item* item = to_save.front();
QVector<CGAL::Three::Polyhedron_demo_io_plugin_interface*> canSavePlugins; QVector<CGAL::Three::Polyhedron_demo_io_plugin_interface*> canSavePlugins;
QStringList filters; QStringList filters;
QString sf; QString sf;
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
if(plugin->canSave(item)) { if(plugin->canSave(item)) {
canSavePlugins << plugin; canSavePlugins << plugin;
filters += plugin->saveNameFilters(); filters += plugin->saveNameFilters();
@ -1925,7 +1948,7 @@ void MainWindow::on_actionSaveAs_triggered()
tr("Cannot save"), tr("Cannot save"),
tr("The selected object %1 cannot be saved.") tr("The selected object %1 cannot be saved.")
.arg(item->name())); .arg(item->name()));
return; return;
} }
Q_FOREACH(QString string, filters) Q_FOREACH(QString string, filters)
{ {
@ -2016,18 +2039,18 @@ void MainWindow::on_actionSaveAs_triggered()
} }
for(auto v : CGAL::QGLViewer::QGLViewerPool()) for(auto v : CGAL::QGLViewer::QGLViewerPool())
v->update(); v->update();
save(filename, item); save(filename, to_save);
} }
} }
void MainWindow::save(QString filename, CGAL::Three::Scene_item* item) { void MainWindow::save(QString filename, QList<CGAL::Three::Scene_item*>& to_save) {
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
bool saved = false; bool saved = false;
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin, io_plugins) { for(CGAL::Three::Polyhedron_demo_io_plugin_interface* plugin : io_plugins) {
if( plugin->canSave(item) && if( plugin->canSave(to_save.front()) &&
file_matches_filter(plugin->saveNameFilters(),filename.toLower()) ) file_matches_filter(plugin->saveNameFilters(),filename.toLower()) )
{ {
if(plugin->save(item, fileinfo)) if(plugin->save(fileinfo, to_save))
{ {
saved = true; saved = true;
break; break;
@ -2038,7 +2061,7 @@ void MainWindow::save(QString filename, CGAL::Three::Scene_item* item) {
QMessageBox::warning(this, QMessageBox::warning(this,
tr("Cannot save"), tr("Cannot save"),
tr("The selected object %1 was not saved. (Maybe a wrong extension ?)") tr("The selected object %1 was not saved. (Maybe a wrong extension ?)")
.arg(item->name())); .arg(to_save.front()->name()));
} }
void MainWindow::on_actionSaveSnapshot_triggered() void MainWindow::on_actionSaveSnapshot_triggered()
@ -3131,14 +3154,16 @@ void MainWindow::on_action_Save_triggered()
if(QMessageBox::question(this, "Save", "Are you sure you want to override these files ?") if(QMessageBox::question(this, "Save", "Are you sure you want to override these files ?")
== QMessageBox::No) == QMessageBox::No)
return; return;
Scene_item* item = nullptr; QList<Scene_item*> to_save;
Q_FOREACH(Scene::Item_id id, scene->selectionIndices())
for(Scene::Item_id id : scene->selectionIndices())
{ {
item = scene->item(id); Scene_item* item = scene->item(id);
if(!item->property("source filename").toString().isEmpty()) if(!item->property("source filename").toString().isEmpty())
{ {
QString filename = item->property("source filename").toString(); QString filename = item->property("source filename").toString();
save(filename, item); to_save.append(item);
save(filename, to_save);
} }
} }
} }

View File

@ -87,11 +87,14 @@ public:
@returns the IO plugin associated with `loader_name`*/ @returns the IO plugin associated with `loader_name`*/
CGAL::Three::Polyhedron_demo_io_plugin_interface* findLoader(const QString& loader_name) const; CGAL::Three::Polyhedron_demo_io_plugin_interface* findLoader(const QString& loader_name) const;
/*! \brief Loads an item with a given loader. /*! \brief Loads on or more item with a given loader.
* *
* throws `std::logic_error` if loading does not succeed or * throws `std::logic_error` if loading does not succeed or
* `std::invalid_argument` if `fileinfo` specifies an invalid file*/ * `std::invalid_argument` if `fileinfo` specifies an invalid file*/
CGAL::Three::Scene_item* loadItem(QFileInfo fileinfo, CGAL::Three::Polyhedron_demo_io_plugin_interface*); QList<CGAL::Three::Scene_item *> loadItem(QFileInfo fileinfo,
CGAL::Three::Polyhedron_demo_io_plugin_interface*,
bool& ok,
bool add_to_scene=true);
void computeViewerBBox(CGAL::qglviewer::Vec &min, CGAL::qglviewer::Vec &max); void computeViewerBBox(CGAL::qglviewer::Vec &min, CGAL::qglviewer::Vec &max);
void updateViewerBbox(Viewer* vi, bool recenter, CGAL::qglviewer::Vec min, void updateViewerBbox(Viewer* vi, bool recenter, CGAL::qglviewer::Vec min,
CGAL::qglviewer::Vec max); CGAL::qglviewer::Vec max);
@ -346,7 +349,7 @@ protected Q_SLOTS:
//!Opens a dialog to save selected item if able. //!Opens a dialog to save selected item if able.
void on_actionSaveAs_triggered(); void on_actionSaveAs_triggered();
//!Calls the function save of the current plugin if able. //!Calls the function save of the current plugin if able.
void save(QString filename, CGAL::Three::Scene_item* item); void save(QString filename, QList<CGAL::Three::Scene_item*>& to_save);
//!Calls the function saveSnapShot of the viewer. //!Calls the function saveSnapShot of the viewer.
void on_actionSaveSnapshot_triggered(); void on_actionSaveSnapshot_triggered();
//!Opens a Dialog to choose a color and make it the background color. //!Opens a Dialog to choose a color and make it the background color.

View File

@ -40,30 +40,31 @@ public:
bool applicable(QAction*) const { return false;} bool applicable(QAction*) const { return false;}
QString nameFilters() const; QString nameFilters() const;
QString name() const { return "gocad_plugin"; } QString name() const { return "gocad_plugin"; }
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& );
}; };
QString Polyhedron_demo_gocad_plugin::nameFilters() const { QString Polyhedron_demo_gocad_plugin::nameFilters() const {
return "GOCAD files (*.ts)"; return "GOCAD files (*.ts)";
} }
bool Polyhedron_demo_gocad_plugin::canLoad() const { bool Polyhedron_demo_gocad_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*>
Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) { Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
// Open file // Open file
std::ifstream in(fileinfo.filePath().toUtf8()); std::ifstream in(fileinfo.filePath().toUtf8());
if(!in) { if(!in) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
@ -74,7 +75,10 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
SMesh& P = * const_cast<SMesh*>(item->polyhedron()); SMesh& P = * const_cast<SMesh*>(item->polyhedron());
@ -82,7 +86,8 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
if(! read_gocad(P, in, name, color)){ if(! read_gocad(P, in, name, color)){
std::cerr << "Error: Invalid polyhedron" << std::endl; std::cerr << "Error: Invalid polyhedron" << std::endl;
delete item; delete item;
return 0; ok = false;
return QList<Scene_item*>();
} }
t.stop(); t.stop();
@ -98,7 +103,10 @@ Polyhedron_demo_gocad_plugin::load(QFileInfo fileinfo) {
item->setColor(qcolor); item->setColor(qcolor);
} }
item->invalidateOpenGLBuffers(); item->invalidateOpenGLBuffers();
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_gocad_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_gocad_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -107,8 +115,10 @@ bool Polyhedron_demo_gocad_plugin::canSave(const CGAL::Three::Scene_item* item)
return qobject_cast<const Scene_surface_mesh_item*>(item); return qobject_cast<const Scene_surface_mesh_item*>(item);
} }
bool Polyhedron_demo_gocad_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_gocad_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// This plugin supports polyhedrons // This plugin supports polyhedrons
const Scene_surface_mesh_item* sm_item = const Scene_surface_mesh_item* sm_item =
qobject_cast<const Scene_surface_mesh_item*>(item); qobject_cast<const Scene_surface_mesh_item*>(item);
@ -120,6 +130,7 @@ bool Polyhedron_demo_gocad_plugin::save(const CGAL::Three::Scene_item* item, QFi
out.precision (std::numeric_limits<double>::digits10 + 2); out.precision (std::numeric_limits<double>::digits10 + 2);
SMesh* poly = const_cast<SMesh*>(sm_item->polyhedron()); SMesh* poly = const_cast<SMesh*>(sm_item->polyhedron());
write_gocad(*poly, out, qPrintable(fileinfo.baseName())); write_gocad(*poly, out, qPrintable(fileinfo.baseName()));
items.pop_front();
return true; return true;
} }

View File

@ -1,8 +1,9 @@
#include "Scene_points_with_normal_item.h" #include "Scene_points_with_normal_item.h"
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h> #include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
#include <CGAL/Three/Three.h>
#include <CGAL/Three/Scene_item.h>
#include <fstream> #include <fstream>
using namespace CGAL::Three;
class Polyhedron_demo_las_plugin : class Polyhedron_demo_las_plugin :
public QObject, public QObject,
public CGAL::Three::Polyhedron_demo_io_plugin_interface public CGAL::Three::Polyhedron_demo_io_plugin_interface
@ -14,19 +15,19 @@ class Polyhedron_demo_las_plugin :
public: public:
QString name() const { return "las_plugin"; } QString name() const { return "las_plugin"; }
QString nameFilters() const { return "LAS files (*.las);;Compressed LAS files (*.laz)"; } QString nameFilters() const { return "LAS files (*.las);;Compressed LAS files (*.laz)"; }
bool canLoad() const; bool canLoad(QFileInfo fileinfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
}; };
bool Polyhedron_demo_las_plugin::canLoad() const { bool Polyhedron_demo_las_plugin::canLoad(QFileInfo fileinfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*> Polyhedron_demo_las_plugin::
Polyhedron_demo_las_plugin::load(QFileInfo fileinfo) { load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary); std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary);
if(!in) if(!in)
@ -37,11 +38,15 @@ Polyhedron_demo_las_plugin::load(QFileInfo fileinfo) {
if(!item->read_las_point_set(in)) if(!item->read_las_point_set(in))
{ {
delete item; delete item;
return 0; ok = false;
return QList<Scene_item*>();
} }
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_las_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_las_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -49,8 +54,9 @@ bool Polyhedron_demo_las_plugin::canSave(const CGAL::Three::Scene_item* item)
return qobject_cast<const Scene_points_with_normal_item*>(item); return qobject_cast<const Scene_points_with_normal_item*>(item);
} }
bool Polyhedron_demo_las_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_las_plugin::save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// Check extension (quietly) // Check extension (quietly)
std::string extension = fileinfo.suffix().toUtf8().data(); std::string extension = fileinfo.suffix().toUtf8().data();
if (extension != "las" && extension != "LAS") if (extension != "las" && extension != "LAS")
@ -63,6 +69,7 @@ bool Polyhedron_demo_las_plugin::save(const CGAL::Three::Scene_item* item, QFile
return false; return false;
std::ofstream out(fileinfo.filePath().toUtf8().data()); std::ofstream out(fileinfo.filePath().toUtf8().data());
items.pop_front();
return point_set_item->write_las_point_set(out); return point_set_item->write_las_point_set(out);
} }

View File

@ -17,32 +17,37 @@ class Polyhedron_demo_io_nef_plugin :
public: public:
QString nameFilters() const; QString nameFilters() const;
QString name() const { return "io_nef_plugin"; } QString name() const { return "io_nef_plugin"; }
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items);
}; };
QString Polyhedron_demo_io_nef_plugin::nameFilters() const { QString Polyhedron_demo_io_nef_plugin::nameFilters() const {
return "nef files (*.nef3)"; return "nef files (*.nef3)";
} }
bool Polyhedron_demo_io_nef_plugin::canLoad() const { bool Polyhedron_demo_io_nef_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*> Polyhedron_demo_io_nef_plugin::
Polyhedron_demo_io_nef_plugin::load(QFileInfo fileinfo) { load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
//do not try file with extension different from nef3 //do not try file with extension different from nef3
if (fileinfo.suffix() != "nef3") return 0; if (fileinfo.suffix() != "nef3")
{
ok = false;
return QList<Scene_item*>();
}
// Open file // Open file
std::ifstream in(fileinfo.filePath().toUtf8()); std::ifstream in(fileinfo.filePath().toUtf8());
if(!in) { if(!in) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
// Try to read .nef3 in a polyhedron // Try to read .nef3 in a polyhedron
@ -51,15 +56,22 @@ Polyhedron_demo_io_nef_plugin::load(QFileInfo fileinfo) {
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
if(!item->load(in)) if(!item->load(in))
{ {
delete item; delete item;
return 0; ok = false;
return QList<Scene_item*>();
} }
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_io_nef_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_io_nef_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -68,8 +80,9 @@ bool Polyhedron_demo_io_nef_plugin::canSave(const CGAL::Three::Scene_item* item)
return qobject_cast<const Scene_nef_polyhedron_item*>(item); return qobject_cast<const Scene_nef_polyhedron_item*>(item);
} }
bool Polyhedron_demo_io_nef_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_io_nef_plugin::save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// This plugin supports polyhedrons and polygon soups // This plugin supports polyhedrons and polygon soups
const Scene_nef_polyhedron_item* nef_item = const Scene_nef_polyhedron_item* nef_item =
qobject_cast<const Scene_nef_polyhedron_item*>(item); qobject_cast<const Scene_nef_polyhedron_item*>(item);
@ -79,6 +92,7 @@ bool Polyhedron_demo_io_nef_plugin::save(const CGAL::Three::Scene_item* item, QF
std::ofstream out(fileinfo.filePath().toUtf8()); std::ofstream out(fileinfo.filePath().toUtf8());
out.precision (std::numeric_limits<double>::digits10 + 2); out.precision (std::numeric_limits<double>::digits10 + 2);
items.pop_front();
return (nef_item && nef_item->save(out)); return (nef_item && nef_item->save(out));
} }

View File

@ -40,22 +40,21 @@ public:
} }
QString name() const { return "off_plugin"; } QString name() const { return "off_plugin"; }
QString nameFilters() const { return "OFF files (*.off);;Wavefront OBJ (*.obj)"; } QString nameFilters() const { return "OFF files (*.off);;Wavefront OBJ (*.obj)"; }
bool canLoad() const; bool canLoad(QFileInfo fileinfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
CGAL::Three::Scene_item* load_off(QFileInfo fileinfo); CGAL::Three::Scene_item* load_off(QFileInfo fileinfo);
CGAL::Three::Scene_item* load_obj(QFileInfo fileinfo); CGAL::Three::Scene_item* load_obj(QFileInfo fileinfo);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
}; };
bool Polyhedron_demo_off_plugin::canLoad() const { bool Polyhedron_demo_off_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
QList<Scene_item*> Polyhedron_demo_off_plugin::
CGAL::Three::Scene_item* load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
@ -63,14 +62,41 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
Scene_surface_mesh_item* item = Scene_surface_mesh_item* item =
new Scene_surface_mesh_item(SMesh()); new Scene_surface_mesh_item(SMesh());
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
if(fileinfo.suffix().toLower() == "off"){ if(fileinfo.suffix().toLower() == "off"){
return load_off(fileinfo); Scene_item* item = load_off(fileinfo);
if(item){
ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
}
else
{
ok = false;
return QList<Scene_item*>();
}
} else if(fileinfo.suffix().toLower() == "obj"){ } else if(fileinfo.suffix().toLower() == "obj"){
return load_obj(fileinfo);
Scene_item* item = load_obj(fileinfo);
if(item)
{
ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
}
else
{
ok = true;
return QList<Scene_item*>();
}
} }
return 0; return QList<Scene_item*>();
} }
@ -183,8 +209,12 @@ bool Polyhedron_demo_off_plugin::canSave(const CGAL::Three::Scene_item* item)
qobject_cast<const Scene_points_with_normal_item*>(item); qobject_cast<const Scene_points_with_normal_item*>(item);
} }
bool Polyhedron_demo_off_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo)
bool
Polyhedron_demo_off_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// This plugin supports point sets, surface_meshes and polygon soups // This plugin supports point sets, surface_meshes and polygon soups
const Scene_points_with_normal_item* points_item = const Scene_points_with_normal_item* points_item =
qobject_cast<const Scene_points_with_normal_item*>(item); qobject_cast<const Scene_points_with_normal_item*>(item);
@ -200,12 +230,26 @@ bool Polyhedron_demo_off_plugin::save(const CGAL::Three::Scene_item* item, QFile
out.precision (std::numeric_limits<double>::digits10 + 2); out.precision (std::numeric_limits<double>::digits10 + 2);
if(fileinfo.suffix().toLower() == "off"){ if(fileinfo.suffix().toLower() == "off"){
return (sm_item && sm_item->save(out)) || bool res = (sm_item && sm_item->save(out)) ||
(soup_item && soup_item->save(out)) || (soup_item && soup_item->save(out)) ||
(points_item && points_item->write_off_point_set(out)); (points_item && points_item->write_off_point_set(out));
if(res){
items.pop_front();
return true;
}
else{
return false;
}
} }
if(fileinfo.suffix().toLower() == "obj"){ if(fileinfo.suffix().toLower() == "obj"){
return (sm_item && sm_item->save_obj(out)); bool res = (sm_item && sm_item->save_obj(out));
if(res)
{
items.pop_front();
return true;
}
else
return false;
} }
return false; return false;
} }

View File

@ -16,19 +16,19 @@ class Polyhedron_demo_off_to_nef_plugin :
public: public:
QString name() const { return "off_to_nef_plugin"; } QString name() const { return "off_to_nef_plugin"; }
QString nameFilters() const { return "OFF files, into nef (*.off)"; } QString nameFilters() const { return "OFF files, into nef (*.off)"; }
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
}; };
bool Polyhedron_demo_off_to_nef_plugin::canLoad() const { bool Polyhedron_demo_off_to_nef_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*> Polyhedron_demo_off_to_nef_plugin::
Polyhedron_demo_off_to_nef_plugin::load(QFileInfo fileinfo) { load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
std::ifstream in(fileinfo.filePath().toUtf8()); std::ifstream in(fileinfo.filePath().toUtf8());
if(!in) if(!in)
@ -38,16 +38,23 @@ Polyhedron_demo_off_to_nef_plugin::load(QFileInfo fileinfo) {
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
if(!item->load_from_off(in)) if(!item->load_from_off(in))
{ {
delete item; delete item;
return 0; ok = false;
return QList<Scene_item*>()<<item;
} }
item->setName(fileinfo.baseName()); item->setName(fileinfo.baseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_off_to_nef_plugin::canSave(const CGAL::Three::Scene_item*) bool Polyhedron_demo_off_to_nef_plugin::canSave(const CGAL::Three::Scene_item*)
@ -55,7 +62,8 @@ bool Polyhedron_demo_off_to_nef_plugin::canSave(const CGAL::Three::Scene_item*)
return false; return false;
} }
bool Polyhedron_demo_off_to_nef_plugin::save(const CGAL::Three::Scene_item*, QFileInfo) bool Polyhedron_demo_off_to_nef_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
return false; return false;
} }

View File

@ -13,7 +13,7 @@
#include <CGAL/IO/PLY_writer.h> #include <CGAL/IO/PLY_writer.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h> #include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <QMessageBox> #include <QMessageBox>
using namespace CGAL::Three;
class Polyhedron_demo_ply_plugin : class Polyhedron_demo_ply_plugin :
public QObject, public QObject,
public CGAL::Three::Polyhedron_demo_io_plugin_interface public CGAL::Three::Polyhedron_demo_io_plugin_interface
@ -31,20 +31,22 @@ public:
} }
QString name() const { return "ply_plugin"; } QString name() const { return "ply_plugin"; }
QString nameFilters() const { return "PLY files (*.ply)"; } QString nameFilters() const { return "PLY files (*.ply)"; }
bool canLoad() const; bool canLoad(QFileInfo fileinfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
}; };
bool Polyhedron_demo_ply_plugin::canLoad() const { bool Polyhedron_demo_ply_plugin::
canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*>
Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) { Polyhedron_demo_ply_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene) {
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary); std::ifstream in(fileinfo.filePath().toUtf8(), std::ios_base::binary);
if(!in) if(!in)
@ -55,7 +57,8 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
return 0; ok = false;
return QList<Scene_item*>();
} }
// Test if input is mesh or point set // Test if input is mesh or point set
@ -99,7 +102,10 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
sm_item->setName(fileinfo.completeBaseName()); sm_item->setName(fileinfo.completeBaseName());
sm_item->comments() = comments; sm_item->comments() = comments;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return sm_item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(sm_item);
return QList<Scene_item*>()<<sm_item;
} }
in.clear(); in.clear();
@ -114,14 +120,18 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
if (!(CGAL::read_PLY (in, points, polygons, fcolors, vcolors))) if (!(CGAL::read_PLY (in, points, polygons, fcolors, vcolors)))
{ {
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return NULL; ok = false;
return QList<Scene_item*>();
} }
Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item; Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item;
soup_item->setName(fileinfo.completeBaseName()); soup_item->setName(fileinfo.completeBaseName());
soup_item->load (points, polygons, fcolors, vcolors); soup_item->load (points, polygons, fcolors, vcolors);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return soup_item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(soup_item);
return QList<Scene_item*>()<<soup_item;
} }
else // Open point set else // Open point set
{ {
@ -131,16 +141,21 @@ Polyhedron_demo_ply_plugin::load(QFileInfo fileinfo) {
{ {
delete item; delete item;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return NULL; ok = false;
return QList<Scene_item*>();
} }
if(item->has_normals()) if(item->has_normals())
item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode());
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
return NULL; ok = true;
return QList<Scene_item*>();
} }
bool Polyhedron_demo_ply_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_ply_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -152,8 +167,10 @@ bool Polyhedron_demo_ply_plugin::canSave(const CGAL::Three::Scene_item* item)
|| qobject_cast<const Scene_textured_surface_mesh_item*>(item)); || qobject_cast<const Scene_textured_surface_mesh_item*>(item));
} }
bool Polyhedron_demo_ply_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_ply_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// Check extension (quietly) // Check extension (quietly)
std::string extension = fileinfo.suffix().toUtf8().data(); std::string extension = fileinfo.suffix().toUtf8().data();
if (extension != "ply" && extension != "PLY") if (extension != "ply" && extension != "PLY")
@ -179,25 +196,49 @@ bool Polyhedron_demo_ply_plugin::save(const CGAL::Three::Scene_item* item, QFile
const Scene_points_with_normal_item* point_set_item = const Scene_points_with_normal_item* point_set_item =
qobject_cast<const Scene_points_with_normal_item*>(item); qobject_cast<const Scene_points_with_normal_item*>(item);
if (point_set_item) if (point_set_item)
return point_set_item->write_ply_point_set(out, (choice == tr("Binary"))); {
bool res =
point_set_item->write_ply_point_set(out, (choice == tr("Binary")));
if(res)
items.pop_front();
return res;
}
// This plugin supports polygon soups // This plugin supports polygon soups
const Scene_polygon_soup_item* soup_item = const Scene_polygon_soup_item* soup_item =
qobject_cast<const Scene_polygon_soup_item*>(item); qobject_cast<const Scene_polygon_soup_item*>(item);
if (soup_item) if (soup_item)
return CGAL::write_PLY (out, soup_item->points(), soup_item->polygons()); {
bool res =
CGAL::write_PLY (out, soup_item->points(), soup_item->polygons());
if(res)
items.pop_front();
return res;
}
// This plugin supports surface meshes // This plugin supports surface meshes
const Scene_surface_mesh_item* sm_item = const Scene_surface_mesh_item* sm_item =
qobject_cast<const Scene_surface_mesh_item*>(item); qobject_cast<const Scene_surface_mesh_item*>(item);
if (sm_item) if (sm_item)
return CGAL::write_ply (out, *(sm_item->polyhedron()), sm_item->comments()); {
bool res =
CGAL::write_ply (out, *(sm_item->polyhedron()), sm_item->comments());
if(res)
items.pop_front();
return res;
}
// This plugin supports textured surface meshes // This plugin supports textured surface meshes
const Scene_textured_surface_mesh_item* stm_item = const Scene_textured_surface_mesh_item* stm_item =
qobject_cast<const Scene_textured_surface_mesh_item*>(item); qobject_cast<const Scene_textured_surface_mesh_item*>(item);
if (stm_item) if (stm_item)
return CGAL::write_ply (out, *(stm_item->textured_face_graph())); {
bool res =
CGAL::write_ply (out, *(stm_item->textured_face_graph()));
if(res)
items.pop_front();
return res;
}
return false; return false;
} }

View File

@ -45,11 +45,11 @@ public:
} }
QString name() const { return "polylines_io_plugin"; } QString name() const { return "polylines_io_plugin"; }
QString nameFilters() const { return "Polylines files (*.polylines.txt *.cgal)"; } QString nameFilters() const { return "Polylines files (*.polylines.txt *.cgal)"; }
bool canLoad() const; bool canLoad(QFileInfo fileinfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
bool applicable(QAction* a) const { bool applicable(QAction* a) const {
bool all_polylines_selected = true; bool all_polylines_selected = true;
Q_FOREACH(int index, scene->selectionIndices()) Q_FOREACH(int index, scene->selectionIndices())
@ -85,19 +85,21 @@ private:
QAction* actionJoin_polylines; QAction* actionJoin_polylines;
}; };
bool Polyhedron_demo_polylines_io_plugin::canLoad() const { bool Polyhedron_demo_polylines_io_plugin::canLoad(QFileInfo fileinfo) const{
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*>
Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) { Polyhedron_demo_polylines_io_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
// Open file // Open file
std::ifstream ifs(fileinfo.filePath().toUtf8()); std::ifstream ifs(fileinfo.filePath().toUtf8());
if(!ifs) { if(!ifs) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
@ -105,7 +107,10 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
Scene_polylines_item* item = new Scene_polylines_item; Scene_polylines_item* item = new Scene_polylines_item;
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
std::list<std::vector<Scene_polylines_item::Point_3> > polylines; std::list<std::vector<Scene_polylines_item::Point_3> > polylines;
@ -123,7 +128,11 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
Scene_polylines_item::Point_3 p; Scene_polylines_item::Point_3 p;
ifs >> p; ifs >> p;
polyline.push_back(p); polyline.push_back(p);
if(!ifs.good()) return 0; if(!ifs.good())
{
ok = false;
return QList<Scene_item*>();
}
} }
std::string line_remainder; std::string line_remainder;
std::getline(ifs, line_remainder); std::getline(ifs, line_remainder);
@ -136,9 +145,17 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
std::cerr << " (metadata: \"" << qPrintable(metadata) << "\")\n"; std::cerr << " (metadata: \"" << qPrintable(metadata) << "\")\n";
} else { } else {
} }
if(ifs.bad() || ifs.fail()) return 0; if(ifs.bad() || ifs.fail())
{
ok = false;
return QList<Scene_item*>();
}
}
if(counter == 0)
{
ok = false;
return QList<Scene_item*>();
} }
if(counter == 0) return 0;
Scene_polylines_item* item = new Scene_polylines_item; Scene_polylines_item* item = new Scene_polylines_item;
item->polylines = polylines; item->polylines = polylines;
item->setName(fileinfo.baseName()); item->setName(fileinfo.baseName());
@ -146,7 +163,10 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) {
item->setProperty("polylines metadata", polylines_metadata); item->setProperty("polylines metadata", polylines_metadata);
std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl; std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl;
item->invalidateOpenGLBuffers(); item->invalidateOpenGLBuffers();
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_polylines_io_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_polylines_io_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -154,8 +174,10 @@ bool Polyhedron_demo_polylines_io_plugin::canSave(const CGAL::Three::Scene_item*
return qobject_cast<const Scene_polylines_item*>(item) != 0; return qobject_cast<const Scene_polylines_item*>(item) != 0;
} }
bool Polyhedron_demo_polylines_io_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_polylines_io_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
const Scene_polylines_item* poly_item = const Scene_polylines_item* poly_item =
qobject_cast<const Scene_polylines_item*>(item); qobject_cast<const Scene_polylines_item*>(item);
@ -188,7 +210,10 @@ bool Polyhedron_demo_polylines_io_plugin::save(const CGAL::Three::Scene_item* it
} }
out << std::endl; out << std::endl;
} }
return (bool) out; bool res = (bool) out;
if(res)
items.pop_front();
return res;
} }
void Polyhedron_demo_polylines_io_plugin::split() void Polyhedron_demo_polylines_io_plugin::split()

View File

@ -47,44 +47,51 @@ public:
bool applicable(QAction*) const { return false;} bool applicable(QAction*) const { return false;}
QString nameFilters() const; QString nameFilters() const;
QString name() const { return "stl_plugin"; } QString name() const { return "stl_plugin"; }
bool canLoad() const; bool canLoad(QFileInfo fileinfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
}; };
QString Polyhedron_demo_stl_plugin::nameFilters() const { QString Polyhedron_demo_stl_plugin::nameFilters() const {
return "STL files (*.stl)"; return "STL files (*.stl)";
} }
bool Polyhedron_demo_stl_plugin::canLoad() const { bool Polyhedron_demo_stl_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item*
Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) { QList<Scene_item*>
Polyhedron_demo_stl_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
// Open file // Open file
std::ifstream in(fileinfo.filePath().toUtf8(), std::ios::in | std::ios::binary); std::ifstream in(fileinfo.filePath().toUtf8(), std::ios::in | std::ios::binary);
if(!in) { if(!in) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
if(fileinfo.size() == 0) if(fileinfo.size() == 0)
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
Scene_surface_mesh_item* item = new Scene_surface_mesh_item(); Scene_surface_mesh_item* item = new Scene_surface_mesh_item();
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
std::vector<std::array<double, 3> > points; std::vector<std::array<double, 3> > points;
std::vector<std::array<int, 3> > triangles; std::vector<std::array<int, 3> > triangles;
if (!CGAL::read_STL(in, points, triangles)) if (!CGAL::read_STL(in, points, triangles))
{ {
std::cerr << "Error: invalid STL file" << std::endl; std::cerr << "Error: invalid STL file" << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
try{ try{
@ -98,7 +105,10 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
else{ else{
Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM); Scene_surface_mesh_item* item = new Scene_surface_mesh_item(SM);
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
} }
catch(...){} catch(...){}
@ -106,7 +116,10 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
Scene_polygon_soup_item* item = new Scene_polygon_soup_item(); Scene_polygon_soup_item* item = new Scene_polygon_soup_item();
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
item->load(points, triangles); item->load(points, triangles);
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool Polyhedron_demo_stl_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_stl_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -114,8 +127,10 @@ bool Polyhedron_demo_stl_plugin::canSave(const CGAL::Three::Scene_item* item)
return qobject_cast<const Scene_surface_mesh_item*>(item); return qobject_cast<const Scene_surface_mesh_item*>(item);
} }
bool Polyhedron_demo_stl_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_stl_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
const Scene_surface_mesh_item* sm_item = const Scene_surface_mesh_item* sm_item =
qobject_cast<const Scene_surface_mesh_item*>(item); qobject_cast<const Scene_surface_mesh_item*>(item);
@ -144,6 +159,7 @@ bool Polyhedron_demo_stl_plugin::save(const CGAL::Three::Scene_item* item, QFile
if (sm_item) if (sm_item)
{ {
CGAL::write_STL(*sm_item->face_graph(), out); CGAL::write_STL(*sm_item->face_graph(), out);
items.pop_front();
return true; return true;
} }
return false; return false;

View File

@ -42,19 +42,34 @@ public:
bool applicable(QAction*) const { return false;} bool applicable(QAction*) const { return false;}
QString name() const { return "surf_io_plugin"; } QString name() const { return "surf_io_plugin"; }
QString nameFilters() const { return "Amira files (*.surf)"; } QString nameFilters() const { return "Amira files (*.surf)"; }
bool canLoad() const{ return true; } bool canLoad(QFileInfo) const{ return true; }
template<class FaceGraphItem> template<class FaceGraphItem>
CGAL::Three::Scene_item* actual_load(QFileInfo fileinfo); CGAL::Three::Scene_item* actual_load(QFileInfo fileinfo);
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*) { return false; } bool canSave(const CGAL::Three::Scene_item*) { return false; }
bool save(const CGAL::Three::Scene_item*, QFileInfo) { return false; } bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& ) { return false; }
}; };
CGAL::Three::Scene_item* Surf_io_plugin::load(QFileInfo fileinfo) QList<Scene_item*>
Surf_io_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{ {
return actual_load<Scene_surface_mesh_item>(fileinfo); Scene_item* item =
actual_load<Scene_surface_mesh_item>(fileinfo);
if(item)
{
ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
}
else
{
ok = false;
return QList<Scene_item*>();
}
} }
template< class FaceGraphItem> template< class FaceGraphItem>
CGAL::Three::Scene_item* Surf_io_plugin::actual_load(QFileInfo fileinfo) CGAL::Three::Scene_item* Surf_io_plugin::actual_load(QFileInfo fileinfo)

View File

@ -21,26 +21,28 @@ public:
QString name() const { return "xyz_plugin"; } QString name() const { return "xyz_plugin"; }
QString nameFilters() const { return "XYZ as Point Set (*.xyz);;Point Set with Normal (*.pwn)"; } QString nameFilters() const { return "XYZ as Point Set (*.xyz);;Point Set with Normal (*.pwn)"; }
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>&);
}; };
bool Polyhedron_demo_xyz_plugin::canLoad() const { bool Polyhedron_demo_xyz_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
CGAL::Three::Scene_item* QList<Scene_item*>
Polyhedron_demo_xyz_plugin::load(QFileInfo fileinfo) Polyhedron_demo_xyz_plugin::
load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{ {
// Open file // Open file
std::ifstream in(fileinfo.filePath().toUtf8().data()); std::ifstream in(fileinfo.filePath().toUtf8().data());
if(!in) { if(!in) {
std::cerr << "Error! Cannot open file " << fileinfo.filePath().toStdString() << std::endl; std::cerr << "Error! Cannot open file " << fileinfo.filePath().toStdString() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
@ -50,19 +52,26 @@ Polyhedron_demo_xyz_plugin::load(QFileInfo fileinfo)
Scene_points_with_normal_item* item = Scene_points_with_normal_item* item =
new Scene_points_with_normal_item(); new Scene_points_with_normal_item();
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
// Read .xyz in a point set // Read .xyz in a point set
Scene_points_with_normal_item* point_set_item = new Scene_points_with_normal_item; Scene_points_with_normal_item* point_set_item = new Scene_points_with_normal_item;
point_set_item->setName(fileinfo.completeBaseName()); point_set_item->setName(fileinfo.completeBaseName());
if(!point_set_item->read_xyz_point_set(in)) { if(!point_set_item->read_xyz_point_set(in)) {
delete point_set_item; delete point_set_item;
return NULL; ok = false;
return QList<Scene_item*>();
} }
if(point_set_item->has_normals()) if(point_set_item->has_normals())
point_set_item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode()); point_set_item->setRenderingMode(CGAL::Three::Three::defaultPointSetRenderingMode());
return point_set_item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(point_set_item);
return QList<Scene_item*>()<<point_set_item;
} }
bool Polyhedron_demo_xyz_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_xyz_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -71,8 +80,10 @@ bool Polyhedron_demo_xyz_plugin::canSave(const CGAL::Three::Scene_item* item)
return qobject_cast<const Scene_points_with_normal_item*>(item); return qobject_cast<const Scene_points_with_normal_item*>(item);
} }
bool Polyhedron_demo_xyz_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) bool Polyhedron_demo_xyz_plugin::
save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items)
{ {
Scene_item* item = items.front();
// Check extension (quietly) // Check extension (quietly)
std::string extension = fileinfo.suffix().toUtf8().data(); std::string extension = fileinfo.suffix().toUtf8().data();
if (extension != "xyz" && extension != "XYZ" && if (extension != "xyz" && extension != "XYZ" &&
@ -88,7 +99,10 @@ bool Polyhedron_demo_xyz_plugin::save(const CGAL::Three::Scene_item* item, QFile
// Save point set as .xyz // Save point set as .xyz
std::ofstream out(fileinfo.filePath().toUtf8().data()); std::ofstream out(fileinfo.filePath().toUtf8().data());
out.precision (std::numeric_limits<double>::digits10 + 2); out.precision (std::numeric_limits<double>::digits10 + 2);
return point_set_item->write_xyz_point_set(out); bool res = point_set_item->write_xyz_point_set(out);
if(res)
items.pop_front();
return res;
} }
#include "XYZ_io_plugin.moc" #include "XYZ_io_plugin.moc"

View File

@ -33,13 +33,14 @@ public:
"3-map files (*.3map)"; "3-map files (*.3map)";
} }
bool canLoad() const { return true; } bool canLoad(QFileInfo) const { return true; }
CGAL::Three::Scene_item* load(QFileInfo fileinfo){ QList<CGAL::Three::Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true){
// Open file // Open file
std::ifstream ifs(fileinfo.filePath().toUtf8()); std::ifstream ifs(fileinfo.filePath().toUtf8());
if(!ifs) { if(!ifs) {
std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return nullptr; ok = false;
return QList<CGAL::Three::Scene_item*>();
} }
Scene_lcc_item::LCC lcc; Scene_lcc_item::LCC lcc;
@ -53,17 +54,21 @@ public:
} }
if(!res) if(!res)
{ {
return nullptr; ok = false;
return QList<CGAL::Three::Scene_item*>();
} }
Scene_lcc_item* new_item = new Scene_lcc_item(lcc); Scene_lcc_item* new_item = new Scene_lcc_item(lcc);
new_item->setName(fileinfo.fileName()); new_item->setName(fileinfo.fileName());
new_item->invalidateOpenGLBuffers(); new_item->invalidateOpenGLBuffers();
return new_item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(new_item);
ok = true;
return QList<CGAL::Three::Scene_item*>()<<new_item;
} }
bool canSave(const CGAL::Three::Scene_item*){return false;} bool canSave(const CGAL::Three::Scene_item*){return false;}
bool save(const CGAL::Three::Scene_item*, QFileInfo){ bool save(QFileInfo, QList<CGAL::Three::Scene_item*>& ){
return false; return false;
} }

View File

@ -37,11 +37,11 @@ public:
{ {
return false; return false;
} }
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item*, QFileInfo fileinfo); bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& );
private: private:
bool try_load_other_binary_format(std::istream& in, C3t3& c3t3); bool try_load_other_binary_format(std::istream& in, C3t3& c3t3);
@ -50,21 +50,23 @@ private:
}; };
bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad() const { bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
QList<Scene_item*>
CGAL::Three::Scene_item* Polyhedron_demo_c3t3_binary_io_plugin::load(
Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { QFileInfo fileinfo, bool& ok, bool add_to_scene) {
// Open file // Open file
ok = true;
std::ifstream in(fileinfo.filePath().toUtf8(), std::ifstream in(fileinfo.filePath().toUtf8(),
std::ios_base::in|std::ios_base::binary); std::ios_base::in|std::ios_base::binary);
if(!in) { if(!in) {
std::cerr << "Error! Cannot open file " std::cerr << "Error! Cannot open file "
<< (const char*)fileinfo.filePath().toUtf8() << std::endl; << (const char*)fileinfo.filePath().toUtf8() << std::endl;
return NULL; ok = false;
return QList<Scene_item*>();
} }
Scene_c3t3_item* item = new Scene_c3t3_item(); Scene_c3t3_item* item = new Scene_c3t3_item();
@ -72,7 +74,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
{ {
CGAL::Three::Three::warning( tr("The file you are trying to load is empty.")); CGAL::Three::Three::warning( tr("The file you are trying to load is empty."));
item->setName(fileinfo.completeBaseName()); item->setName(fileinfo.completeBaseName());
return item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<< item;
} }
if(fileinfo.suffix().toLower() == "cgal") if(fileinfo.suffix().toLower() == "cgal")
{ {
@ -80,7 +84,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
if(item->load_binary(in)) { if(item->load_binary(in)) {
return item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>() << item;
} }
item->c3t3().clear(); item->c3t3().clear();
@ -89,7 +95,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
item->c3t3_changed(); item->c3t3_changed();
item->changed(); item->changed();
item->resetCutPlane(); item->resetCutPlane();
return item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<< item;
} }
item->c3t3().clear(); item->c3t3().clear();
@ -98,7 +106,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
item->c3t3_changed(); item->c3t3_changed();
item->changed(); item->changed();
item->resetCutPlane(); item->resetCutPlane();
return item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
} }
else if (fileinfo.suffix().toLower() == "mesh") else if (fileinfo.suffix().toLower() == "mesh")
@ -154,7 +164,9 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
item->c3t3_changed(); item->c3t3_changed();
item->resetCutPlane(); item->resetCutPlane();
return item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
else if(item->c3t3().triangulation().number_of_finite_cells() == 0) else if(item->c3t3().triangulation().number_of_finite_cells() == 0)
{ {
@ -168,7 +180,8 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) {
// if all loading failed... // if all loading failed...
delete item; delete item;
return NULL; ok = false;
return QList<Scene_item*>();
} }
bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_item* item) bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_item* item)
@ -179,51 +192,63 @@ bool Polyhedron_demo_c3t3_binary_io_plugin::canSave(const CGAL::Three::Scene_ite
bool bool
Polyhedron_demo_c3t3_binary_io_plugin:: Polyhedron_demo_c3t3_binary_io_plugin::
save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) save(QFileInfo fileinfo, QList<Scene_item *> &items)
{ {
const Scene_c3t3_item* c3t3_item = qobject_cast<const Scene_c3t3_item*>(item); Scene_item* item = items.front();
if ( NULL == c3t3_item ) const Scene_c3t3_item* c3t3_item = qobject_cast<const Scene_c3t3_item*>(item);
{ if ( NULL == c3t3_item )
return false; {
} return false;
}
QString path = fileinfo.absoluteFilePath(); QString path = fileinfo.absoluteFilePath();
if(path.endsWith(".cgal")) if(path.endsWith(".cgal"))
{ {
std::ofstream out(fileinfo.filePath().toUtf8(), std::ofstream out(fileinfo.filePath().toUtf8(),
std::ios_base::out|std::ios_base::binary); std::ios_base::out|std::ios_base::binary);
return out && c3t3_item->save_binary(out); bool ok = out && c3t3_item->save_binary(out);
} if(!ok)
return false;
else if (fileinfo.suffix() == "mesh")
{
std::ofstream medit_file (qPrintable(path));
c3t3_item->c3t3().output_to_medit(medit_file,true,true);
return true;
}
else if (fileinfo.suffix() == "ma")
{
std::ofstream maya_file (qPrintable(path));
c3t3_item->c3t3().output_to_maya(
maya_file,true);
return true;
}
else if (fileinfo.suffix() == "am")
{
std::ofstream avizo_file (qPrintable(path));
CGAL::output_to_avizo(avizo_file, c3t3_item->c3t3());
return true;
}
else if (fileinfo.suffix() == "off")
{
std::ofstream off_file(qPrintable(path));
c3t3_item->c3t3().output_facets_in_complex_to_off(off_file);
return true;
}
else else
return false; {
items.pop_front();
return true;
}
}
else if (fileinfo.suffix() == "mesh")
{
std::ofstream medit_file (qPrintable(path));
c3t3_item->c3t3().output_to_medit(medit_file,true,true);
items.pop_front();
return true;
}
else if (fileinfo.suffix() == "ma")
{
std::ofstream maya_file (qPrintable(path));
c3t3_item->c3t3().output_to_maya(
maya_file,true);
items.pop_front();
return true;
}
else if (fileinfo.suffix() == "am")
{
std::ofstream avizo_file (qPrintable(path));
CGAL::output_to_avizo(avizo_file, c3t3_item->c3t3());
items.pop_front();
return true;
}
else if (fileinfo.suffix() == "off")
{
std::ofstream off_file(qPrintable(path));
c3t3_item->c3t3().output_facets_in_complex_to_off(off_file);
items.pop_front();
return true;
}
else
return false;
} }
struct Fake_mesh_domain { struct Fake_mesh_domain {

View File

@ -282,15 +282,18 @@ public:
Io_image_plugin() : planeSwitch(NULL) {} Io_image_plugin() : planeSwitch(NULL) {}
QString nameFilters() const; QString nameFilters() const;
bool canLoad() const; bool canLoad(QFileInfo) const;
CGAL::Three::Scene_item* load(QFileInfo fileinfo); QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
bool canSave(const CGAL::Three::Scene_item*); bool canSave(const CGAL::Three::Scene_item*);
bool save(const CGAL::Three::Scene_item* item, QFileInfo fi) { bool save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& items ) {
Scene_item* item = items.front();
const Scene_image_item* im_item = qobject_cast<const Scene_image_item*>(item); const Scene_image_item* im_item = qobject_cast<const Scene_image_item*>(item);
point_image p_im = *im_item->image()->image(); point_image p_im = *im_item->image()->image();
return _writeImage(&p_im, fi.filePath().toUtf8()) == 0; bool ok = _writeImage(&p_im, fileinfo.filePath().toUtf8()) == 0;
items.pop_front();
return ok;
} }
QString name() const { return "segmented images"; } QString name() const { return "segmented images"; }
@ -965,7 +968,7 @@ QString Io_image_plugin::nameFilters() const {
} }
bool Io_image_plugin::canLoad() const { bool Io_image_plugin::canLoad(QFileInfo) const {
return true; return true;
} }
@ -987,8 +990,11 @@ void convert(Image* image)
image->image()->wdim = 4; image->image()->wdim = 4;
image->image()->wordKind = WK_FLOAT; image->image()->wordKind = WK_FLOAT;
} }
CGAL::Three::Scene_item*
Io_image_plugin::load(QFileInfo fileinfo) { QList<Scene_item*>
Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
{
ok = true;
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
Image* image = new Image; Image* image = new Image;
if(fileinfo.suffix() != "H" && fileinfo.suffix() != "HH" && if(fileinfo.suffix() != "H" && fileinfo.suffix() != "HH" &&
@ -1075,8 +1081,9 @@ Io_image_plugin::load(QFileInfo fileinfo) {
success = false; success = false;
} }
if(!success){ if(!success){
ok = false;
delete image; delete image;
return NULL; return QList<Scene_item*>();
} }
} }
//read a sep file //read a sep file
@ -1117,7 +1124,8 @@ Io_image_plugin::load(QFileInfo fileinfo) {
if(return_code != QDialog::Accepted) if(return_code != QDialog::Accepted)
{ {
delete image; delete image;
return NULL; ok = false;
return QList<Scene_item*>();
} }
// Get selected precision // Get selected precision
@ -1145,7 +1153,9 @@ Io_image_plugin::load(QFileInfo fileinfo) {
else else
image_item = new Scene_image_item(image,voxel_scale, false); image_item = new Scene_image_item(image,voxel_scale, false);
image_item->setName(fileinfo.baseName()); image_item->setName(fileinfo.baseName());
return image_item; if(add_to_scene)
CGAL::Three::Three::scene()->addItem(image_item);
return QList<Scene_item*>() << image_item;
} }
bool Io_image_plugin::canSave(const CGAL::Three::Scene_item* item) bool Io_image_plugin::canSave(const CGAL::Three::Scene_item* item)

View File

@ -78,7 +78,7 @@ public:
QString nameFilters() const { return "Selection files(*.selection.txt)"; } QString nameFilters() const { return "Selection files(*.selection.txt)"; }
QString name() const { return "selection_sm_plugin"; } QString name() const { return "selection_sm_plugin"; }
bool canLoad() const { bool canLoad(QFileInfo) const {
Scene_item * item = CGAL::Three::Three::scene()->item( Scene_item * item = CGAL::Three::Three::scene()->item(
CGAL::Three::Three::scene()->mainSelectionIndex()); CGAL::Three::Three::scene()->mainSelectionIndex());
Scene_facegraph_item* fg_item = qobject_cast<Scene_facegraph_item*>(item); Scene_facegraph_item* fg_item = qobject_cast<Scene_facegraph_item*>(item);
@ -91,26 +91,38 @@ public:
return false; return false;
} }
CGAL::Three::Scene_item* load(QFileInfo fileinfo) { QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) {
if(fileinfo.suffix().toLower() != "txt") return 0; if(fileinfo.suffix().toLower() != "txt")
{
ok = false;
return QList<Scene_item*>();
}
// There will be no actual loading at this step. // There will be no actual loading at this step.
Scene_polyhedron_selection_item* item = new Scene_polyhedron_selection_item(); Scene_polyhedron_selection_item* item = new Scene_polyhedron_selection_item();
if(!item->load(fileinfo.filePath().toStdString())) { if(!item->load(fileinfo.filePath().toStdString())) {
delete item; delete item;
return NULL; ok = false;
return QList<Scene_item*>();
} }
item->setName(fileinfo.baseName()); item->setName(fileinfo.baseName());
return item; ok = true;
if(add_to_scene)
CGAL::Three::Three::scene()->addItem(item);
return QList<Scene_item*>()<<item;
} }
bool canSave(const CGAL::Three::Scene_item* scene_item) { bool canSave(const CGAL::Three::Scene_item* scene_item) {
return qobject_cast<const Scene_polyhedron_selection_item*>(scene_item); return qobject_cast<const Scene_polyhedron_selection_item*>(scene_item);
} }
bool save(const CGAL::Three::Scene_item* scene_item, QFileInfo fileinfo) { bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& items) {
Scene_item* scene_item = items.front();
const Scene_polyhedron_selection_item* item = qobject_cast<const Scene_polyhedron_selection_item*>(scene_item); const Scene_polyhedron_selection_item* item = qobject_cast<const Scene_polyhedron_selection_item*>(scene_item);
if(item == NULL) { return false; } if(item == NULL) { return false; }
return item->save(fileinfo.filePath().toStdString()); bool res = item->save(fileinfo.filePath().toStdString());
if(res)
items.pop_front();
return res;
} }
bool applicable(QAction*) const { bool applicable(QAction*) const {

View File

@ -58,17 +58,23 @@ public:
//! Specifies if the io_plugin is able to load an item or not. //! Specifies if the io_plugin is able to load an item or not.
//! This must be overriden. //! This must be overriden.
virtual bool canLoad() const = 0; virtual bool canLoad(QFileInfo fileinfo) const = 0;
//! Loads an item from a file. //! Loads one or more item(s) from a file. `ok` is `true` if the loading
//! was successful, `false` otherwise.
//! New items will be added to the scene if `add_to_scene` is `true`.
//! You don't want that when you reload an item, for example,
//! as it will be added at some other point of the process.
//! This must be overriden. //! This must be overriden.
virtual Scene_item* load(QFileInfo fileinfo) = 0; virtual QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) = 0;
//!Specifies if the io_plugin can save the item or not. //!Specifies if the io_plugin can save the item or not.
//!This must be overriden. //!This must be overriden.
virtual bool canSave(const Scene_item*) = 0; virtual bool canSave(const Scene_item*) = 0;
//!Saves the item in the file corresponding to the path //!Saves one or more items in the file corresponding to the path
//!contained in fileinfo. Returns false if error. //!contained in fileinfo. Returns false if error.
//! This must be overriden. //! This must be overriden.
virtual bool save(const Scene_item*, QFileInfo fileinfo) = 0; //! @attention When a file is successfully saved, it must be removed from the
//! list.
virtual bool save(QFileInfo fileinfo,QList<CGAL::Three::Scene_item*>& ) = 0;
//! If this returns `true`, then the loader will be chosen as default in the //! If this returns `true`, then the loader will be chosen as default in the
//! list of available loaders when saving a file, which means it will be the //! list of available loaders when saving a file, which means it will be the

View File

@ -0,0 +1,4 @@
#ifndef SCENE_3MF_ITEM_INTERFACE_H
#define SCENE_3MF_ITEM_INTERFACE_H
#endif // SCENE_3MF_ITEM_INTERFACE_H