From 827adf63b8fa9eeaaaa1dc995e3e596b29cd5f55 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 15 Apr 2016 17:03:07 +0200 Subject: [PATCH] Small fixes - Fix the reload item - Prints the warning about not oriented facets in the console, and explains how to convert a polygon_soup into a surface_mesh or a polyhedron. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 2 +- .../Plugins/IO/Surface_mesh_io_plugin.cpp | 52 +++++++++++++------ .../Plugins/PMP/Orient_soup_plugin.cpp | 2 + 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 226aab568ab..e720c9f24c6 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -867,7 +867,7 @@ void MainWindow::reloadItem() { QString loader_name = item->property("loader_name").toString(); if(filename.isEmpty() || loader_name.isEmpty()) { std::cerr << "Cannot reload item: " - << "the item has no \"source filename\" or no \"loader_name\" attached attached\n"; + << "the item has no \"source filename\" or no \"loader_name\" attached\n"; return; } diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/Surface_mesh_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/Surface_mesh_io_plugin.cpp index ea6e95c65bf..4f29ac06471 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/Surface_mesh_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/Surface_mesh_io_plugin.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -8,27 +9,43 @@ #include #include "Scene_surface_mesh_item.h" #include "Scene_polygon_soup_item.h" +#include "Messages_interface.h" //This plugin crates an action in Operations that displays "Hello World" in the 'console' dockwidet. class SurfaceMeshIoPlugin : public QObject, - public CGAL::Three::Polyhedron_demo_io_plugin_interface + public CGAL::Three::Polyhedron_demo_io_plugin_interface, + public CGAL::Three::Polyhedron_demo_plugin_interface { Q_OBJECT - Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface) + Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface CGAL::Three::Polyhedron_demo_io_plugin_interface) Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: - QString name() const { return "surface_mesh_io_plugin"; } - QString nameFilters() const { return "OFF files (*.off)"; } - bool canLoad() const { return true; } - CGAL::Three::Scene_item* load(QFileInfo fileinfo) { + void init(QMainWindow*, CGAL::Three::Scene_interface*, Messages_interface* m) + { + qDebug()<<"coucou"; + this->message = m; + } + bool applicable(QAction*) const + { + return false; + } + QList actions() const + { + return QList(); + } + QString name() const { return "surface_mesh_io_plugin"; } + QString nameFilters() const { return "OFF files (*.off)"; } + bool canLoad() const { return true; } + CGAL::Three::Scene_item* load(QFileInfo fileinfo) { if(fileinfo.suffix().toLower() != "off") return 0; // Open file std::ifstream in(fileinfo.filePath().toUtf8()); if(!in) { - std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; + message->error(QString("Cannot open file %1").arg((const char*)fileinfo.filePath().toUtf8())); return NULL; } @@ -36,36 +53,39 @@ public: in >> *surface_mesh; if(!in || surface_mesh->is_empty()) { - delete surface_mesh; + delete surface_mesh; in.close(); // Try to read .off in a polygon soup Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item(); soup_item->setName(fileinfo.completeBaseName()); std::ifstream in2(fileinfo.filePath().toUtf8()); if(!soup_item->load(in2)) { + message->error(QString("Cannot open file %1").arg((const char*)fileinfo.filePath().toUtf8())); delete soup_item; return 0; } + message->information("The facets don't seem to be oriented. Loading a Soup of polygons instead." + "To convert it to a Surface_mesh or a Polyhedron, use Polygon Mesh Processing -> Orient polygon soup"); return soup_item; } Scene_surface_mesh_item* item = new Scene_surface_mesh_item(surface_mesh); item->setName(fileinfo.completeBaseName()); return item; - } - bool canSave(const CGAL::Three::Scene_item* ) { + } + bool canSave(const CGAL::Three::Scene_item* ) { return false; - } + } - bool save(const CGAL::Three::Scene_item* , QFileInfo ) { + bool save(const CGAL::Three::Scene_item* , QFileInfo ) { return false; - } + } private: - QList _actions; - //The reference to the main window - QMainWindow* mw; + QList _actions; + //The reference to the main window + Messages_interface* message; }; #include "Surface_mesh_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp index 53b1df18bf5..a8cf89d70f3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/PMP/Orient_soup_plugin.cpp @@ -149,6 +149,7 @@ void Polyhedron_demo_orient_soup_plugin::orientPoly() poly_item->setVisible(item->visible()); poly_item->invalidateOpenGLBuffers(); poly_item->setProperty("source filename", item->property("source filename")); + poly_item->setProperty("loader_name", item->property("loader_name")); scene->replaceItem(index, poly_item); item->deleteLater(); } else { @@ -192,6 +193,7 @@ void Polyhedron_demo_orient_soup_plugin::orientSM() sm_item->setRenderingMode(item->renderingMode()); sm_item->setVisible(item->visible()); sm_item->setProperty("source filename", item->property("source filename")); + sm_item->setProperty("loader_name", item->property("loader_name")); scene->replaceItem(index, sm_item); item->deleteLater(); } else {