diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 48b37b5bc2c..5584b11e2ae 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1174,7 +1174,7 @@ void Scene::printVertexIds(CGAL::Three::Viewer_interface* viewer) Scene_item *it = item(mainSelectionIndex()); if(it) { - Scene_print_item_interface* item= dynamic_cast(it); + Scene_print_item_interface* item= qobject_cast(it); if(item) item->printVertexIds(viewer); } @@ -1186,7 +1186,7 @@ void Scene::printEdgeIds(CGAL::Three::Viewer_interface* viewer) if(it) { //Only call printEdgeIds if the item is a Scene_print_item_interface - Scene_print_item_interface* item= dynamic_cast(it); + Scene_print_item_interface* item= qobject_cast(it); if(item) item->printEdgeIds(viewer); } @@ -1198,7 +1198,7 @@ void Scene::printFaceIds(CGAL::Three::Viewer_interface* viewer) if(it) { //Only call printFaceIds if the item is a Scene_print_item_interface - Scene_print_item_interface* item= dynamic_cast(it); + Scene_print_item_interface* item= qobject_cast(it); if(item) item->printFaceIds(viewer); } @@ -1210,7 +1210,7 @@ void Scene::printAllIds(CGAL::Three::Viewer_interface* viewer) if(it) { //Only call printFaceIds if the item is a Scene_print_item_interface - Scene_print_item_interface* item= dynamic_cast(it); + Scene_print_item_interface* item= qobject_cast(it); if(item) item->printAllIds(viewer); } @@ -1219,7 +1219,7 @@ void Scene::updatePrimitiveIds(CGAL::Three::Viewer_interface* viewer, CGAL::Thre { if(it) { - Scene_print_item_interface* item= dynamic_cast(it); + Scene_print_item_interface* item= qobject_cast(it); if(item) { //As this function works as a toggle, the first call hides the ids and the second one shows them again, diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index 8f23a16c317..e6fae3a322e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -2421,9 +2421,15 @@ void Scene_polyhedron_item::zoomToId() viewer->camera()->position().z - viewer->camera()->sceneCenter().z) .norm() * normal ; - viewer->camera()->setSceneCenter(qglviewer::Vec(p.x(), - p.y(), +#if QGLVIEWER_VERSION >= 0x020502 + viewer->camera()->setPivotPoint(qglviewer::Vec(p.x(), + p.y(), p.z())); +#else + viewer->camera()->setRevolveAroundPoint(qglviewer::Vec(p.x(), + p.y(), + p.z())); +#endif viewer->moveCameraToCoordinates(QString("%1 %2 %3 %4 %5 %6 %7").arg(new_pos.x()) .arg(new_pos.y()) @@ -2435,3 +2441,7 @@ void Scene_polyhedron_item::zoomToId() } } } +bool Scene_polyhedron_item::shouldDisplayIds(CGAL::Three::Scene_item *current_item) const +{ + return this == current_item; +} diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h index 5e5eb272dc5..65da2c23513 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h @@ -137,6 +137,7 @@ public: bool printEdgeIds(CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE; bool printFaceIds(CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE; void printAllIds(CGAL::Three::Viewer_interface*) Q_DECL_OVERRIDE; + bool shouldDisplayIds(CGAL::Three::Scene_item *current_item) const Q_DECL_OVERRIDE; bool testDisplayId(double x, double y, double z, CGAL::Three::Viewer_interface*)const Q_DECL_OVERRIDE; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index 5831550c040..3119dbfac3a 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp @@ -2207,3 +2207,52 @@ void Scene_polyhedron_selection_item::selection_changed(bool b) viewer->setNoBinding(); } } + +void Scene_polyhedron_selection_item::printPrimitiveId(QPoint p, CGAL::Three::Viewer_interface* viewer) +{ +#ifndef USE_SURFACE_MESH + d->item->polyhedron_item()->printPrimitiveId(p, viewer); +#endif +} +bool Scene_polyhedron_selection_item::printVertexIds(CGAL::Three::Viewer_interface* viewer) const +{ +#ifndef USE_SURFACE_MESH + return d->item->polyhedron_item()->printVertexIds(viewer); +#endif + return false; +} +bool Scene_polyhedron_selection_item::printEdgeIds(CGAL::Three::Viewer_interface* viewer) const +{ +#ifndef USE_SURFACE_MESH + d->item->polyhedron_item()->printEdgeIds(viewer); +#endif + return false; +} +bool Scene_polyhedron_selection_item::printFaceIds(CGAL::Three::Viewer_interface* viewer) const +{ +#ifndef USE_SURFACE_MESH + return d->item->polyhedron_item()->printFaceIds(viewer); +#endif + return false; +} +void Scene_polyhedron_selection_item::printAllIds(CGAL::Three::Viewer_interface* viewer) +{ +#ifndef USE_SURFACE_MESH + d->item->polyhedron_item()->printAllIds(viewer); +#endif +} +bool Scene_polyhedron_selection_item::testDisplayId(double x, double y, double z, CGAL::Three::Viewer_interface* viewer)const +{ +#ifndef USE_SURFACE_MESH + return d->item->polyhedron_item()->testDisplayId(x, y, z, viewer); +#endif + return false; +} + +bool Scene_polyhedron_selection_item::shouldDisplayIds(CGAL::Three::Scene_item *current_item) const +{ +#ifndef USE_SURFACE_MESH + return d->item->polyhedron_item() == current_item; +#endif + return false; +} diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 9279a9d1e10..ac0b35f8434 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -17,6 +17,8 @@ #include #include #include +#include + #include "Polyhedron_demo_detect_sharp_edges.h" // Laurent Rineau, 2016/04/07: that header should not be included here, but @@ -201,9 +203,12 @@ struct Selection_traits #include +#include +#include "Scene_polyhedron_selection_item.h" void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer) { QPainter *painter = viewer->getPainter(); @@ -9,7 +11,12 @@ void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer) qglviewer::Camera* camera = viewer->camera(); //Display the items textItems Q_FOREACH(TextListItem* list, textItems) - if(list->item() == scene->item(scene->mainSelectionIndex())) + { + CGAL::Three::Scene_print_item_interface* item = + qobject_cast(scene->item(scene->mainSelectionIndex())); + if( item && + item->shouldDisplayIds(list->item()) + ) Q_FOREACH(TextItem* item, list->textList()) { qglviewer::Vec src(item->position().x(), item->position().y(),item->position().z()); @@ -31,6 +38,7 @@ void TextRenderer::draw(CGAL::Three::Viewer_interface *viewer) painter->drawText(rect, item->text()); } } + } //Display the local TextItems Q_FOREACH(TextItem* item, local_textItems) diff --git a/Three/include/CGAL/Three/Scene_print_item_interface.h b/Three/include/CGAL/Three/Scene_print_item_interface.h index 0c5c866529a..16ad2329219 100644 --- a/Three/include/CGAL/Three/Scene_print_item_interface.h +++ b/Three/include/CGAL/Three/Scene_print_item_interface.h @@ -27,6 +27,7 @@ namespace CGAL { namespace Three { class Viewer_interface; + class Scene_item; //! An item that wants to print its primitive IDs must derive from this interface. @@ -56,6 +57,14 @@ public: //! \returns true if the Id should be displayed //! \returns false if the Id should not be displayed (if it is hidden for example) virtual bool testDisplayId(double, double, double, CGAL::Three::Viewer_interface*)const = 0; + + //! \brief Tests if this item should display its ids. + //! + //! The default behavior is to only display ids of the currently selected item (\see mainSelectionIndex()). + //! This function allows to override this behavior. + //! @param tets_item the currently tested TextListItem. + //! \return true if this item should display its ids when `test_item` is tested. + virtual bool shouldDisplayIds(CGAL::Three::Scene_item* test_item)const = 0; }; } }