0000818: [PATCH] added new page to Customize dialog for space navigator

This commit is contained in:
wmayer 2012-09-06 14:09:43 +02:00
parent 629cf6546c
commit 2d172cde0b
6 changed files with 229 additions and 146 deletions

View File

@ -193,18 +193,21 @@ void Gui::GUIApplicationNativeEventAware::Move3d(HANDLE device, std::vector<floa
if (!currentWidget)
currentWidget = mainWindow;
int x, y, z, rx, ry, rz;
x = ceil(motionData[0])*(-1);
y = ceil(motionData[1]);
z = ceil(motionData[2]);
rx = ceil(motionData[3])*(-1);
ry = ceil(motionData[4]);
rz = ceil(motionData[5]);
motionDataArray[0] = ceil(motionData[0]);
motionDataArray[1] = ceil(motionData[1]);
motionDataArray[2] = ceil(motionData[2]);
motionDataArray[3] = ceil(motionData[3]);
motionDataArray[4] = ceil(motionData[4]);
motionDataArray[5] = ceil(motionData[5]);
if (!setOSIndependentMotionData()) return;
importSettings();
Spaceball::MotionEvent *motionEvent = new Spaceball::MotionEvent();
//motionEvent->setTranslations(x, y, z);
//motionEvent->setRotations(rx, ry, rz);
motionEvent->setMotionData(x, y, z, rx, ry, rz);
motionEvent->setTranslations(motionDataArray[0], motionDataArray[1], motionDataArray[2]);
motionEvent->setRotations(motionDataArray[3], motionDataArray[4], motionDataArray[5]);
this->postEvent(currentWidget, motionEvent);
}

View File

@ -555,7 +555,11 @@ void DlgCustomizeSpaceball::setMessage(const QString& message)
{
QLabel *messageLabel = new QLabel(message,this);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(messageLabel);
QHBoxLayout *layout2 = new QHBoxLayout();
layout2->addStretch();
layout2->addWidget(messageLabel);
layout2->addStretch();
layout->addItem(layout2);
this->setLayout(layout);
}

View File

@ -32,6 +32,7 @@
#include <Base/Console.h>
#include "GuiApplicationNativeEventAware.h"
#include "SpaceballEvent.h"
#include "Application.h"
//linux dependency libspnav-dev
#ifdef Q_WS_X11
@ -128,6 +129,184 @@ bool Gui::GUIApplicationNativeEventAware::processSpaceballEvent(QObject *object,
return true;
}
float Gui::GUIApplicationNativeEventAware::convertPrefToSensitivity(int value)
{
if (value < 0)
{
return ((0.9/50)*float(value) + 1);
}
else
{
return ((2.5/50)*float(value) + 1);
}
}
// This function modifies motionDataArray to be OS independent
// on some OSes these axes are inverted, and some are switched - this method sets them up like this:
// motionDataArray[0] - pan Left - Right with mouse - pan Left(Left) - Right(Left) on screen
// motionDataArray[1] - pan Front - Back with mouse - pan Up(Front) - Down(Back) on screen
// motionDataArray[2] - pan Up - Down with mouse - zoom In(Up) - Out(Down) on screen
// motionDataArray[3] - lean mouse Left-Right - rotate around Vertical axis on screen
// motionDataArray[4] - lean mouse Front - Back - rotate around Horizointal axis on screen on screen
// motionDataArray[5] - Spin mouse - rotate around "Zoom" axis on screen
bool Gui::GUIApplicationNativeEventAware::setOSIndependentMotionData()
{
#ifdef SPNAV_FOUND
int temp;
motionDataArray[0] = -motionDataArray[0];
motionDataArray[3] = -motionDataArray[3];
temp = motionDataArray[1];
motionDataArray[1] = -motionDataArray[2];
motionDataArray[2] = -temp;
temp = motionDataArray[4];
motionDataArray[4] = -motionDataArray[5];
motionDataArray[5] = -temp;
#elif _USE_3DCONNEXION_SDK
motionDataArray[0] = -motionDataArray[0];
motionDataArray[3] = -motionDataArray[3];
#else
return false;
#endif
return true;
}
void Gui::GUIApplicationNativeEventAware::importSettings()
{
ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Spaceball")->GetGroup("Motion");
// here I import settings from a dialog. For now they are set as is
bool dominant = group->GetBool("Dominant"); // Is dominant checked
bool flipXY = group->GetBool("FlipYZ");; // Is Flip X/Y checked
float generalSensitivity = convertPrefToSensitivity(group->GetInt("GlobalSensitivity"));
// array that has stored info about "Enabled" checkboxes of all axes
bool enabled[6];
enabled[0] = group->GetBool("Translations", true) && group->GetBool("PanLREnable", true);
enabled[1] = group->GetBool("Translations", true) && group->GetBool("PanUDEnable", true);
enabled[2] = group->GetBool("Translations", true) && group->GetBool("ZoomEnable", true);
enabled[3] = group->GetBool("Rotations", true) && group->GetBool("TiltEnable", true);
enabled[4] = group->GetBool("Rotations", true) && group->GetBool("RollEnable", true);
enabled[5] = group->GetBool("Rotations", true) && group->GetBool("SpinEnable", true);
// array that has stored info about "Reversed" checkboxes of all axes
bool reversed[6];
reversed[0] = group->GetBool("PanLRReverse");
reversed[1] = group->GetBool("PanUDReverse");
reversed[2] = group->GetBool("ZoomReverse");
reversed[3] = group->GetBool("TiltReverse");
reversed[4] = group->GetBool("RollReverse");
reversed[5] = group->GetBool("SpinReverse");
// array that has stored info about sliders - on each slider you need to use method DlgSpaceballSettings::GetValuefromSlider
// which will convert <-50, 50> linear integers from slider to <0.1, 10> exponential floating values
float sensitivity[6];
sensitivity[0] = convertPrefToSensitivity(group->GetInt("PanLRSensitivity"));
sensitivity[1] = convertPrefToSensitivity(group->GetInt("PanUDSensitivity"));
sensitivity[2] = convertPrefToSensitivity(group->GetInt("ZoomSensitivity"));
sensitivity[3] = convertPrefToSensitivity(group->GetInt("TiltSensitivity"));
sensitivity[4] = convertPrefToSensitivity(group->GetInt("RollSensitivity"));
sensitivity[5] = convertPrefToSensitivity(group->GetInt("SpinSensitivity"));
if (group->GetBool("Calibrate"))
{
group->SetInt("CalibrationX",motionDataArray[0]);
group->SetInt("CalibrationY",motionDataArray[1]);
group->SetInt("CalibrationZ",motionDataArray[2]);
group->SetInt("CalibrationXr",motionDataArray[3]);
group->SetInt("CalibrationYr",motionDataArray[4]);
group->SetInt("CalibrationZr",motionDataArray[5]);
group->RemoveBool("Calibrate");
return;
}
else
{
motionDataArray[0] = motionDataArray[0] - group->GetInt("CalibrationX");
motionDataArray[1] = motionDataArray[1] - group->GetInt("CalibrationY");
motionDataArray[2] = motionDataArray[2] - group->GetInt("CalibrationZ");
motionDataArray[3] = motionDataArray[3] - group->GetInt("CalibrationXr");
motionDataArray[4] = motionDataArray[4] - group->GetInt("CalibrationYr");
motionDataArray[5] = motionDataArray[5] - group->GetInt("CalibrationZr");
}
int i;
if (flipXY) {
bool tempBool;
float tempFloat;
tempBool = enabled[1];
enabled[1] = enabled[2];
enabled[2] = tempBool;
tempBool = enabled[4];
enabled[4] = enabled[5];
enabled[5] = tempBool;
tempBool = reversed[1];
reversed[1] = reversed[2];
reversed[2] = tempBool;
tempBool = reversed[4];
reversed[4] = reversed[5];
reversed[5] = tempBool;
tempFloat = sensitivity[1];
sensitivity[1] = sensitivity[2];
sensitivity[2] = tempFloat;
tempFloat = sensitivity[4];
sensitivity[4] = sensitivity[5];
sensitivity[5] = tempFloat;
i = motionDataArray[1];
motionDataArray[1] = motionDataArray[2];
motionDataArray[2] = - i;
i = motionDataArray[4];
motionDataArray[4] = motionDataArray[5];
motionDataArray[5] = - i;
}
if (dominant) { // if dominant is checked
int max = 0;
bool flag = false;
for (i = 0; i < 6; ++i) {
if (abs(motionDataArray[i]) > abs(max)) max = motionDataArray[i];
}
for (i = 0; i < 6; ++i) {
if ((motionDataArray[i] != max) || (flag)) {
motionDataArray[i] = 0;
} else if (motionDataArray[i] == max) {
flag = true;
}
}
}
for (i = 0; i < 6; ++i) {
if (motionDataArray[i] != 0) {
if (enabled[i] == false)
motionDataArray[i] = 0;
else {
if (reversed[i] == true)
motionDataArray[i] = - motionDataArray[i];
motionDataArray[i] = (int)((float)(motionDataArray[i]) * sensitivity[i] * generalSensitivity);
}
}
}
}
#ifdef Q_WS_X11
bool Gui::GUIApplicationNativeEventAware::x11EventFilter(XEvent *event)
{
@ -142,10 +321,21 @@ bool Gui::GUIApplicationNativeEventAware::x11EventFilter(XEvent *event)
if (navEvent.type == SPNAV_EVENT_MOTION)
{
motionDataArray[0] = navEvent.motion.x;
motionDataArray[1] = navEvent.motion.y;
motionDataArray[2] = navEvent.motion.z;
motionDataArray[3] = navEvent.motion.rx;
motionDataArray[4] = navEvent.motion.ry;
motionDataArray[5] = navEvent.motion.rz;
if (!setOSIndependentMotionData()) return false;
importSettings();
Spaceball::MotionEvent *motionEvent = new Spaceball::MotionEvent();
// motionEvent->setTranslations(navEvent.motion.x, navEvent.motion.y, navEvent.motion.z);
// motionEvent->setRotations(navEvent.motion.rx, navEvent.motion.ry, navEvent.motion.rz);
motionEvent->setMotionData(navEvent.motion.x, navEvent.motion.y, navEvent.motion.z, navEvent.motion.rx, navEvent.motion.ry, navEvent.motion.rz);
motionEvent->setTranslations(motionDataArray[0], motionDataArray[1], motionDataArray[2]);
motionEvent->setRotations(motionDataArray[3], motionDataArray[4], motionDataArray[5]);
this->postEvent(currentWidget, motionEvent);
return true;
}

View File

@ -36,7 +36,7 @@ class QMainWindow;
#include <vector>
#include <map>
// #define _WIN32_WINNT 0x0501 //target at least windows XP
//#define _WIN32_WINNT 0x0501 //target at least windows XP
#include <Windows.h>
@ -56,6 +56,10 @@ namespace Gui
private:
bool spaceballPresent;
QMainWindow *mainWindow;
int motionDataArray[6];
bool setOSIndependentMotionData();
void importSettings();
float convertPrefToSensitivity(int value);
// For X11
#ifdef Q_WS_X11

View File

@ -41,132 +41,15 @@ MotionEvent::MotionEvent() : EventBase(static_cast<QEvent::Type>(MotionEventType
MotionEvent::MotionEvent(const MotionEvent& in) : EventBase(static_cast<QEvent::Type>(MotionEventType))
{
int motionDataArray[6] = {in.xTrans, in.yTrans, in.zTrans, in.xRot, in.yRot, in.zRot};
importSettings(motionDataArray);
xTrans = in.xTrans;
yTrans = in.yTrans;
zTrans = in.zTrans;
xRot = in.xRot;
yRot = in.yRot;
zRot = in.zRot;
handled = in.handled;
}
float MotionEvent::convertPrefToSensitivity(int value)
{
if (value < 0)
{
return ((0.6/50)*float(value) + 1);
}
else
{
return ((1.1/50)*float(value) + 1);
}
}
void MotionEvent::importSettings(int* motionDataArray)
{
ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Spaceball")->GetGroup("Motion");
// here I import settings from a dialog. For now they are set as is
bool dominant = group->GetBool("Dominant"); // Is dominant checked
bool flipXY = group->GetBool("FlipYZ");; // Is Flip X/Y checked
float generalSensitivity = convertPrefToSensitivity(group->GetInt("GlobalSensitivity"));
// array that has stored info about "Enabled" checkboxes of all axes
bool enabled[6];
enabled[0] = group->GetBool("Translations", true) && group->GetBool("PanLREnable", true);
enabled[1] = group->GetBool("Translations", true) && group->GetBool("PanUDEnable", true);
enabled[2] = group->GetBool("Translations", true) && group->GetBool("ZoomEnable", true);
enabled[3] = group->GetBool("Rotations", true) && group->GetBool("TiltEnable", true);
enabled[4] = group->GetBool("Rotations", true) && group->GetBool("RollEnable", true);
enabled[5] = group->GetBool("Rotations", true) && group->GetBool("SpinEnable", true);
// array that has stored info about "Reversed" checkboxes of all axes
bool reversed[6];
reversed[0] = group->GetBool("PanLRReverse");
reversed[1] = group->GetBool("PanUDReverse");
reversed[2] = group->GetBool("ZoomReverse");
reversed[3] = group->GetBool("TiltReverse");
reversed[4] = group->GetBool("RollReverse");
reversed[5] = group->GetBool("SpinReverse");
// array that has stored info about sliders - on each slider you need to use method DlgSpaceballSettings::GetValuefromSlider
// which will convert <-50, 50> linear integers from slider to <0.1, 10> exponential floating values
float sensitivity[6];
sensitivity[0] = convertPrefToSensitivity(group->GetInt("PanLRSensitivity"));
sensitivity[1] = convertPrefToSensitivity(group->GetInt("PanUDSensitivity"));
sensitivity[2] = convertPrefToSensitivity(group->GetInt("ZoomSensitivity"));
sensitivity[3] = convertPrefToSensitivity(group->GetInt("TiltSensitivity"));
sensitivity[4] = convertPrefToSensitivity(group->GetInt("RollSensitivity"));
sensitivity[5] = convertPrefToSensitivity(group->GetInt("SpinSensitivity"));
int i;
if (group->GetBool("Calibrate"))
{
group->SetInt("CalibrationX",motionDataArray[0]);
group->SetInt("CalibrationY",motionDataArray[1]);
group->SetInt("CalibrationZ",motionDataArray[2]);
group->SetInt("CalibrationXr",motionDataArray[3]);
group->SetInt("CalibrationYr",motionDataArray[4]);
group->SetInt("CalibrationZr",motionDataArray[5]);
group->RemoveBool("Calibrate");
return;
}
else
{
motionDataArray[0] = motionDataArray[0] - group->GetInt("CalibrationX");
motionDataArray[1] = motionDataArray[1] - group->GetInt("CalibrationY");
motionDataArray[2] = motionDataArray[2] - group->GetInt("CalibrationZ");
motionDataArray[3] = motionDataArray[3] - group->GetInt("CalibrationXr");
motionDataArray[4] = motionDataArray[4] - group->GetInt("CalibrationYr");
motionDataArray[5] = motionDataArray[5] - group->GetInt("CalibrationZr");
}
if (dominant) { // if dominant is checked
int max = 0;
bool flag = false;
for (i = 0; i < 6; ++i) {
if (abs(motionDataArray[i]) > abs(max)) max = motionDataArray[i];
}
for (i = 0; i < 6; ++i) {
if ((motionDataArray[i] != max) || (flag)) {
motionDataArray[i] = 0;
} else if (motionDataArray[i] == max){
flag = true;
}
}
}
if (flipXY) {
int temp = motionDataArray[1];
motionDataArray[1] = motionDataArray[2];
motionDataArray[2] = - temp;
}
for (i = 0; i < 6; ++i) {
if (motionDataArray[i] != 0) {
if (enabled[i] == false)
motionDataArray[i] = 0;
else {
if (reversed[i] == true)
motionDataArray[i] = - motionDataArray[i];
motionDataArray[i] = (int)((float)(motionDataArray[i]) * sensitivity[i] * generalSensitivity);
}
}
}
xTrans = motionDataArray[0];
yTrans = motionDataArray[1];
zTrans = motionDataArray[2];
xRot = motionDataArray[3];
yRot = motionDataArray[4];
zRot = motionDataArray[5];
}
void MotionEvent::setMotionData(int &xTransIn, int &yTransIn, int &zTransIn, int &xRotIn, int &yRotIn, int &zRotIn){
int motionDataArray[6] = {xTransIn, yTransIn, zTransIn, xRotIn, yRotIn, zRotIn};
importSettings(motionDataArray);
}
void MotionEvent::translations(int &xTransOut, int &yTransOut, int &zTransOut)
{
xTransOut = xTrans;
@ -176,8 +59,9 @@ void MotionEvent::translations(int &xTransOut, int &yTransOut, int &zTransOut)
void MotionEvent::setTranslations(const int &xTransIn, const int &yTransIn, const int &zTransIn)
{
int motionDataArray[6] = {xTransIn, yTransIn, zTransIn, xRot, yRot, zRot};
importSettings(motionDataArray);
xTrans = xTransIn;
yTrans = yTransIn;
zTrans = zTransIn;
}
void MotionEvent::rotations(int &xRotOut, int &yRotOut, int &zRotOut)
@ -189,8 +73,9 @@ void MotionEvent::rotations(int &xRotOut, int &yRotOut, int &zRotOut)
void MotionEvent::setRotations(const int &xRotIn, const int &yRotIn, const int &zRotIn)
{
int motionDataArray[6] = {xTrans, yTrans, zTrans, xRotIn, yRotIn, zRotIn};
importSettings(motionDataArray);
xRot = xRotIn;
yRot = yRotIn;
zRot = zRotIn;
}

View File

@ -56,7 +56,6 @@ namespace Spaceball
int rotationY(){return yRot;}
int rotationZ(){return zRot;}
void setMotionData(int &xTransOut, int &yTransOut, int &zTransOut, int &xRotOut, int &yRotOut, int &zRotOut);
static int MotionEventType;
private:
@ -67,8 +66,6 @@ namespace Spaceball
int yRot;
int zRot;
bool handled;
void importSettings(int* motionDataArray);
float convertPrefToSensitivity(int value);
};
class ButtonEvent : public EventBase