From 787a37be82640cdf6bd8498a533d29af4fc65cbd Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 12 Dec 2022 16:41:58 +0100 Subject: [PATCH] Gui: fix View3DInventorViewer's getViewProviderByPath, getViewProviderByPathFromTail, getViewProvidersOfType The View3DInventorViewer only contains the top-level view providers which caused unexpected behaviour when using the three methods above. Thus, in client code they haven't been used any more. Now the methods internally invoke the corresponding methods of the document. This allows it in client code to directly call the appropriate methods again (LoD). --- src/Gui/View3DInventorViewer.cpp | 41 ++++--------------- src/Gui/View3DPy.cpp | 8 +--- .../Inspection/Gui/ViewProviderInspection.cpp | 4 +- src/Mod/Mesh/Gui/MeshSelection.cpp | 2 +- src/Mod/Mesh/Gui/ViewProvider.cpp | 22 +++++----- src/Mod/Mesh/Gui/ViewProviderCurvature.cpp | 4 +- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 2 +- src/Mod/Points/Gui/ViewProvider.cpp | 2 +- 8 files changed, 29 insertions(+), 56 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 4438a37348..3e87861603 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -3365,46 +3365,23 @@ void View3DInventorViewer::removeEventCallback(SoType eventtype, SoEventCallback ViewProvider* View3DInventorViewer::getViewProviderByPath(SoPath* path) const { - for (int i = 0; i < path->getLength(); i++) { - SoNode* node = path->getNode(i); - - if (node->isOfType(SoSeparator::getClassTypeId())) { - auto it = _ViewProviderMap.find(static_cast(node)); - if (it != _ViewProviderMap.end()) { - return it->second; - } - } - } - return nullptr; + if (!guiDocument) + return nullptr; + return guiDocument->getViewProviderByPathFromHead(path); } ViewProvider* View3DInventorViewer::getViewProviderByPathFromTail(SoPath* path) const { - // Make sure I'm the lowest LocHL in the pick path! - for (int i = 0; i < path->getLength(); i++) { - SoNode* node = path->getNodeFromTail(i); - - if (node->isOfType(SoSeparator::getClassTypeId())) { - std::map::const_iterator it = _ViewProviderMap.find(static_cast(node)); - if (it != _ViewProviderMap.end()) { - return it->second; - } - } - } - - return nullptr; + if (!guiDocument) + return nullptr; + return guiDocument->getViewProviderByPathFromTail(path); } std::vector View3DInventorViewer::getViewProvidersOfType(const Base::Type& typeId) const { - std::vector views; - for (std::set::const_iterator it = _ViewProviderSet.begin(); it != _ViewProviderSet.end(); ++it) { - if ((*it)->getTypeId().isDerivedFrom(typeId)) { - views.push_back(*it); - } - } - - return views; + if (!guiDocument) + return {}; + return guiDocument->getViewProvidersOfType(typeId); } void View3DInventorViewer::turnAllDimensionsOn() diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index d681a964ef..1c8f8bd29a 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -1469,9 +1469,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) dict.setItem("y", Py::Float(pt[1])); dict.setItem("z", Py::Float(pt[2])); - Gui::Document* doc = getView3DIventorPtr()->getViewer()->getDocument(); - ViewProvider *vp = doc ? doc->getViewProviderByPathFromHead(Point->getPath()) - : getView3DIventorPtr()->getViewer()->getViewProviderByPath(Point->getPath()); + ViewProvider *vp = getView3DIventorPtr()->getViewer()->getViewProviderByPath(Point->getPath()); if (vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { if (!vp->isSelectable()) return ret; @@ -1570,7 +1568,6 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) action.apply(getView3DIventorPtr()->getViewer()->getSoRenderManager()->getSceneGraph()); const SoPickedPointList& pp = action.getPickedPointList(); - Gui::Document* doc = getView3DIventorPtr()->getViewer()->getDocument(); Py::Object ret = Py::None(); if (pp.getLength() > 0) { Py::List list; @@ -1582,8 +1579,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) dict.setItem("y", Py::Float(pt[1])); dict.setItem("z", Py::Float(pt[2])); - ViewProvider *vp = doc ? doc->getViewProviderByPathFromHead(point->getPath()) - : getView3DIventorPtr()->getViewer()->getViewProviderByPath(point->getPath()); + ViewProvider *vp = getView3DIventorPtr()->getViewer()->getViewProviderByPath(point->getPath()); if(vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { if(!vp->isSelectable()) continue; diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp index 53697347fc..2ee9f4e69f 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp @@ -537,7 +537,7 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) n->setHandled(); // check if we have picked one a node of the view provider we are insterested in - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) { ViewProviderInspection* that = static_cast(vp); QString info = that->inspectDistance(point); @@ -557,7 +557,7 @@ void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n) const SoPickedPointList& pps = action.getPickedPointList(); for (int i=0; igetDocument()->getViewProviderByPathFromTail(point->getPath()); + vp = view->getViewProviderByPathFromTail(point->getPath()); if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) { ViewProviderInspection* self = static_cast(vp); QString info = self->inspectDistance(point); diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index a944d0cfbc..9c526a5908 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -548,7 +548,7 @@ void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) return; ViewProviderMesh* mesh = static_cast(vp); diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 36ca0e991f..d9f41ddf84 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -969,7 +969,7 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n) if (clPoly.front() != clPoly.back()) clPoly.push_back(clPoly.front()); - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); if (!views.empty()) { Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Cut")); bool commitCommand = false; @@ -1030,7 +1030,7 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n) if (clPoly.front() != clPoly.back()) clPoly.push_back(clPoly.front()); - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); if (!views.empty()) { Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Trim")); bool commitCommand = false; @@ -1112,7 +1112,7 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb) Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Split")); try { - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { ViewProviderMesh* that = static_cast(*it); if (that->getEditingMode() > -1) { @@ -1176,7 +1176,7 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb) Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Segment")); try { - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { ViewProviderMesh* that = static_cast(*it); if (that->getEditingMode() > -1) { @@ -1241,7 +1241,7 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n) if (h<0) h = -h; std::vector views; - views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { ViewProviderMesh* that = static_cast(*it); if (that->getEditingMode() > -1) { @@ -1637,7 +1637,7 @@ void ViewProviderMesh::faceInfoCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) return; @@ -1711,7 +1711,7 @@ void ViewProviderMesh::fillHoleCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) return; ViewProviderMesh* that = static_cast(vp); @@ -1746,20 +1746,20 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) view->setSelectionEnabled(true); view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), markPartCallback,ud); - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { static_cast(*it)->clearSelection(); } } else if (cf == id) { - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { static_cast(*it)->clearSelection(); } } else if (rm == id) { Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Delete")); - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { static_cast(*it)->deleteSelection(); } @@ -1778,7 +1778,7 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n) // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) return; ViewProviderMesh* that = static_cast(vp); diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index e16cfb49f8..3a835f3a41 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -518,7 +518,7 @@ void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) return; ViewProviderMeshCurvature* self = static_cast(vp); @@ -552,7 +552,7 @@ void ViewProviderMeshCurvature::curvatureInfoCallback(void * ud, SoEventCallback // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMeshCurvature::getClassTypeId())) return; ViewProviderMeshCurvature* that = static_cast(vp); diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index 3ec8775549..13c38b843e 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -600,7 +600,7 @@ void CurveOnMeshHandler::Private::vertexCallback(void * ud, SoEventCallback * cb if (pp) { CurveOnMeshHandler* self = static_cast(ud); if (!self->d_ptr->wireClosed) { - Gui::ViewProvider* vp = view->getDocument()->getViewProviderByPathFromTail(pp->getPath()); + Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(pp->getPath()); if (vp && vp->getTypeId().isDerivedFrom(MeshGui::ViewProviderMesh::getClassTypeId())) { MeshGui::ViewProviderMesh* mesh = static_cast(vp); const SoDetail* detail = pp->getDetail(); diff --git a/src/Mod/Points/Gui/ViewProvider.cpp b/src/Mod/Points/Gui/ViewProvider.cpp index 8167da2e91..4fc30f6e01 100644 --- a/src/Mod/Points/Gui/ViewProvider.cpp +++ b/src/Mod/Points/Gui/ViewProvider.cpp @@ -326,7 +326,7 @@ void ViewProviderPoints::clipPointsCallback(void *, SoEventCallback * n) if (clPoly.front() != clPoly.back()) clPoly.push_back(clPoly.front()); - std::vector views = view->getDocument()->getViewProvidersOfType(ViewProviderPoints::getClassTypeId()); + std::vector views = view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId()); for (std::vector::iterator it = views.begin(); it != views.end(); ++it) { ViewProviderPoints* that = static_cast(*it); if (that->getEditingMode() > -1) {