From 45effcef687d7f77be43ca6b9f86e100b7b3ffba Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 31 Jan 2017 15:21:34 +0100 Subject: [PATCH] Secure the invalid c3t3_items to keep from calling algorithm that won't work on them. --- .../Plugins/Mesh_3/C3t3_io_plugin.cpp | 1 + .../Mesh_3/C3t3_rib_exporter_plugin.cpp | 4 +- .../Plugins/Mesh_3/Optimization_plugin.cpp | 2 +- .../demo/Polyhedron/Scene_c3t3_item.cpp | 40 +++++++++++++------ Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 3 ++ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp index 385853bb60c..50d693052b8 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_io_plugin.cpp @@ -97,6 +97,7 @@ Polyhedron_demo_c3t3_binary_io_plugin::load(QFileInfo fileinfo) { Scene_c3t3_item* item = new Scene_c3t3_item(); item->setName(fileinfo.baseName()); item->setScene(scene); + item->set_valid(false); std::vector border_infos; bool facets_in_complex = false; if(CGAL::build_triangulation_from_file(in, item->c3t3().triangulation(), border_infos)) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_rib_exporter_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_rib_exporter_plugin.cpp index fa98a977b4a..ff56048b7da 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_rib_exporter_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/C3t3_rib_exporter_plugin.cpp @@ -47,7 +47,9 @@ public: { return QList() << actionCreateRib; } - bool applicable(QAction*)const{return qobject_cast(scene->item(scene->mainSelectionIndex()));} + bool applicable(QAction*)const{ + Scene_c3t3_item* item = qobject_cast(scene->item(scene->mainSelectionIndex())); + return item && item->is_valid();} public Q_SLOTS: void create_rib(); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin.cpp index 1aa351022c8..0bcad1dda79 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Optimization_plugin.cpp @@ -90,7 +90,7 @@ public: bool applicable(QAction* a) const { Scene_c3t3_item* item = qobject_cast(scene->item(scene->mainSelectionIndex())); - if (NULL == item) + if (NULL == item || !item->is_valid()) return false; if (a == actionOdt || a == actionLloyd) diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index b19ecbc8805..4682b58322e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -231,6 +231,7 @@ struct Scene_c3t3_item_priv { , histogram_() , surface_patch_indices_() , subdomain_indices_() + , is_valid(true) { init_default_values(); } @@ -241,6 +242,7 @@ struct Scene_c3t3_item_priv { , histogram_() , surface_patch_indices_() , subdomain_indices_() + , is_valid(true) { init_default_values(); } @@ -389,6 +391,7 @@ struct Scene_c3t3_item_priv { bool show_tetrahedra; bool is_aabb_tree_built; bool cnc_are_shown; + bool is_valid; }; struct Set_show_tetrahedra { @@ -1129,20 +1132,22 @@ QMenu* Scene_c3t3_item::contextMenu() SIGNAL(triggered()), this, SLOT(export_facets_in_complex())); - QAction* actionShowSpheres = - menu->addAction(tr("Show protecting &spheres")); - actionShowSpheres->setCheckable(true); - actionShowSpheres->setObjectName("actionShowSpheres"); - connect(actionShowSpheres, SIGNAL(toggled(bool)), - this, SLOT(show_spheres(bool))); - - QAction* actionShowCNC = - menu->addAction(tr("Show cells not in complex")); - actionShowCNC->setCheckable(true); - actionShowCNC->setObjectName("actionShowCNC"); - connect(actionShowCNC, SIGNAL(toggled(bool)), - this, SLOT(show_cnc(bool))); + if(is_valid()) + { + QAction* actionShowSpheres = + menu->addAction(tr("Show protecting &spheres")); + actionShowSpheres->setCheckable(true); + actionShowSpheres->setObjectName("actionShowSpheres"); + connect(actionShowSpheres, SIGNAL(toggled(bool)), + this, SLOT(show_spheres(bool))); + QAction* actionShowCNC = + menu->addAction(tr("Show cells not in complex")); + actionShowCNC->setCheckable(true); + actionShowCNC->setObjectName("actionShowCNC"); + connect(actionShowCNC, SIGNAL(toggled(bool)), + this, SLOT(show_cnc(bool))); + } QAction* actionShowTets = menu->addAction(tr("Show &tetrahedra")); actionShowTets->setCheckable(true); @@ -1624,4 +1629,13 @@ void Scene_c3t3_item::copyProperties(Scene_item *item) show_grid(c3t3_item->has_grid()); } + +bool Scene_c3t3_item::is_valid() const +{ + return d->is_valid; +} +void Scene_c3t3_item::set_valid(bool b) +{ + d->is_valid = b; +} #include "Scene_c3t3_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index 155d20d0872..79a6ca348e3 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -59,6 +59,8 @@ public: void c3t3_changed(); + void set_valid(bool); + const C3t3& c3t3() const; C3t3& c3t3(); @@ -70,6 +72,7 @@ public: bool has_grid() const; bool has_cnc() const; bool has_tets() const; + bool is_valid() const;//true if the c3t3 is correct, false if it was made from a .mesh, for example ManipulatedFrame* manipulatedFrame(); void setPosition(float x, float y, float z) ;