From 29d7a375bc010fdefe97bfdd5e6bb0d27db53edc Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 14 Oct 2016 16:55:24 +0200 Subject: [PATCH] Restore the spheres, grid, intersections and CNC state when reloading a c3t3_item. --- Polyhedron/demo/Polyhedron/MainWindow.cpp | 5 +- .../demo/Polyhedron/Scene_c3t3_item.cpp | 56 +++++++++++++++++++ Polyhedron/demo/Polyhedron/Scene_c3t3_item.h | 9 ++- .../CGAL/Three/Scene_item_with_properties.h | 37 ++++++++++++ 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 Three/include/CGAL/Three/Scene_item_with_properties.h diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index f5b07baa9cb..f9005bbe10d 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -40,7 +40,7 @@ #include #include - +#include #include "ui_MainWindow.h" #include "ui_Preferences.h" #include "ui_Statistics_on_item_dialog.h" @@ -884,6 +884,9 @@ void MainWindow::reloadItem() { new_item->setColor(item->color()); new_item->setRenderingMode(item->renderingMode()); new_item->setVisible(item->visible()); + Scene_item_with_properties *property_item = dynamic_cast(new_item); + if(property_item) + property_item->copyProperties(item); new_item->invalidateOpenGLBuffers(); scene->replaceItem(item_index, new_item, true); item->deleteLater(); diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 511d178de0c..eaede41f713 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -390,6 +390,7 @@ struct Set_show_tetrahedra { Scene_c3t3_item_priv* priv; Set_show_tetrahedra(Scene_c3t3_item_priv* priv) : priv(priv) {} void operator()(bool b) { + qDebug()<<"coucou"; priv->show_tetrahedra = b; priv->item->show_intersection(b); } @@ -1483,11 +1484,23 @@ Scene_c3t3_item::setColor(QColor c) void Scene_c3t3_item::show_grid(bool b) { d->is_grid_shown = b; + Q_FOREACH(QAction* action, contextMenu()->actions()) + if(action->objectName() == "actionShowGrid") + { + action->setChecked(b); + break; + } itemChanged(); } void Scene_c3t3_item::show_spheres(bool b) { d->spheres_are_shown = b; + Q_FOREACH(QAction* action, contextMenu()->actions()) + if(action->objectName() == "actionShowSpheres") + { + action->setChecked(b); + break; + } if(b && !d->spheres) { d->spheres = new Scene_spheres_item(this, true); @@ -1509,6 +1522,12 @@ void Scene_c3t3_item::show_spheres(bool b) } void Scene_c3t3_item::show_intersection(bool b) { + Q_FOREACH(QAction* action, contextMenu()->actions()) + if(action->objectName() == "actionShowTets") + { + action->setChecked(b); + break; + } if(b && !d->intersection) { d->intersection = new Scene_intersection_item(this); @@ -1535,6 +1554,12 @@ void Scene_c3t3_item::show_intersection(bool b) void Scene_c3t3_item::show_cnc(bool b) { d->cnc_are_shown = b; + Q_FOREACH(QAction* action, contextMenu()->actions()) + if(action->objectName() == "actionShowCNC") + { + action->setChecked(b); + break; + } Q_EMIT redraw(); } @@ -1556,7 +1581,38 @@ void Scene_c3t3_item::setPosition(float x, float y, float z) { d->frame->setPosition(x, y, z); } +bool Scene_c3t3_item::has_spheres()const { return d->spheres_are_shown;} + +bool Scene_c3t3_item::has_grid()const { return d->is_grid_shown;} + +bool Scene_c3t3_item::has_cnc()const { return d->cnc_are_shown;} + +bool Scene_c3t3_item::has_tets()const { if(d->intersection) return true; else return false; } + void Scene_c3t3_item::setNormal(float x, float y, float z) { d->frame->setOrientation(x, y, z, 0.f); } + +void Scene_c3t3_item::copyProperties(Scene_item *item) +{ + Scene_c3t3_item* c3t3_item = qobject_cast(item); + if(!c3t3_item) + return; + d->frame->setPositionAndOrientation(c3t3_item->manipulatedFrame()->position(), + c3t3_item->manipulatedFrame()->orientation()); + + if(c3t3_item->has_tets()) + show_intersection(true); + + if(c3t3_item->has_spheres()) + show_spheres(true); + + + if(c3t3_item->has_cnc()) + show_cnc(true); + + show_grid(c3t3_item->has_grid()); + + +} #include "Scene_c3t3_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index 53284998e3d..e626abb197b 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -23,13 +23,14 @@ #include #include #include +#include struct Scene_c3t3_item_priv; class Scene_spheres_item; class Scene_intersection_item; using namespace CGAL::Three; class SCENE_C3T3_ITEM_EXPORT Scene_c3t3_item - : public Scene_group_item + : public Scene_group_item, public Scene_item_with_properties { Q_OBJECT public: @@ -64,6 +65,11 @@ public: bool manipulatable() const { return true; } + + bool has_spheres() const; + bool has_grid() const; + bool has_cnc() const; + bool has_tets() const; ManipulatedFrame* manipulatedFrame(); void setPosition(float x, float y, float z) ; @@ -108,6 +114,7 @@ public: void drawPoints(CGAL::Three::Viewer_interface * viewer) const; public: QMenu* contextMenu(); + void copyProperties(Scene_item *); public Q_SLOTS: void export_facets_in_complex(); diff --git a/Three/include/CGAL/Three/Scene_item_with_properties.h b/Three/include/CGAL/Three/Scene_item_with_properties.h new file mode 100644 index 00000000000..af708294799 --- /dev/null +++ b/Three/include/CGAL/Three/Scene_item_with_properties.h @@ -0,0 +1,37 @@ +// Copyright (c) 2016 GeometryFactory Sarl (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Maxime GIMENO + +#ifndef SCENE_ITEM_WITH_PROPERTIES_H +#define SCENE_ITEM_WITH_PROPERTIES_H +namespace CGAL +{ +namespace Three { + class Scene_item; + +//! Base class to allow an item to copy properties from another. +class Scene_item_with_properties { +public: + virtual ~Scene_item_with_properties(){} + //!Copies properties from another Scene_item + virtual void copyProperties(Scene_item*){} +}; +} +} +#endif // SCENE_ITEM_WITH_PROPERTIES_H +