From 30bd6345f549f322cc82193c7effbf61af65472e Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 7 Sep 2019 16:31:01 +0300 Subject: [PATCH] Gui: add preference to set 3d view scale for new documents + change default view orientation to Trimetric. --- src/Gui/DlgSettings3DView.ui | 94 ++++++++++++++++++++++---------- src/Gui/DlgSettings3DViewImp.cpp | 4 +- src/Gui/View3DPy.cpp | 40 ++++++++++++-- 3 files changed, 105 insertions(+), 33 deletions(-) diff --git a/src/Gui/DlgSettings3DView.ui b/src/Gui/DlgSettings3DView.ui index 48469bbdac..af0ac5f2e0 100644 --- a/src/Gui/DlgSettings3DView.ui +++ b/src/Gui/DlgSettings3DView.ui @@ -7,7 +7,7 @@ 0 0 477 - 630 + 763 @@ -202,23 +202,6 @@ will be shown at the lower left in opened files - - - - 3D Navigation - - - - - - - Navigation settings set - - - -1 - - - @@ -232,10 +215,10 @@ will be shown at the lower left in opened files - - + + - Orbit style + Anti-Aliasing @@ -261,13 +244,6 @@ Turntable: the part will be rotated around the z-axis. - - - - Anti-Aliasing - - - @@ -313,6 +289,30 @@ Turntable: the part will be rotated around the z-axis. + + + + Navigation settings set + + + -1 + + + + + + + Orbit style + + + + + + + 3D Navigation + + + @@ -320,6 +320,38 @@ Turntable: the part will be rotated around the z-axis. + + + + New document scale + + + + + + + Sets camera zoom for new documents. The value is the diameter of the sphere to fit on the screen. + + + mm + + + 0.000010000000000 + + + 10000000.000000000000000 + + + NewDocumentCameraScale + + + View + + + 100.000000000000000 + + + @@ -787,6 +819,12 @@ bounding box size of the 3D object that is currently displayed. QDoubleSpinBox
Gui/PrefWidgets.h
+ + PrefUnitSpinBox + QWidget +
Gui/PrefWidgets.h
+ 1 +
CheckBox_CornerCoordSystem diff --git a/src/Gui/DlgSettings3DViewImp.cpp b/src/Gui/DlgSettings3DViewImp.cpp index 7b088b594d..7b79404b00 100644 --- a/src/Gui/DlgSettings3DViewImp.cpp +++ b/src/Gui/DlgSettings3DViewImp.cpp @@ -110,6 +110,7 @@ void DlgSettings3DViewImp::saveSettings() sliderIntensity->onSave(); radioPerspective->onSave(); radioOrthographic->onSave(); + qspinNewDocScale->onSave(); QVariant camera = comboNewDocView->itemData(comboNewDocView->currentIndex(), Qt::UserRole); hGrp->SetASCII("NewDocumentCameraOrientation", (const char*)camera.toByteArray()); @@ -140,6 +141,7 @@ void DlgSettings3DViewImp::loadSettings() sliderIntensity->onRestore(); radioPerspective->onRestore(); radioOrthographic->onRestore(); + qspinNewDocScale->onRestore(); ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); @@ -185,7 +187,7 @@ void DlgSettings3DViewImp::loadSettings() comboNewDocView->addItem(tr("Rear"), QByteArray("Rear")); comboNewDocView->addItem(tr("Bottom"), QByteArray("Bottom")); comboNewDocView->addItem(tr("Custom"), QByteArray("Custom")); - std::string camera = hGrp->GetASCII("NewDocumentCameraOrientation", "Top"); + std::string camera = hGrp->GetASCII("NewDocumentCameraOrientation", "Trimetric"); index = comboNewDocView->findData(QByteArray(camera.c_str())); if (index > -1) comboNewDocView->setCurrentIndex(index); if (camera == "Custom") { diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index a1d8793fbb..974f310838 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -94,7 +94,16 @@ void View3DInventorPy::init_type() add_varargs_method("viewIsometric",&View3DInventorPy::viewIsometric,"viewIsometric()"); add_varargs_method("viewDimetric",&View3DInventorPy::viewDimetric,"viewDimetric()"); add_varargs_method("viewTrimetric",&View3DInventorPy::viewTrimetric,"viewTrimetric()"); - add_varargs_method("viewDefaultOrientation",&View3DInventorPy::viewDefaultOrientation,"viewDefaultOrientation()"); + add_varargs_method("viewDefaultOrientation",&View3DInventorPy::viewDefaultOrientation, + "viewDefaultOrientation(ori_str = '', scale = -1.0): sets camera rotation to a predefined one, \n" + "and camera position and zoom to show certain amount of model space. \n" + "ori_string can be 'Top', 'Bottom', 'Front', 'Rear', 'Left', 'Right', \n" + "'Isometric', 'Dimetric', 'Trimetric', 'Custom'. If empty, the value is \n" + "fetched from Parameters.\n" + "scale sets distance from camera to origin, and height of the screen in \n" + "model space, so that a sphere of diameter fits the height of the\n" + "viewport. If zero, scaling is not done. If negative, the value is \n" + "fetched from Parameters."); add_varargs_method("viewRotateLeft",&View3DInventorPy::viewRotateLeft,"viewRotateLeft()"); add_varargs_method("viewRotateRight",&View3DInventorPy::viewRotateRight,"viewRotateRight()"); add_varargs_method("zoomIn",&View3DInventorPy::zoomIn,"zoomIn()"); @@ -639,7 +648,8 @@ Py::Object View3DInventorPy::viewTrimetric(const Py::Tuple& args) Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args) { char* view = nullptr; - if (!PyArg_ParseTuple(args.ptr(), "|s", &view)) + double scale = -1.0; + if (!PyArg_ParseTuple(args.ptr(), "|sd", &view, &scale)) throw Py::Exception(); try { @@ -650,7 +660,7 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args) } else { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - newDocView = hGrp->GetASCII("NewDocumentCameraOrientation", "Top"); + newDocView = hGrp->GetASCII("NewDocumentCameraOrientation", "Trimetric"); } if (newDocView == "Top") { @@ -689,7 +699,29 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args) rot.setValue(q0, q1, q2, q3); } - _view->getViewer()->setCameraOrientation(rot); + SoCamera* cam = _view->getViewer()->getCamera(); + cam->orientation = rot; + + if (scale < 0.0){ + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + scale = hGrp->GetFloat("NewDocumentCameraScale",100.0); + } + if (scale > 1e-7) { + double f = 0.0; //focal dist + if (cam->isOfType(SoOrthographicCamera::getClassTypeId())){ + static_cast(cam)->height = scale; + f = scale; + } else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())){ + //nothing to do + double ang = static_cast(cam)->heightAngle.getValue(); + f = 0.5 * scale / sin(ang * 0.5); + } + SbVec3f lookDir; + rot.multVec(SbVec3f(0,0,-1), lookDir); + SbVec3f pos = lookDir * -f; + cam->focalDistance = f; + cam->position = pos; + } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what());