Skip to content

Commit

Permalink
Add default element picking for container view provider
Browse files Browse the repository at this point in the history
Move default element picking code from
ViewProviderGeoFeatureGroupExtension to ViewProviderDocumentObject, so
that any view provider having a child root node gets the default
implementation. This fixes ViewProviderOrigin element picking.
  • Loading branch information
realthunder committed Jan 24, 2018
1 parent 759c866 commit 4715432
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 41 deletions.
53 changes: 53 additions & 0 deletions src/Gui/ViewProviderDocumentObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# include <Inventor/nodes/SoSwitch.h>
# include <Inventor/nodes/SoTransform.h>
# include <Inventor/actions/SoGetBoundingBoxAction.h>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/SoFullPath.h>
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......
Expand Down Expand Up @@ -378,3 +380,54 @@ Base::BoundBox3d ViewProviderDocumentObject::getBoundingBox() const {
bbox.getMin().getValue(minX,minY,minZ);
return Base::BoundBox3d(minX,minY,minZ,maxX,maxY,maxZ);
}

bool ViewProviderDocumentObject::getElementPicked(const SoPickedPoint *pp, std::string &subname) const
{
auto childRoot = getChildRoot();
if(!childRoot)
return ViewProvider::getElementPicked(pp,subname);

if(!isSelectable()) return false;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
if(ext->extensionGetElementPicked(pp,subname))
return true;

SoPath* path = pp->getPath();
auto idx = path->findNode(childRoot);
if(idx<0 || idx+1>=path->getLength())
return false;
auto vp = getDocument()->getViewProvider(path->getNode(idx+1));
if(!vp) return false;
auto obj = vp->getObject();
if(!obj || !obj->getNameInDocument())
return false;
std::ostringstream str;
str << obj->getNameInDocument() << '.';
if(vp->getElementPicked(pp,subname))
str << subname;
subname = str.str();
return true;
}

SoDetail *ViewProviderDocumentObject::getDetailPath(const char *subname, SoFullPath *path, bool append) const
{
auto det = ViewProvider::getDetailPath(subname,path,append);
if(det) return det;

auto childRoot = getChildRoot();
if(childRoot && subname) {
const char *dot = strchr(subname,'.');
if(!dot) return 0;
auto obj = getObject();
if(!obj || !obj->getNameInDocument()) return 0;
auto sobj = obj->getSubObject(std::string(subname,dot-subname+1).c_str());
if(!sobj) return 0;
auto vp = Application::Instance->getViewProvider(sobj);
if(!vp) return 0;
path->append(childRoot);
det = vp->getDetailPath(dot+1,path,true);
}
return det;
}

5 changes: 5 additions & 0 deletions src/Gui/ViewProviderDocumentObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class GuiExport ViewProviderDocumentObject : public ViewProvider
/// Get the python wrapper for that ViewProvider
PyObject* getPyObject();

/// return a hit element given the picked point which contains the full node path
virtual bool getElementPicked(const SoPickedPoint *, std::string &subname) const override;
/// return the coin node detail and path to the node of the subelement
virtual SoDetail* getDetailPath(const char *subelement, SoFullPath *pPath, bool append) const override;

/* Force update visual
*
* These method exists because some view provider skips visual update when
Expand Down
38 changes: 0 additions & 38 deletions src/Gui/ViewProviderGeoFeatureGroupExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include "Document.h"
#include <App/GeoFeatureGroupExtension.h>
#include <Inventor/nodes/SoGroup.h>
#include <Inventor/SoPickedPoint.h>
#include <Inventor/SoFullPath.h>

using namespace Gui;

Expand Down Expand Up @@ -133,42 +131,6 @@ void ViewProviderGeoFeatureGroupExtension::extensionUpdateData(const App::Proper
}
}

bool ViewProviderGeoFeatureGroupExtension::extensionGetElementPicked(
const SoPickedPoint *pp, std::string &subname) const
{
SoPath* path = pp->getPath();
auto idx = path->findNode(pcGroupChildren);
if(idx<0 || idx+1>=path->getLength())
return false;
auto vp = getExtendedViewProvider()->getDocument()->getViewProvider(path->getNode(idx+1));
if(!vp) return false;
auto obj = vp->getObject();
if(!obj || !obj->getNameInDocument())
return false;
std::ostringstream str;
str << obj->getNameInDocument() << '.';
if(vp->getElementPicked(pp,subname))
str << subname;
subname = str.str();
return true;
}

bool ViewProviderGeoFeatureGroupExtension::extensionGetDetailPath(
const char *subname, SoFullPath *path, SoDetail *&det) const
{
if(!subname) return false;
const char *dot = strchr(subname,'.');
if(!dot) return false;
auto obj = getExtendedViewProvider()->getObject();
auto sobj = obj->getSubObject(std::string(subname,dot-subname+1).c_str());
if(!sobj) return false;
auto vp = Application::Instance->getViewProvider(sobj);
if(!vp) return false;
path->append(pcGroupChildren);
det = vp->getDetailPath(dot+1,path,true);
return true;
}

namespace Gui {
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderGeoFeatureGroupExtensionPython, Gui::ViewProviderGeoFeatureGroupExtension)

Expand Down
3 changes: 0 additions & 3 deletions src/Gui/ViewProviderGeoFeatureGroupExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class GuiExport ViewProviderGeoFeatureGroupExtension : public ViewProviderGroupE

virtual void extensionUpdateData(const App::Property*) override;

virtual bool extensionGetElementPicked(const SoPickedPoint *, std::string &) const override;
virtual bool extensionGetDetailPath(const char *, SoFullPath *, SoDetail *&) const override;

protected:
SoGroup *pcGroupChildren;
};
Expand Down

0 comments on commit 4715432

Please sign in to comment.