From f03b2e80d0a599b3db0ca6accfd698e1b8e73610 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 15 Nov 2012 11:17:59 +0100 Subject: [PATCH] 0000869: Mousepointer does not track to line endpoint in sketches attached to copied or imported sketches. --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 42 ++++++++++++++++++--- src/Mod/Sketcher/Gui/ViewProviderSketch.h | 4 ++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index eb68aa346..bc92ce708 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -326,6 +326,36 @@ void ViewProviderSketch::snapToGrid(double &x, double &y) } } +void ViewProviderSketch::getProjectingLine(const SbVec2s& pnt, const Gui::View3DInventorViewer *viewer, SbLine& line) const +{ + const SbViewportRegion& vp = viewer->getViewportRegion(); + + short x,y; pnt.getValue(x,y); + SbVec2f siz = vp.getViewportSize(); + float dX, dY; siz.getValue(dX, dY); + + float fRatio = vp.getViewportAspectRatio(); + float pX = (float)x / float(vp.getViewportSizePixels()[0]); + float pY = (float)y / float(vp.getViewportSizePixels()[1]); + + // now calculate the real points respecting aspect ratio information + // + if (fRatio > 1.0f) { + pX = (pX - 0.5f*dX) * fRatio + 0.5f*dX; + } + else if (fRatio < 1.0f) { + pY = (pY - 0.5f*dY) / fRatio + 0.5f*dY; + } + + SoCamera* pCam = viewer->getCamera(); + if (!pCam) return; + SbViewVolume vol = pCam->getViewVolume(); + + float focalDist = pCam->focalDistance.getValue(); + + vol.projectPointToLine(SbVec2f(pX,pY), line); +} + void ViewProviderSketch::getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal) { // Plane form @@ -360,8 +390,10 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe assert(edit); // Calculate 3d point to the mouse position - SbVec3f point = viewer->getPointOnScreen(cursorPos); - SbVec3f normal = viewer->getViewDirection(); + SbLine line; + getProjectingLine(cursorPos, viewer, line); + SbVec3f point = line.getPosition(); + SbVec3f normal = line.getDirection(); // use scoped_ptr to make sure that instance gets deleted in all cases boost::scoped_ptr pp(this->getPointOnRay(cursorPos, viewer)); @@ -774,11 +806,11 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor assert(edit); // Calculate 3d point to the mouse position - SbVec3f point = viewer->getPointOnScreen(cursorPos); - SbVec3f normal = viewer->getViewDirection(); + SbLine line; + getProjectingLine(cursorPos, viewer, line); double x,y; - getCoordsOnSketchPlane(x,y,point,normal); + getCoordsOnSketchPlane(x,y,line.getPosition(),line.getDirection()); snapToGrid(x, y); bool preselectChanged; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 5749873a2..ecf41d89d 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -35,6 +35,7 @@ class TopoDS_Shape; class TopoDS_Face; class SoSeparator; +class SbLine; class SbVec3f; class SoCoordinate3; class SoPointSet; @@ -134,6 +135,9 @@ public: /// give the coordinates of a line on the sketch plane in sketcher (2D) coordinates void getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal); + /// give projecting line of position + void getProjectingLine(const SbVec2s&, const Gui::View3DInventorViewer *viewer, SbLine&) const; + /// helper to detect preselection bool detectPreselection(const SoPickedPoint *Point, int &PtIndex,int &GeoIndex, int &ConstrIndex, int &CrossIndex);