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).
This commit is contained in:
wmayer
2022-12-12 16:41:58 +01:00
parent 94787e8afa
commit 787a37be82
8 changed files with 29 additions and 56 deletions

View File

@@ -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<SoSeparator*>(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<SoSeparator*,ViewProvider*>::const_iterator it = _ViewProviderMap.find(static_cast<SoSeparator*>(node));
if (it != _ViewProviderMap.end()) {
return it->second;
}
}
}
return nullptr;
if (!guiDocument)
return nullptr;
return guiDocument->getViewProviderByPathFromTail(path);
}
std::vector<ViewProvider*> View3DInventorViewer::getViewProvidersOfType(const Base::Type& typeId) const
{
std::vector<ViewProvider*> views;
for (std::set<ViewProvider*>::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()

View File

@@ -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;

View File

@@ -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<ViewProviderInspection*>(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; i<pps.getLength(); ++i) {
const SoPickedPoint * point = pps[i];
vp = view->getDocument()->getViewProviderByPathFromTail(point->getPath());
vp = view->getViewProviderByPathFromTail(point->getPath());
if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) {
ViewProviderInspection* self = static_cast<ViewProviderInspection*>(vp);
QString info = self->inspectDistance(point);

View File

@@ -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<ViewProviderMesh*>(vp);

View File

@@ -969,7 +969,7 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
if (clPoly.front() != clPoly.back())
clPoly.push_back(clPoly.front());
std::vector<Gui::ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<Gui::ViewProvider*> 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<Gui::ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<Gui::ViewProvider*> 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<Gui::ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*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<Gui::ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
if (that->getEditingMode() > -1) {
@@ -1241,7 +1241,7 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n)
if (h<0) h = -h;
std::vector<Gui::ViewProvider*> views;
views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*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<ViewProviderMesh*>(vp);
@@ -1746,20 +1746,20 @@ void ViewProviderMesh::markPartCallback(void * ud, SoEventCallback * n)
view->setSelectionEnabled(true);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), markPartCallback,ud);
std::vector<ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*it)->clearSelection();
}
}
else if (cf == id) {
std::vector<ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*it)->clearSelection();
}
}
else if (rm == id) {
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Delete"));
std::vector<ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
std::vector<ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
for (std::vector<ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
static_cast<ViewProviderMesh*>(*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<ViewProviderMesh*>(vp);

View File

@@ -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<ViewProviderMeshCurvature*>(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<ViewProviderMeshCurvature*>(vp);

View File

@@ -600,7 +600,7 @@ void CurveOnMeshHandler::Private::vertexCallback(void * ud, SoEventCallback * cb
if (pp) {
CurveOnMeshHandler* self = static_cast<CurveOnMeshHandler*>(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<MeshGui::ViewProviderMesh*>(vp);
const SoDetail* detail = pp->getDetail();

View File

@@ -326,7 +326,7 @@ void ViewProviderPoints::clipPointsCallback(void *, SoEventCallback * n)
if (clPoly.front() != clPoly.back())
clPoly.push_back(clPoly.front());
std::vector<Gui::ViewProvider*> views = view->getDocument()->getViewProvidersOfType(ViewProviderPoints::getClassTypeId());
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderPoints::getClassTypeId());
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderPoints* that = static_cast<ViewProviderPoints*>(*it);
if (that->getEditingMode() > -1) {