From 394ea471c6e25e820263ebe9acac6a77bacddccc Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 7 Apr 2017 10:22:40 +0200 Subject: [PATCH] perform auto view fit when creating body object on sketch creation --- src/Mod/PartDesign/Gui/Command.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index e62037e8bf..54622bbab3 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include @@ -44,6 +45,8 @@ #include #include #include +#include +#include #include @@ -477,6 +480,24 @@ void CmdPartDesignNewSketch::activated(int iMsg) Base::Console().Error("Failed to create a Body object"); return; } + + // The method 'SoCamera::viewBoundingBox' is still declared as protected in Coin3d versions + // older than 4.0. +#if COIN_MAJOR_VERSION >= 4 + // if no part feature was there then auto-adjust the camera + Gui::Document* guidoc = Gui::Application::Instance->getDocument(doc); + Gui::View3DInventor* view = guidoc ? qobject_cast(guidoc->getActiveView()) : nullptr; + if (view) { + SoCamera* camera = view->getViewer()->getCamera(); + SbViewportRegion vpregion = view->getViewer()->getViewportRegion(); + float aspectratio = vpregion.getViewportAspectRatio(); + + float size = Gui::ViewProviderOrigin::defaultSize(); + SbBox3f bbox; + bbox.setBounds(-size,-size,-size,size,size,size); + camera->viewBoundingBox(bbox, aspectratio, 1.0f); + } +#endif } // At this point, we have pcActiveBody