fix sketch editing within transformed parts

This commit is contained in:
Stefan Tröger
2015-05-26 07:01:29 +02:00
parent e7284ecde8
commit a8f27937de
3 changed files with 83 additions and 8 deletions

View File

@@ -32,6 +32,8 @@
# include <Inventor/nodes/SoCamera.h>
# include <Inventor/events/SoMouseButtonEvent.h>
# include <Inventor/events/SoLocation2Event.h>
# include <Inventor/actions/SoGetMatrixAction.h>
# include <Inventor/actions/SoSearchAction.h>
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......
@@ -379,16 +381,32 @@ PyObject* ViewProvider::getPyObject()
SoPickedPoint* ViewProvider::getPointOnRay(const SbVec2s& pos, const View3DInventorViewer* viewer) const
{
// for convenience make a pick ray action to get the (potentially) picked entity in the provider
//first get the path to this node and calculate the current transformation
SoSearchAction sa;
sa.setNode(pcRoot);
sa.setSearchingAll(true);
sa.apply(viewer->getSoRenderManager()->getSceneGraph());
SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion());
gm.apply(sa.getPath());
SoTransform* trans = new SoTransform;
trans->setMatrix(gm.getMatrix());
trans->ref();
// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated
// transformation
SoSeparator* root = new SoSeparator;
root->ref();
root->addChild(viewer->getSoRenderManager()->getCamera());
root->addChild(trans);
root->addChild(pcRoot);
//get the picked point
SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion());
rp.setPoint(pos);
rp.apply(root);
root->unref();
trans->unref();
SoPickedPoint* pick = rp.getPickedPoint();
return (pick ? new SoPickedPoint(*pick) : 0);
@@ -398,9 +416,33 @@ SoPickedPoint* ViewProvider::getPointOnRay(const SbVec3f& pos,const SbVec3f& dir
{
// Note: There seems to be a bug with setRay() which causes SoRayPickAction
// to fail to get intersections between the ray and a line
//first get the path to this node and calculate the current setTransformation
SoSearchAction sa;
sa.setNode(pcRoot);
sa.setSearchingAll(true);
sa.apply(viewer->getSoRenderManager()->getSceneGraph());
SoGetMatrixAction gm(viewer->getSoRenderManager()->getViewportRegion());
gm.apply(sa.getPath());
// build a temporary scenegraph only keeping this viewproviders nodes and the accumulated
// transformation
SoTransform* trans = new SoTransform;
trans->ref();
trans->setMatrix(gm.getMatrix());
SoSeparator* root = new SoSeparator;
root->ref();
root->addChild(viewer->getSoRenderManager()->getCamera());
root->addChild(trans);
root->addChild(pcRoot);
//get the picked point
SoRayPickAction rp(viewer->getSoRenderManager()->getViewportRegion());
rp.setRay(pos,dir);
rp.apply(pcRoot);
rp.apply(root);
root->unref();
trans->unref();
// returns a copy of the point
SoPickedPoint* pick = rp.getPickedPoint();