diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index cfc4c2347..0b27ab2e0 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -26,15 +26,19 @@ # include # include # include +# include #endif #include #include #include +#include #include #include #include -#include +#include +#include +#include #include #include @@ -141,6 +145,7 @@ void CmdPartDesignBody::activated(int iMsg) std::vector features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); App::DocumentObject* baseFeature = nullptr; + bool viewAll = features.empty(); if (!features.empty()) { @@ -164,8 +169,8 @@ void CmdPartDesignBody::activated(int iMsg) QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Bad base feature"), QObject::tr("Body can't be based on annother body.")); baseFeature = nullptr; - } else { - + } + else { partOfBaseFeature = App::Part::getPartOfObject(baseFeature); if (partOfBaseFeature != 0 && partOfBaseFeature != actPart){ //prevent cross-part mess @@ -211,6 +216,21 @@ void CmdPartDesignBody::activated(int iMsg) actPart->getNameInDocument(), bodyName.c_str()); } + // if no part feature was there then auto-adjust the camera + if (viewAll) { + Gui::Document* doc = Gui::Application::Instance->getDocument(getDocument()); + Gui::View3DInventor* view = doc ? qobject_cast(doc->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); + } + } updateActive(); }