Merge pull request #5014 from maxGimeno/Demo-Fix_fit_text-maxGimeno

Polyhedron Demo: Robustify the engrave_text_plugin
This commit is contained in:
Laurent Rineau 2020-09-25 15:34:25 +02:00
commit 0615f32441
1 changed files with 22 additions and 3 deletions

View File

@ -36,6 +36,7 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QDialog> #include <QDialog>
#include <QMessageBox>
#include <CGAL/Qt/GraphicsViewNavigation.h> #include <CGAL/Qt/GraphicsViewNavigation.h>
@ -455,17 +456,28 @@ public Q_SLOTS:
qobject_cast<Scene_polyhedron_selection_item*> qobject_cast<Scene_polyhedron_selection_item*>
(scene->item(scene->mainSelectionIndex())); (scene->item(scene->mainSelectionIndex()));
if(!sel_item) if(!sel_item)
{
QMessageBox::information(mw, "Error", "No selection found.");
return; return;
}
if(sel_item->selected_facets.empty()) if(sel_item->selected_facets.empty())
{ {
QMessageBox::information(mw, "Error", "No selected facets.");
cleanup(); cleanup();
return; return;
} }
if(!CGAL::is_closed(*sel_item->polyhedron())) if(!CGAL::is_closed(*sel_item->polyhedron()))
{ {
QMessageBox::information(mw, "Error", "The surface mesh must be closed.");
cleanup(); cleanup();
return; return;
} }
connect(sel_item, &Scene_polyhedron_selection_item::aboutToBeDestroyed, this,
[this](){
sel_item = nullptr;
});
if(visu_item) if(visu_item)
scene->erase(scene->item_id(visu_item)); scene->erase(scene->item_id(visu_item));
visu_item = nullptr; visu_item = nullptr;
@ -573,7 +585,10 @@ public Q_SLOTS:
Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3); Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3);
visu_item = new Scene_polylines_item; visu_item = new Scene_polylines_item;
connect(visu_item, &Scene_polylines_item::aboutToBeDestroyed, this,
[this](){
visu_item = nullptr;
});
// compute 3D coordinates // compute 3D coordinates
transfo = transfo =
@ -757,6 +772,8 @@ public Q_SLOTS:
} }
SMesh result; SMesh result;
if(!sel_item)
return;
CGAL::copy_face_graph(*sel_item->polyhedron(), result); CGAL::copy_face_graph(*sel_item->polyhedron(), result);
bool OK = PMP::corefine_and_compute_difference(result, text_mesh_complete, result); bool OK = PMP::corefine_and_compute_difference(result, text_mesh_complete, result);
@ -800,7 +817,8 @@ public Q_SLOTS:
textMesh = new Scene_surface_mesh_item(text_mesh); textMesh = new Scene_surface_mesh_item(text_mesh);
connect(textMesh, &Scene_surface_mesh_item::aboutToBeDestroyed, connect(textMesh, &Scene_surface_mesh_item::aboutToBeDestroyed,
this, [this](){ this, [this](){
textMesh = nullptr;}); textMesh = nullptr;
});
textMesh->setName("Extruded Text"); textMesh->setName("Extruded Text");
scene->addItem(textMesh); scene->addItem(textMesh);
} }
@ -907,7 +925,8 @@ private:
dock_widget->rot_slider->setValue(0); dock_widget->rot_slider->setValue(0);
translation = EPICK::Vector_2(0,0); translation = EPICK::Vector_2(0,0);
uv_map_3.reset(); uv_map_3.reset();
graphics_scene->clear(); if(graphics_scene)
graphics_scene->clear();
if(sel_item) if(sel_item)
{ {
scene->erase(scene->item_id(sel_item)); scene->erase(scene->item_id(sel_item));