diff --git a/src/Gui/3Dconnexion/GuiApplicationNativeEventAwareWin32.cpp b/src/Gui/3Dconnexion/GuiApplicationNativeEventAwareWin32.cpp index 425a7af7a..4403fd22b 100644 --- a/src/Gui/3Dconnexion/GuiApplicationNativeEventAwareWin32.cpp +++ b/src/Gui/3Dconnexion/GuiApplicationNativeEventAwareWin32.cpp @@ -202,8 +202,9 @@ void Gui::GUIApplicationNativeEventAware::Move3d(HANDLE device, std::vectorsetTranslations(x, y, z); - motionEvent->setRotations(rx, ry, rz); + //motionEvent->setTranslations(x, y, z); + //motionEvent->setRotations(rx, ry, rz); + motionEvent->setMotionData(x, y, z, rx, ry, rz); this->postEvent(currentWidget, motionEvent); } diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index b4bf7c5a5..ed70b71d6 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -104,6 +104,7 @@ set(Gui_MOC_HDRS DlgCommandsImp.h DlgCustomizeImp.h DlgCustomizeSpaceball.h + DlgCustomizeSpNavSettings.h DlgDisplayPropertiesImp.h DlgEditorImp.h DlgGeneralImp.h @@ -190,6 +191,7 @@ SET(Gui_UIC_SRCS DlgAuthorization.ui DlgChooseIcon.ui DlgCommands.ui + DlgCustomizeSpNavSettings.ui DlgDisplayProperties.ui DlgEditor.ui DlgGeneral.ui @@ -338,6 +340,7 @@ SET(Dialog_Customize_CPP_SRCS DlgCommandsImp.cpp DlgCustomizeImp.cpp DlgCustomizeSpaceball.cpp + DlgCustomizeSpNavSettings.cpp DlgKeyboardImp.cpp DlgToolbarsImp.cpp ) @@ -346,6 +349,7 @@ SET(Dialog_Customize_HPP_SRCS DlgCommandsImp.h DlgCustomizeImp.h DlgCustomizeSpaceball.h + DlgCustomizeSpNavSettings.h DlgKeyboardImp.h DlgToolbarsImp.h ) @@ -355,6 +359,7 @@ SET(Dialog_Customize_SRCS DlgActions.ui DlgChooseIcon.ui DlgCommands.ui + DlgCustomizeSpNavSettings.ui DlgKeyboard.ui DlgToolbars.ui ) diff --git a/src/Gui/DlgCustomizeSpNavSettings.cpp b/src/Gui/DlgCustomizeSpNavSettings.cpp new file mode 100644 index 000000000..9a7113737 --- /dev/null +++ b/src/Gui/DlgCustomizeSpNavSettings.cpp @@ -0,0 +1,310 @@ +/*************************************************************************** + * Copyright (c) 2012 Petar Perisin * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#include "DlgCustomizeSpNavSettings.h" +#include "GuiApplicationNativeEventAware.h" +#include "Application.h" + + +using namespace Gui::Dialog; + +DlgCustomizeSpNavSettings::DlgCustomizeSpNavSettings(QWidget *parent) : + CustomizeActionPage(parent) +{ + GUIApplicationNativeEventAware *app = qobject_cast(QApplication::instance()); + + if (!app) + return; + if (!app->isSpaceballPresent()) + { + this->setWindowTitle(tr("Spaceball Motion")); + this->setMessage(tr("No Spaceball Present")); + return; + } + this->setupUi(this); + initialize(); +} + +DlgCustomizeSpNavSettings::~DlgCustomizeSpNavSettings() +{ +} + +void DlgCustomizeSpNavSettings::setMessage(const QString& message) +{ + QLabel *messageLabel = new QLabel(message,this); + QVBoxLayout *layout = new QVBoxLayout(); + QHBoxLayout *layout2 = new QHBoxLayout(); + layout2->addStretch(); + layout2->addWidget(messageLabel); + layout2->addStretch(); + layout->addItem(layout2); + this->setLayout(layout); +} + + +void DlgCustomizeSpNavSettings::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); +} + +ParameterGrp::handle DlgCustomizeSpNavSettings::spaceballMotionGroup() const +{ + static ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Spaceball")->GetGroup("Motion"); + return group; +} + +void DlgCustomizeSpNavSettings::on_ButtonCalibrate_clicked() +{ + spaceballMotionGroup()->SetBool("Calibrate", true); +} + +void DlgCustomizeSpNavSettings::initialize() +{ + CBDominant->setChecked(spaceballMotionGroup()->GetBool("Dominant", false)); + CBFlipYZ->setChecked(spaceballMotionGroup()->GetBool("FlipYZ", false)); + CBRotations->setChecked(spaceballMotionGroup()->GetBool("Rotations", true)); + CBTranslations->setChecked(spaceballMotionGroup()->GetBool("Translations", true)); + SliderGlobal->setValue(spaceballMotionGroup()->GetInt("GlobalSensitivity", 0)); + + CBEnablePanLR ->setChecked(spaceballMotionGroup()->GetBool("PanLREnable", true)); + CBReversePanLR->setChecked(spaceballMotionGroup()->GetBool("PanLRReverse", false)); + SliderPanLR ->setValue(spaceballMotionGroup()->GetInt("PanLRSensitivity", 0)); + + CBEnablePanUD ->setChecked(spaceballMotionGroup()->GetBool("PanUDEnable", true)); + CBReversePanUD->setChecked(spaceballMotionGroup()->GetBool("PanUDReverse", false)); + SliderPanUD ->setValue(spaceballMotionGroup()->GetInt("PanUDSensitivity", 0)); + + CBEnableZoom ->setChecked(spaceballMotionGroup()->GetBool("ZoomEnable", true)); + CBReverseZoom->setChecked(spaceballMotionGroup()->GetBool("ZoomReverse", false)); + SliderZoom ->setValue(spaceballMotionGroup()->GetInt("ZoomSensitivity", 0)); + + CBEnableTilt ->setChecked(spaceballMotionGroup()->GetBool("TiltEnable", true)); + CBReverseTilt->setChecked(spaceballMotionGroup()->GetBool("TiltReverse", false)); + SliderTilt ->setValue(spaceballMotionGroup()->GetInt("TiltSensitivity", 0)); + + CBEnableRoll ->setChecked(spaceballMotionGroup()->GetBool("RollEnable", true)); + CBReverseRoll->setChecked(spaceballMotionGroup()->GetBool("RollReverse", false)); + SliderRoll ->setValue(spaceballMotionGroup()->GetInt("RollSensitivity", 0)); + + CBEnableSpin ->setChecked(spaceballMotionGroup()->GetBool("SpinEnable", true)); + CBReverseSpin->setChecked(spaceballMotionGroup()->GetBool("SpinReverse", false)); + SliderSpin ->setValue(spaceballMotionGroup()->GetInt("SpinSensitivity", 0)); + + CBEnableTilt ->setEnabled(CBRotations->isChecked()); + CBReverseTilt->setEnabled(CBRotations->isChecked() && CBEnableTilt->isChecked()); + SliderTilt ->setEnabled(CBRotations->isChecked() && CBEnableTilt->isChecked()); + CBEnableRoll ->setEnabled(CBRotations->isChecked()); + CBReverseRoll->setEnabled(CBRotations->isChecked() && CBEnableRoll->isChecked()); + SliderRoll ->setEnabled(CBRotations->isChecked() && CBEnableRoll->isChecked()); + CBEnableSpin ->setEnabled(CBRotations->isChecked()); + CBReverseSpin->setEnabled(CBRotations->isChecked() && CBEnableSpin->isChecked()); + SliderSpin ->setEnabled(CBRotations->isChecked() && CBEnableSpin->isChecked()); + + CBEnablePanLR ->setEnabled(CBTranslations->isChecked()); + CBReversePanLR->setEnabled(CBTranslations->isChecked() && CBEnablePanLR->isChecked()); + SliderPanLR ->setEnabled(CBTranslations->isChecked() && CBEnablePanLR->isChecked()); + CBEnablePanUD ->setEnabled(CBTranslations->isChecked()); + CBReversePanUD->setEnabled(CBTranslations->isChecked() && CBEnablePanUD->isChecked()); + SliderPanUD ->setEnabled(CBTranslations->isChecked() && CBEnablePanUD->isChecked()); + CBEnableZoom ->setEnabled(CBTranslations->isChecked()); + CBReverseZoom ->setEnabled(CBTranslations->isChecked() && CBEnableZoom->isChecked()); + SliderZoom ->setEnabled(CBTranslations->isChecked() && CBEnableZoom->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_ButtonDefaultSpNavMotions_clicked() +{ + spaceballMotionGroup()->Clear(); + initialize(); +} + +void DlgCustomizeSpNavSettings::on_CBDominant_clicked() +{ + spaceballMotionGroup()->SetBool("Dominant", CBDominant->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBFlipYZ_clicked() +{ + spaceballMotionGroup()->SetBool("FlipYZ", CBFlipYZ->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBRotations_clicked() +{ + spaceballMotionGroup()->SetBool("Rotations", CBRotations->isChecked()); + + CBEnableTilt ->setEnabled(CBRotations->isChecked()); + CBReverseTilt->setEnabled(CBRotations->isChecked() && CBEnableTilt->isChecked()); + SliderTilt ->setEnabled(CBRotations->isChecked() && CBEnableTilt->isChecked()); + CBEnableRoll ->setEnabled(CBRotations->isChecked()); + CBReverseRoll->setEnabled(CBRotations->isChecked() && CBEnableRoll->isChecked()); + SliderRoll ->setEnabled(CBRotations->isChecked() && CBEnableRoll->isChecked()); + CBEnableSpin ->setEnabled(CBRotations->isChecked()); + CBReverseSpin->setEnabled(CBRotations->isChecked() && CBEnableSpin->isChecked()); + SliderSpin ->setEnabled(CBRotations->isChecked() && CBEnableSpin->isChecked()); + +} + +void DlgCustomizeSpNavSettings::on_CBTranslations_clicked() +{ + spaceballMotionGroup()->SetBool("Translations", CBTranslations->isChecked()); + + CBEnablePanLR ->setEnabled(CBTranslations->isChecked()); + CBReversePanLR->setEnabled(CBTranslations->isChecked() && CBEnablePanLR->isChecked()); + SliderPanLR ->setEnabled(CBTranslations->isChecked() && CBEnablePanLR->isChecked()); + CBEnablePanUD ->setEnabled(CBTranslations->isChecked()); + CBReversePanUD->setEnabled(CBTranslations->isChecked() && CBEnablePanUD->isChecked()); + SliderPanUD ->setEnabled(CBTranslations->isChecked() && CBEnablePanUD->isChecked()); + CBEnableZoom ->setEnabled(CBTranslations->isChecked()); + CBReverseZoom ->setEnabled(CBTranslations->isChecked() && CBEnableZoom->isChecked()); + SliderZoom ->setEnabled(CBTranslations->isChecked() && CBEnableZoom->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderGlobal_sliderReleased() +{ + spaceballMotionGroup()->SetInt("GlobalSensitivity", SliderGlobal->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnablePanLR_clicked() +{ + spaceballMotionGroup()->SetBool("PanLREnable", CBEnablePanLR->isChecked()); + + CBReversePanLR->setEnabled(CBEnablePanLR->isChecked()); + SliderPanLR ->setEnabled(CBEnablePanLR->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReversePanLR_clicked() +{ + spaceballMotionGroup()->SetBool("PanLRReverse", CBReversePanLR->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderPanLR_sliderReleased() +{ + spaceballMotionGroup()->SetInt("PanLRSensitivity", SliderPanLR->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnablePanUD_clicked() +{ + spaceballMotionGroup()->SetBool("PanUDEnable", CBEnablePanUD->isChecked()); + + CBReversePanUD->setEnabled(CBEnablePanUD->isChecked()); + SliderPanUD ->setEnabled(CBEnablePanUD->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReversePanUD_clicked() +{ + spaceballMotionGroup()->SetBool("PanUDReverse", CBReversePanUD->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderPanUD_sliderReleased() +{ + spaceballMotionGroup()->SetInt("PanUDSensitivity", SliderPanUD->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnableZoom_clicked() +{ + spaceballMotionGroup()->SetBool("ZoomEnable", CBEnableZoom->isChecked()); + + CBReverseZoom ->setEnabled(CBEnableZoom->isChecked()); + SliderZoom ->setEnabled(CBEnableZoom->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReverseZoom_clicked() +{ + spaceballMotionGroup()->SetBool("ZoomReverse", CBReverseZoom->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderZoom_sliderReleased() +{ + spaceballMotionGroup()->SetInt("ZoomSensitivity", SliderZoom->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnableTilt_clicked() +{ + spaceballMotionGroup()->SetBool("TiltEnable", CBEnableTilt->isChecked()); + + CBReverseTilt->setEnabled(CBEnableTilt->isChecked()); + SliderTilt ->setEnabled(CBEnableTilt->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReverseTilt_clicked() +{ + spaceballMotionGroup()->SetBool("TiltReverse", CBReverseTilt->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderTilt_sliderReleased() +{ + spaceballMotionGroup()->SetInt("TiltSensitivity", SliderTilt->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnableRoll_clicked() +{ + spaceballMotionGroup()->SetBool("RollEnable", CBEnableRoll->isChecked()); + + CBReverseRoll->setEnabled(CBEnableRoll->isChecked()); + SliderRoll ->setEnabled(CBEnableRoll->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReverseRoll_clicked() +{ + spaceballMotionGroup()->SetBool("RollReverse", CBReverseRoll->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderRoll_sliderReleased() +{ + spaceballMotionGroup()->SetInt("RollSensitivity", SliderRoll->value()); +} + +void DlgCustomizeSpNavSettings::on_CBEnableSpin_clicked() +{ + spaceballMotionGroup()->SetBool("SpinEnable", CBEnableSpin->isChecked()); + + CBReverseSpin->setEnabled(CBEnableSpin->isChecked()); + SliderSpin ->setEnabled(CBEnableSpin->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_CBReverseSpin_clicked() +{ + spaceballMotionGroup()->SetBool("SpinReverse", CBReverseSpin->isChecked()); +} + +void DlgCustomizeSpNavSettings::on_SliderSpin_sliderReleased() +{ + spaceballMotionGroup()->SetInt("SpinSensitivity", SliderSpin->value()); +} + +void DlgCustomizeSpNavSettings::onAddMacroAction(const QByteArray ¯oName) +{ + //don't think I need to do anything here. +} + +void DlgCustomizeSpNavSettings::onRemoveMacroAction(const QByteArray ¯oName) +{ + //don't think I need to do anything here. +} + +void DlgCustomizeSpNavSettings::onModifyMacroAction(const QByteArray ¯oName) +{ + //don't think I need to do anything here. +} + +#include "moc_DlgCustomizeSpNavSettings.cpp" \ No newline at end of file diff --git a/src/Gui/DlgCustomizeSpNavSettings.h b/src/Gui/DlgCustomizeSpNavSettings.h new file mode 100644 index 000000000..6966094d5 --- /dev/null +++ b/src/Gui/DlgCustomizeSpNavSettings.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) 2012 Petar Perisin * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef DLGCUSTOMIZESPNAVSETTINGS_H +#define DLGCUSTOMIZESPNAVSETTINGS_H + +#include "ui_DlgCustomizeSpNavSettings.h" +#include "PropertyPage.h" +#include + +namespace Gui +{ + namespace Dialog + { + class DlgCustomizeSpNavSettings : public CustomizeActionPage, public Ui_DlgCustomizeSpNavSettings + { + Q_OBJECT + + public: + explicit DlgCustomizeSpNavSettings(QWidget *parent = 0); + ~DlgCustomizeSpNavSettings(); + + + protected Q_SLOTS: + void onAddMacroAction(const QByteArray&); + void onRemoveMacroAction(const QByteArray&); + void onModifyMacroAction(const QByteArray&); + void on_CBDominant_clicked(); + void on_CBFlipYZ_clicked(); + void on_CBRotations_clicked(); + void on_CBTranslations_clicked(); + void on_SliderGlobal_sliderReleased(); + void on_CBEnablePanLR_clicked(); + void on_CBReversePanLR_clicked(); + void on_SliderPanLR_sliderReleased(); + void on_CBEnablePanUD_clicked(); + void on_CBReversePanUD_clicked(); + void on_SliderPanUD_sliderReleased(); + void on_CBEnableZoom_clicked(); + void on_CBReverseZoom_clicked(); + void on_SliderZoom_sliderReleased(); + void on_CBEnableTilt_clicked(); + void on_CBReverseTilt_clicked(); + void on_SliderTilt_sliderReleased(); + void on_CBEnableRoll_clicked(); + void on_CBReverseRoll_clicked(); + void on_SliderRoll_sliderReleased(); + void on_CBEnableSpin_clicked(); + void on_CBReverseSpin_clicked(); + void on_SliderSpin_sliderReleased(); + void on_ButtonDefaultSpNavMotions_clicked(); + void on_ButtonCalibrate_clicked(); + + protected: + void changeEvent(QEvent *e); + + private: + ParameterGrp::handle spaceballMotionGroup() const; + void setMessage(const QString& message); + void initialize(); + }; + } +} + +#endif // DLGCUSTOMIZESPNAVSETTINGS_H diff --git a/src/Gui/DlgCustomizeSpNavSettings.ui b/src/Gui/DlgCustomizeSpNavSettings.ui new file mode 100644 index 000000000..504468780 --- /dev/null +++ b/src/Gui/DlgCustomizeSpNavSettings.ui @@ -0,0 +1,534 @@ + + + DlgCustomizeSpNavSettings + + + + 0 + 0 + 439 + 537 + + + + Spaceball Motion + + + + + + + + Global Sensitivity: + + + + + + + -50 + + + 50 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + + + + + + + Dominant Mode + + + + + + + Flip Y/Z + + + + + + + + + + + Enable Translations + + + true + + + + + + + Enable Rotations + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Calibrate + + + + + + + Default + + + + + + + + + Qt::Vertical + + + + 20 + 116 + + + + + + + + + + + + + + + :/icons/SpNav-PanLR.png + + + + + + + + + + :/icons/SpNav-PanUD.png + + + + + + + + + + :/icons/SpNav-Zoom.png + + + + + + + + + + :/icons/SpNav-Tilt.png + + + + + + + + + + :/icons/SpNav-Roll.png + + + + + + + + + + :/icons/SpNav-Spin.png + + + + + + + + + 20 + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + 0 + + + + + Enable + + + true + + + + + + + Reverse + + + + + + + + + + + 30 + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + -50 + + + 50 + + + 1 + + + 1 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 10 + + + + + + + + + + + + + + + diff --git a/src/Gui/DlgCustomizeSpaceball.cpp b/src/Gui/DlgCustomizeSpaceball.cpp index 4fa00ba4e..8a7dc5aae 100644 --- a/src/Gui/DlgCustomizeSpaceball.cpp +++ b/src/Gui/DlgCustomizeSpaceball.cpp @@ -525,7 +525,7 @@ DlgCustomizeSpaceball::DlgCustomizeSpaceball(QWidget *parent) : CustomizeActionPage(parent), buttonView(0), buttonModel(0), commandView(0), commandModel(0), clearButton(0), printReference(0) { - this->setWindowTitle(tr("Spaceball")); + this->setWindowTitle(tr("Spaceball Buttons")); GUIApplicationNativeEventAware *app = qobject_cast(QApplication::instance()); if (!app) return; diff --git a/src/Gui/GuiApplicationNativeEventAware.cpp b/src/Gui/GuiApplicationNativeEventAware.cpp index f14beb3bb..6f9485ee1 100644 --- a/src/Gui/GuiApplicationNativeEventAware.cpp +++ b/src/Gui/GuiApplicationNativeEventAware.cpp @@ -143,8 +143,9 @@ bool Gui::GUIApplicationNativeEventAware::x11EventFilter(XEvent *event) if (navEvent.type == SPNAV_EVENT_MOTION) { 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->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); this->postEvent(currentWidget, motionEvent); return true; } diff --git a/src/Gui/Icons/SpNav-PanLR.png b/src/Gui/Icons/SpNav-PanLR.png new file mode 100644 index 000000000..c70a16f58 Binary files /dev/null and b/src/Gui/Icons/SpNav-PanLR.png differ diff --git a/src/Gui/Icons/SpNav-PanUD.png b/src/Gui/Icons/SpNav-PanUD.png new file mode 100644 index 000000000..c1ba44fc9 Binary files /dev/null and b/src/Gui/Icons/SpNav-PanUD.png differ diff --git a/src/Gui/Icons/SpNav-Roll.png b/src/Gui/Icons/SpNav-Roll.png new file mode 100644 index 000000000..372b3ae8b Binary files /dev/null and b/src/Gui/Icons/SpNav-Roll.png differ diff --git a/src/Gui/Icons/SpNav-Spin.png b/src/Gui/Icons/SpNav-Spin.png new file mode 100644 index 000000000..8d198097b Binary files /dev/null and b/src/Gui/Icons/SpNav-Spin.png differ diff --git a/src/Gui/Icons/SpNav-Tilt.png b/src/Gui/Icons/SpNav-Tilt.png new file mode 100644 index 000000000..73f072ec4 Binary files /dev/null and b/src/Gui/Icons/SpNav-Tilt.png differ diff --git a/src/Gui/Icons/SpNav-Zoom.png b/src/Gui/Icons/SpNav-Zoom.png new file mode 100644 index 000000000..39686bca4 Binary files /dev/null and b/src/Gui/Icons/SpNav-Zoom.png differ diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 2114905a6..e506168b6 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -78,5 +78,11 @@ Tree_Dimension.svg Tree_Python.svg spaceball_button.svg + SpNav-PanLR.png + SpNav-PanUD.png + SpNav-Roll.png + SpNav-Spin.png + SpNav-Tilt.png + SpNav-Zoom.png diff --git a/src/Gui/SpaceballEvent.cpp b/src/Gui/SpaceballEvent.cpp index 55efa7a27..7b93ade1a 100644 --- a/src/Gui/SpaceballEvent.cpp +++ b/src/Gui/SpaceballEvent.cpp @@ -22,6 +22,7 @@ #include "PreCompiled.h" #include "SpaceballEvent.h" +#include "Application.h" using namespace Spaceball; @@ -40,15 +41,132 @@ MotionEvent::MotionEvent() : EventBase(static_cast(MotionEventType MotionEvent::MotionEvent(const MotionEvent& in) : EventBase(static_cast(MotionEventType)) { - xTrans = in.xTrans; - yTrans = in.yTrans; - zTrans = in.zTrans; - xRot = in.xRot; - yRot = in.yRot; - zRot = in.zRot; + int motionDataArray[6] = {in.xTrans, in.yTrans, in.zTrans, in.xRot, in.yRot, in.zRot}; + importSettings(motionDataArray); 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; @@ -58,9 +176,8 @@ void MotionEvent::translations(int &xTransOut, int &yTransOut, int &zTransOut) void MotionEvent::setTranslations(const int &xTransIn, const int &yTransIn, const int &zTransIn) { - xTrans = xTransIn; - yTrans = yTransIn; - zTrans = zTransIn; + int motionDataArray[6] = {xTransIn, yTransIn, zTransIn, xRot, yRot, zRot}; + importSettings(motionDataArray); } void MotionEvent::rotations(int &xRotOut, int &yRotOut, int &zRotOut) @@ -72,9 +189,8 @@ void MotionEvent::rotations(int &xRotOut, int &yRotOut, int &zRotOut) void MotionEvent::setRotations(const int &xRotIn, const int &yRotIn, const int &zRotIn) { - xRot = xRotIn; - yRot = yRotIn; - zRot = zRotIn; + int motionDataArray[6] = {xTrans, yTrans, zTrans, xRotIn, yRotIn, zRotIn}; + importSettings(motionDataArray); } diff --git a/src/Gui/SpaceballEvent.h b/src/Gui/SpaceballEvent.h index b07113e56..4f506a0b0 100644 --- a/src/Gui/SpaceballEvent.h +++ b/src/Gui/SpaceballEvent.h @@ -56,6 +56,7 @@ 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: @@ -66,6 +67,8 @@ namespace Spaceball int yRot; int zRot; bool handled; + void importSettings(int* motionDataArray); + float convertPrefToSensitivity(int value); }; class ButtonEvent : public EventBase diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index b7f3ce8fb..8a72ca046 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -45,6 +45,7 @@ #include "DlgCommandsImp.h" #include "DlgKeyboardImp.h" #include "DlgCustomizeSpaceball.h" +#include "DlgCustomizeSpNavSettings.h" using namespace Gui; using namespace Gui::Dialog; @@ -75,6 +76,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() new CustomPageProducer; //new CustomPageProducer; new CustomPageProducer; + new CustomPageProducer; new CustomPageProducer; // ADD YOUR PREFERENCE WIDGETS HERE