Gui: add preference to set 3d view scale for new documents

+ change default view orientation to Trimetric.
This commit is contained in:
DeepSOIC
2019-09-07 16:31:01 +03:00
committed by wmayer
parent 81808b1f5c
commit 30bd6345f5
3 changed files with 105 additions and 33 deletions

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>477</width>
<height>630</height>
<height>763</height>
</rect>
</property>
<property name="windowTitle">
@@ -202,23 +202,6 @@ will be shown at the lower left in opened files</string>
</item>
<item>
<layout class="QGridLayout" name="gridLayout2">
<item row="0" column="0">
<widget class="QLabel" name="navigationLabel">
<property name="text">
<string>3D Navigation</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboNavigationStyle">
<property name="toolTip">
<string>Navigation settings set</string>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mouseButton">
<property name="sizePolicy">
@@ -232,10 +215,10 @@ will be shown at the lower left in opened files</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="orbitLabel">
<item row="2" column="0">
<widget class="QLabel" name="aliasingLAbel">
<property name="text">
<string>Orbit style</string>
<string>Anti-Aliasing</string>
</property>
</widget>
</item>
@@ -261,13 +244,6 @@ Turntable: the part will be rotated around the z-axis.</string>
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="aliasingLAbel">
<property name="text">
<string>Anti-Aliasing</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefComboBox" name="comboAliasing">
<property name="toolTip">
@@ -313,6 +289,30 @@ Turntable: the part will be rotated around the z-axis.</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboNavigationStyle">
<property name="toolTip">
<string>Navigation settings set</string>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="orbitLabel">
<property name="text">
<string>Orbit style</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="navigationLabel">
<property name="text">
<string>3D Navigation</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboNewDocView">
<property name="toolTip">
@@ -320,6 +320,38 @@ Turntable: the part will be rotated around the z-axis.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>New document scale</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="PrefUnitSpinBox" name="qspinNewDocScale" native="true">
<property name="toolTip">
<string>Sets camera zoom for new documents. The value is the diameter of the sphere to fit on the screen.</string>
</property>
<property name="unit" stdset="0">
<string>mm</string>
</property>
<property name="minimum" stdset="0">
<double>0.000010000000000</double>
</property>
<property name="maximum" stdset="0">
<double>10000000.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<string>NewDocumentCameraScale</string>
</property>
<property name="prefPath" stdset="0">
<string>View</string>
</property>
<property name="rawValue" stdset="0">
<double>100.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -787,6 +819,12 @@ bounding box size of the 3D object that is currently displayed. </string>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>PrefUnitSpinBox</class>
<extends>QWidget</extends>
<header>Gui/PrefWidgets.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>CheckBox_CornerCoordSystem</tabstop>

View File

@@ -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") {

View File

@@ -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 <scale> 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<SoOrthographicCamera*>(cam)->height = scale;
f = scale;
} else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())){
//nothing to do
double ang = static_cast<SoPerspectiveCamera*>(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());