From 7149cce90f04b0dbe259b0548dd2691e26d2938f Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 27 Dec 2014 17:50:37 +0100 Subject: [PATCH] + fixes #0000957: Sketch view problem when go to edit --- src/Gui/NavigationStyle.cpp | 1 + src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 06d89b3a1..acbaea135 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -440,6 +440,7 @@ void NavigationStyle::setCameraOrientation(const SbRotation& rot, SbBool moveToC // due to possible round-off errors make sure that the // exact orientation is set cam->orientation.setValue(rot); + cam->position = PRIVATE(this)->focal2 - cam->focalDistance.getValue() * direction; } } else { diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index aec44b923..c1404acfa 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -4339,6 +4339,27 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo Base::Rotation tmp(plm.getRotation()); SbRotation rot((float)tmp[0],(float)tmp[1],(float)tmp[2],(float)tmp[3]); + + // Will the sketch be visible from the new position (#0000957)? + // + SoCamera* camera = viewer->getSoRenderManager()->getCamera(); + SbVec3f curdir; // current view direction + camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), curdir); + SbVec3f focal = camera->position.getValue() + + camera->focalDistance.getValue() * curdir; + + SbVec3f newdir; // future view direction + rot.multVec(SbVec3f(0, 0, -1), newdir); + SbVec3f newpos = focal - camera->focalDistance.getValue() * newdir; + + SbVec3f plnpos = Base::convertTo(plm.getPosition()); + double dist = (plnpos - newpos).dot(newdir); + if (dist < 0) { + float focalLength = camera->focalDistance.getValue() - dist + 5; + camera->position = focal - focalLength * curdir; + camera->focalDistance.setValue(focalLength); + } + viewer->setCameraOrientation(rot); viewer->setEditing(TRUE);