Support of customizeable zoom step and zoom-at-cursor

This commit is contained in:
wmayer 2012-02-20 19:52:56 +01:00
parent c69bb0999d
commit 2348a70d25
9 changed files with 139 additions and 38 deletions

View File

@ -257,17 +257,11 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
this->button3down = press;
break;
case SoMouseButtonEvent::BUTTON4:
if (this->invertZoom)
zoom(viewer->getCamera(), -0.05f);
else
zoom(viewer->getCamera(), 0.05f);
doZoom(viewer->getCamera(), TRUE, posn);
processed = TRUE;
break;
case SoMouseButtonEvent::BUTTON5:
if (this->invertZoom)
zoom(viewer->getCamera(), 0.05f);
else
zoom(viewer->getCamera(), -0.05f);
doZoom(viewer->getCamera(), FALSE, posn);
processed = TRUE;
break;
default:

View File

@ -286,17 +286,11 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev)
this->button3down = press;
break;
case SoMouseButtonEvent::BUTTON4:
if (this->invertZoom)
zoom(viewer->getCamera(), -0.05f);
else
zoom(viewer->getCamera(), 0.05f);
doZoom(viewer->getCamera(), TRUE, posn);
processed = TRUE;
break;
case SoMouseButtonEvent::BUTTON5:
if (this->invertZoom)
zoom(viewer->getCamera(), 0.05f);
else
zoom(viewer->getCamera(), -0.05f);
doZoom(viewer->getCamera(), FALSE, posn);
processed = TRUE;
break;
default:

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>477</width>
<height>442</height>
<height>495</height>
</rect>
</property>
<property name="windowTitle">
@ -25,7 +25,7 @@
<property name="title">
<string>3D View settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="CheckBox_CornerCoordSystem">
<property name="text">
@ -130,6 +130,65 @@
</layout>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxZoomAtCursor">
<property name="text">
<string>Zoom at cursor</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ZoomAtCursor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Zoom step</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="spinBoxZoomStep">
<property name="minimum">
<double>0.010000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>0.050000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>ZoomStep</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxInvertZoom">
<property name="text">
<string>Invert zoom</string>
@ -142,7 +201,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="Gui::PrefCheckBox" name="checkBoxAntiAliasing">
<property name="text">
<string>Enable anti-aliasing (slower)</string>
@ -155,7 +214,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="Line" name="line1">
<property name="frameShape">
<enum>QFrame::HLine</enum>
@ -168,7 +227,7 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<layout class="QHBoxLayout" name="eyedistanceLayout">
<property name="spacing">
<number>6</number>
@ -210,7 +269,7 @@
</item>
</layout>
</item>
<item row="8" column="0">
<item row="9" column="0">
<layout class="QGridLayout" name="backlightLayout">
<property name="margin">
<number>11</number>
@ -399,6 +458,8 @@
<tabstop>comboNavigationStyle</tabstop>
<tabstop>mouseButton</tabstop>
<tabstop>comboOrbitStyle</tabstop>
<tabstop>checkBoxZoomAtCursor</tabstop>
<tabstop>spinBoxZoomStep</tabstop>
<tabstop>checkBoxInvertZoom</tabstop>
<tabstop>checkBoxAntiAliasing</tabstop>
<tabstop>FloatSpinBox_EyeDistance</tabstop>

View File

@ -72,7 +72,9 @@ void DlgSettings3DViewImp::saveSettings()
int index = comboOrbitStyle->currentIndex();
hGrp->SetInt("OrbitStyle", index);
checkBoxZoomAtCursor->onSave();
checkBoxInvertZoom->onSave();
spinBoxZoomStep->onSave();
checkBoxAntiAliasing->onSave();
CheckBox_CornerCoordSystem->onSave();
CheckBox_ShowFPS->onSave();
@ -87,7 +89,9 @@ void DlgSettings3DViewImp::saveSettings()
void DlgSettings3DViewImp::loadSettings()
{
checkBoxZoomAtCursor->onRestore();
checkBoxInvertZoom->onRestore();
spinBoxZoomStep->onRestore();
checkBoxAntiAliasing->onRestore();
CheckBox_CornerCoordSystem->onRestore();
CheckBox_ShowFPS->onRestore();

View File

@ -251,17 +251,11 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
this->button3down = press;
break;
case SoMouseButtonEvent::BUTTON4:
if (this->invertZoom)
zoom(viewer->getCamera(), -0.05f);
else
zoom(viewer->getCamera(), 0.05f);
doZoom(viewer->getCamera(), TRUE, posn);
processed = TRUE;
break;
case SoMouseButtonEvent::BUTTON5:
if (this->invertZoom)
zoom(viewer->getCamera(), 0.05f);
else
zoom(viewer->getCamera(), -0.05f);
doZoom(viewer->getCamera(), FALSE, posn);
processed = TRUE;
break;
default:

View File

@ -215,6 +215,10 @@ void NavigationStyle::initialize()
this->altdown = FALSE;
this->invertZoom = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View")->GetBool("InvertZoom",false);
this->zoomAtCursor = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View")->GetBool("ZoomAtCursor",false);
this->zoomStep = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View")->GetFloat("ZoomSetp",0.05f);
}
void NavigationStyle::finalize()
@ -709,6 +713,33 @@ void NavigationStyle::zoomByCursor(const SbVec2f & thispos, const SbVec2f & prev
zoom(viewer->getCamera(), (thispos[1] - prevpos[1]) * 10.0f/*20.0f*/);
}
void NavigationStyle::doZoom(SoCamera* camera, SbBool forward, const SbVec2f& pos)
{
SbBool zoomAtCur = this->zoomAtCursor;
if (zoomAtCur) {
const SbViewportRegion & vp = viewer->getViewportRegion();
float ratio = vp.getViewportAspectRatio();
SbViewVolume vv = camera->getViewVolume(vp.getViewportAspectRatio());
SbPlane panplane = vv.getPlane(camera->focalDistance.getValue());
panCamera(viewer->getCamera(), ratio, panplane, SbVec2f(0.5,0.5), pos);
}
float value = this->zoomStep;
if (!forward)
value = -value;
if (this->invertZoom)
value = -value;
zoom(camera, value);
if (zoomAtCur) {
const SbViewportRegion & vp = viewer->getViewportRegion();
float ratio = vp.getViewportAspectRatio();
SbViewVolume vv = camera->getViewVolume(vp.getViewportAspectRatio());
SbPlane panplane = vv.getPlane(camera->focalDistance.getValue());
panCamera(viewer->getCamera(), ratio, panplane, pos, SbVec2f(0.5,0.5));
}
}
/** Uses the sphere sheet projector to map the mouseposition onto
* a 3D point and find a rotation from this and the last calculated point.
*/
@ -884,6 +915,21 @@ SbBool NavigationStyle::isZoomInverted() const
return this->invertZoom;
}
void NavigationStyle::setZoomStep(float val)
{
this->zoomStep = val;
}
void NavigationStyle::setZoomAtCursor(SbBool on)
{
this->zoomAtCursor = on;
}
SbBool NavigationStyle::isZoomAtCursor() const
{
return this->zoomAtCursor;
}
void NavigationStyle::startSelection(AbstractMouseSelection* mouse)
{
if (!mouse)

View File

@ -111,6 +111,9 @@ public:
void setZoomInverted(SbBool);
SbBool isZoomInverted() const;
void setZoomStep(float);
void setZoomAtCursor(SbBool);
SbBool isZoomAtCursor() const;
void updateAnimation();
void redraw();
@ -162,6 +165,7 @@ protected:
void panToCenter(const SbPlane & pplane, const SbVec2f & currpos);
void zoom(SoCamera * camera, float diffvalue);
void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos);
void doZoom(SoCamera * camera, SbBool forward, const SbVec2f& pos);
void spin(const SbVec2f & pointerpos);
SbBool doSpin();
@ -191,6 +195,8 @@ protected:
SbBool ctrldown, shiftdown, altdown;
SbBool button1down, button2down, button3down;
SbBool invertZoom;
SbBool zoomAtCursor;
float zoomStep;
/** @name Mouse model */
//@{

View File

@ -154,17 +154,11 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev)
this->setViewing(true);
break;
case SoKeyboardEvent::PAGE_UP:
if (this->invertZoom)
zoom(viewer->getCamera(), 0.05f);
else
zoom(viewer->getCamera(), -0.05f);
doZoom(viewer->getCamera(), TRUE, posn);
processed = TRUE;
break;
case SoKeyboardEvent::PAGE_DOWN:
if (this->invertZoom)
zoom(viewer->getCamera(), -0.05f);
else
zoom(viewer->getCamera(), 0.05f);
doZoom(viewer->getCamera(), FALSE, posn);
processed = TRUE;
break;
default:

View File

@ -276,6 +276,14 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M
bool on = rGrp.GetBool("InvertZoom", false);
_viewer->navigationStyle()->setZoomInverted(on);
}
else if (strcmp(Reason,"ZoomAtCursor") == 0) {
bool on = rGrp.GetBool("ZoomAtCursor", false);
_viewer->navigationStyle()->setZoomAtCursor(on);
}
else if (strcmp(Reason,"ZoomSetp") == 0) {
float val = rGrp.GetFloat("ZoomSetp", 0.0f);
_viewer->navigationStyle()->setZoomStep(val);
}
else if (strcmp(Reason,"EyeDistance") == 0) {
_viewer->setStereoOffset(rGrp.GetFloat("EyeDistance",65.0));
}