Clean-up io-plugins

This commit is contained in:
Maxime Gimeno 2019-05-16 14:00:04 +02:00
parent e717987f64
commit dbf2a6854f
7 changed files with 45 additions and 99 deletions

View File

@ -1118,11 +1118,11 @@ void MainWindow::open(QString filename)
{
// 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
Q_FOREACH(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin, io_plugins) {
if ( !io_plugin->canLoad(fileinfo) ) continue;
all_items << io_plugin->name();
for(CGAL::Three::Polyhedron_demo_io_plugin_interface* io_plugin : io_plugins) {
if ( file_matches_filter(io_plugin->loadNameFilters(), filename.toLower()) )
{
if ( !io_plugin->canLoad(fileinfo) ) continue;
all_items << io_plugin->name();
if(io_plugin->isDefaultLoader(fileinfo.completeSuffix()))
selected_items.prepend(io_plugin->name());
else

View File

@ -1,50 +1,41 @@
#include <QtCore/qglobal.h>
#include "Messages_interface.h"
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
#include "Camera_positions_list.h"
#include <CGAL/Three/Three.h>
#include <CGAL/Three/Viewer_interface.h>
#include <QMainWindow>
using namespace CGAL::Three;
class Polyhedron_demo_camera_positions_plugin :
public QObject,
public Polyhedron_demo_plugin_interface,
public CGAL::Three::Polyhedron_demo_io_plugin_interface
{
Q_OBJECT
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_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90")
public:
void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* );
QList<QAction*> actions() const;
void init();
QString name() const { return "camera_positions_plugin"; }
QString nameFilters() const { return "Camera positions (*.camera.txt)"; }
bool canLoad() const { return true; }
Scene_item* load(QFileInfo fileinfo) { cpl->load(fileinfo.filePath()); return 0; }
bool canLoad(QFileInfo) const { return true; }
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true) { ok = true; cpl->load(fileinfo.filePath()); return QList<Scene_item*>(); }
bool canSave(const Scene_item*) { return false; }
bool save(const Scene_item*, QFileInfo ) {return false; }
bool applicable(QAction*) const {return false;}
bool save(QFileInfo,QList<CGAL::Three::Scene_item*>& ) {return false; }
private:
Camera_positions_list* cpl;
};
void Polyhedron_demo_camera_positions_plugin::init(QMainWindow* mainWindow, Scene_interface*, Messages_interface *)
void Polyhedron_demo_camera_positions_plugin::init()
{
cpl = new Camera_positions_list(mainWindow);
mainWindow->addDockWidget(Qt::LeftDockWidgetArea, cpl);
}
QList<QAction*>
Polyhedron_demo_camera_positions_plugin::actions() const
{
return QList<QAction*>();
cpl = new Camera_positions_list(CGAL::Three::Three::mainWindow());
CGAL::Three::Three::mainWindow()->addDockWidget(Qt::LeftDockWidgetArea, cpl);
}
#include "Camera_positions_plugin.moc"

View File

@ -17,27 +17,15 @@ using namespace CGAL::Three;
class Polyhedron_demo_gocad_plugin :
public QObject,
public Polyhedron_demo_io_plugin_interface,
public Polyhedron_demo_plugin_helper
public Polyhedron_demo_io_plugin_interface
{
Q_OBJECT
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" FILE "gocad_io_plugin.json")
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90" )
Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90" FILE "gocad_io_plugin.json")
public:
void init(QMainWindow* mainWindow,
CGAL::Three::Scene_interface* scene_interface,
Messages_interface*) {
//get the references
this->scene = scene_interface;
this->mw = mainWindow;
}
QList<QAction*> actions() const {
return QList<QAction*>();
}
bool applicable(QAction*) const { return false;}
QString nameFilters() const;
QString name() const { return "gocad_plugin"; }
bool canLoad(QFileInfo) const;

View File

@ -5,8 +5,6 @@
#include "SMesh_type.h"
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include <CGAL/Three/Three.h>
#include <fstream>
@ -25,26 +23,13 @@
using namespace CGAL::Three;
class Polyhedron_demo_stl_plugin :
public QObject,
public Polyhedron_demo_io_plugin_interface,
public Polyhedron_demo_plugin_helper
public Polyhedron_demo_io_plugin_interface
{
Q_OBJECT
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" FILE "stl_io_plugin.json")
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90")
Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90" FILE "stl_io_plugin.json")
public:
void init(QMainWindow* mainWindow,
CGAL::Three::Scene_interface* scene_interface,
Messages_interface*) {
//get the references
this->scene = scene_interface;
this->mw = mainWindow;
}
QList<QAction*> actions() const {
return QList<QAction*>();
}
bool applicable(QAction*) const { return false;}
QString nameFilters() const;
QString name() const { return "stl_plugin"; }
bool canLoad(QFileInfo fileinfo) const;

View File

@ -3,8 +3,6 @@
#include <QMainWindow>
#include <QObject>
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_helper.h>
#include <CGAL/Three/Scene_group_item.h>
#include <CGAL/Three/Three.h>
@ -20,26 +18,14 @@
using namespace CGAL::Three;
class Surf_io_plugin:
public QObject,
public Polyhedron_demo_io_plugin_interface,
public Polyhedron_demo_plugin_helper
public Polyhedron_demo_io_plugin_interface
{
Q_OBJECT
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" FILE "surf_io_plugin.json")
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90")
Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90" FILE "surf_io_plugin.json")
public:
void init(QMainWindow* mainWindow,
CGAL::Three::Scene_interface* scene_interface,
Messages_interface*) {
//get the references
this->scene = scene_interface;
this->mw = mainWindow;
}
QList<QAction*> actions() const {
return QList<QAction*>();
}
bool applicable(QAction*) const { return false;}
QString name() const { return "surf_io_plugin"; }
QString nameFilters() const { return "Amira files (*.surf)"; }
bool canLoad(QFileInfo) const{ return true; }
@ -118,8 +104,8 @@ CGAL::Three::Scene_item* Surf_io_plugin::actual_load(QFileInfo fileinfo)
FaceGraphItem *patch = new FaceGraphItem(patches[i]);
patch->setName(QString("Patch #%1").arg(i));
patch->setColor(colors_[i]);
scene->addItem(patch);
scene->changeGroup(patch, group);
CGAL::Three::Three::scene()->addItem(patch);
CGAL::Three::Three::scene()->changeGroup(patch, group);
}
return group;
}

View File

@ -2,7 +2,6 @@
#include "Scene_c3t3_item.h"
#include <CGAL/Mesh_3/tet_soup_to_c3t3.h>
#include <CGAL/Three/Polyhedron_demo_io_plugin_interface.h>
#include <CGAL/Three/Polyhedron_demo_plugin_interface.h>
#include <CGAL/Three/Three.h>
#include <CGAL/IO/File_avizo.h>
#include <iostream>
@ -12,31 +11,17 @@
class Polyhedron_demo_c3t3_binary_io_plugin :
public QObject,
public CGAL::Three::Polyhedron_demo_io_plugin_interface,
public CGAL::Three::Polyhedron_demo_plugin_interface
public CGAL::Three::Polyhedron_demo_io_plugin_interface
{
Q_OBJECT
Q_INTERFACES(CGAL::Three::Polyhedron_demo_io_plugin_interface)
Q_INTERFACES(CGAL::Three::Polyhedron_demo_plugin_interface)
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0" FILE "c3t3_io_plugin.json")
Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.90" FILE "c3t3_io_plugin.json")
public:
void init(QMainWindow*, CGAL::Three::Scene_interface* sc, Messages_interface*)
{
this->scene = sc;
}
QString name() const { return "C3t3_io_plugin"; }
QString nameFilters() const { return "binary files (*.cgal);;ascii (*.mesh);;maya (*.ma)"; }
QString saveNameFilters() const { return "binary files (*.cgal);;ascii (*.mesh);;maya (*.ma);;avizo (*.am);;OFF files (*.off)"; }
QString loadNameFilters() const { return "binary files (*.cgal);;ascii (*.mesh)"; }
QList<QAction*> actions() const
{
return QList<QAction*>();
}
bool applicable(QAction*) const
{
return false;
}
bool canLoad(QFileInfo) const;
QList<Scene_item*> load(QFileInfo fileinfo, bool& ok, bool add_to_scene=true);
@ -50,8 +35,23 @@ private:
};
bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad(QFileInfo) const {
bool Polyhedron_demo_c3t3_binary_io_plugin::canLoad(QFileInfo fi) const {
std::ifstream in(fi.filePath().toUtf8(),
std::ios_base::in|std::ios_base::binary);
if(!in) {
std::cerr << "Error! Cannot open file "
<< (const char*)fi.filePath().toUtf8() << std::endl;
return false;
}
std::string line;
std::istringstream iss;
std::getline (in,line);
iss.str(line);
std::string keyword;
if (iss >> keyword)
if (keyword == "binary")
return true;
return false;
}
QList<Scene_item*>

View File

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