From dad0c36612231d26b698d7f50106e4a229377d1f Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 25 Oct 2022 22:56:56 +0200 Subject: [PATCH] Gui: in placement dialog use spin boxes for rotation axis --- src/Gui/Placement.cpp | 55 ++++++++++++++----------------------------- src/Gui/Placement.h | 12 ++++------ src/Gui/Placement.ui | 20 +++++++++------- src/Gui/Transform.cpp | 21 +++++++---------- src/Gui/Transform.h | 13 ++++------ 5 files changed, 48 insertions(+), 73 deletions(-) diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index cb83affe1d..382f460593 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include #include +#include #include #include #include @@ -85,13 +86,14 @@ public: /* TRANSLATOR Gui::Dialog::Placement */ Placement::Placement(QWidget* parent, Qt::WindowFlags fl) - : Gui::LocationDialog(parent, fl) + : QDialog(parent, fl) , changeProperty(false) { selectionObjects = Gui::Selection().getSelectionEx(); propertyName = "Placement"; // default name - ui = new Ui_PlacementComp(this); + ui = new Ui_Placement(); + ui->setupUi(this); ui->gridLayout->removeItem(ui->vSpacer); ui->xPos->setUnit(Base::Unit::Length); @@ -108,7 +110,6 @@ Placement::Placement(QWidget* parent, Qt::WindowFlags fl) // create a signal mapper in order to have one slot to perform the change signalMapper = new QSignalMapper(this); - connect(this, SIGNAL(directionChanged()), signalMapper, SLOT(map())); signalMapper->setMapping(this, 0); int id = 1; @@ -649,22 +650,23 @@ void Placement::bindObject() ui->yPos->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Base.y"))); ui->zPos->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Base.z"))); + ui->xAxis->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Axis.x"))); + ui->yAxis->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Axis.y"))); + ui->zAxis->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Axis.z"))); + ui->angle->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Angle"))); + ui->yawAngle ->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Yaw"))); ui->pitchAngle->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Pitch"))); ui->rollAngle ->bind(App::ObjectIdentifier::parse(obj, propertyName + std::string(".Rotation.Roll"))); } } -void Placement::directionActivated(int index) -{ - if (ui->directionActivated(this, index)) { - Q_EMIT directionChanged(); - } -} - Base::Vector3d Placement::getDirection() const { - return ui->getDirection(); + double x = ui->xAxis->value().getValue(); + double y = ui->yAxis->value().getValue(); + double z = ui->zAxis->value().getValue(); + return Base::Vector3d(x, y, z); } void Placement::setPlacement(const Base::Placement& p) @@ -685,35 +687,14 @@ void Placement::setPlacementData(const Base::Placement& p) ui->pitchAngle->setValue(Base::Quantity(P, Base::Unit::Angle)); ui->rollAngle->setValue(Base::Quantity(R, Base::Unit::Angle)); - // check if the user-defined direction is already there - bool newitem = true; double angle; Base::Vector3d axis; - p.getRotation().getValue(axis, angle); + p.getRotation().getRawValue(axis, angle); + ui->xAxis->setValue(axis.x); + ui->yAxis->setValue(axis.y); + ui->zAxis->setValue(axis.z); ui->angle->setValue(Base::Quantity(angle*180.0/D_PI, Base::Unit::Angle)); - Base::Vector3d dir(axis.x,axis.y,axis.z); - for (int i=0; idirection->count()-1; i++) { - QVariant data = ui->direction->itemData (i); - if (data.canConvert()) { - const Base::Vector3d val = data.value(); - if (val == dir) { - ui->direction->setCurrentIndex(i); - newitem = false; - break; - } - } - } - if (newitem) { - // add a new item before the very last item - QString display = QString::fromLatin1("(%1,%2,%3)") - .arg(dir.x) - .arg(dir.y) - .arg(dir.z); - ui->direction->insertItem(ui->direction->count()-1, display, - QVariant::fromValue(dir)); - ui->direction->setCurrentIndex(ui->direction->count()-2); - } signalMapper->blockSignals(false); } @@ -798,7 +779,7 @@ QString Placement::getPlacementString() const void Placement::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { - ui->retranslate(this); + ui->retranslateUi(this); } else { QDialog::changeEvent(e); diff --git a/src/Gui/Placement.h b/src/Gui/Placement.h index a259745f4e..e6a8d298e8 100644 --- a/src/Gui/Placement.h +++ b/src/Gui/Placement.h @@ -23,7 +23,8 @@ #ifndef GUI_PLACEMENT_H #define GUI_PLACEMENT_H -#include +#include +#include #include #include #include @@ -38,7 +39,7 @@ namespace Dialog { class Ui_Placement; class TaskPlacement; -class GuiExport Placement : public Gui::LocationDialog +class GuiExport Placement : public QDialog { Q_OBJECT @@ -49,7 +50,7 @@ public: void reject() override; void bindObject(); - Base::Vector3d getDirection() const override; + Base::Vector3d getDirection() const; void setPlacement(const Base::Placement&); Base::Placement getPlacement() const; void showDefaultButtons(bool); @@ -75,7 +76,6 @@ private: Base::Placement getPlacementData() const; Base::Vector3d getCenterData() const; QString getPlacementString() const; - void directionActivated(int) override; void applyPlacement(const Base::Placement& p, bool incremental); void applyPlacement(const QString& p, bool incremental); void revertTransformation(); @@ -84,12 +84,10 @@ private: Q_SIGNALS: void placementChanged(const QVariant &, bool, bool); - void directionChanged(); private: - using Ui_PlacementComp = Gui::LocationUi; using Connection = boost::signals2::connection; - Ui_PlacementComp* ui; + Ui_Placement* ui; QSignalMapper* signalMapper; Connection connectAct; Base::Placement ref; diff --git a/src/Gui/Placement.ui b/src/Gui/Placement.ui index 6ae43e3261..345e3e66d8 100644 --- a/src/Gui/Placement.ui +++ b/src/Gui/Placement.ui @@ -292,13 +292,15 @@ - - - -1 - - + - + + + + + + + @@ -311,7 +313,7 @@ - + @@ -525,7 +527,9 @@ rotationInput - direction + xAxis + yAxis + zAxis applyIncrementalPlacement oKButton applyButton diff --git a/src/Gui/Transform.cpp b/src/Gui/Transform.cpp index 3adf6dd37a..c6379bbd1a 100644 --- a/src/Gui/Transform.cpp +++ b/src/Gui/Transform.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #include +#include #include #include @@ -280,9 +281,10 @@ void DefaultTransformStrategy::onSelectionChanged(const Gui::SelectionChanges& m /* TRANSLATOR Gui::Dialog::Transform */ Transform::Transform(QWidget* parent, Qt::WindowFlags fl) - : Gui::LocationDialog(parent, fl), strategy(nullptr) + : QDialog(parent, fl), strategy(nullptr) { - ui = new Ui_TransformComp(this); + ui = new Ui_Placement(); + ui->setupUi(this); ui->resetButton->hide(); ui->applyIncrementalPlacement->hide(); @@ -291,7 +293,6 @@ Transform::Transform(QWidget* parent, Qt::WindowFlags fl) // create a signal mapper in order to have one slot to perform the change auto signalMapper = new QSignalMapper(this); - connect(this, SIGNAL(directionChanged()), signalMapper, SLOT(map())); signalMapper->setMapping(this, 0); int id = 1; @@ -373,16 +374,12 @@ void Transform::on_applyButton_clicked() ui->zCnt->setValue(Base::Quantity(cnt.z, Base::Unit::Length)); } -void Transform::directionActivated(int index) -{ - if (ui->directionActivated(this, index)) { - Q_EMIT directionChanged(); - } -} - Base::Vector3d Transform::getDirection() const { - return ui->getDirection(); + double x = ui->xAxis->value().getValue(); + double y = ui->yAxis->value().getValue(); + double z = ui->zAxis->value().getValue(); + return Base::Vector3d(x, y, z); } Base::Placement Transform::getPlacementData() const @@ -413,7 +410,7 @@ Base::Placement Transform::getPlacementData() const void Transform::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { - ui->retranslate(this); + ui->retranslateUi(this); ui->closeButton->setText(tr("Cancel")); this->setWindowTitle(tr("Transform")); } diff --git a/src/Gui/Transform.h b/src/Gui/Transform.h index 0cf313ae2b..1268bea0b7 100644 --- a/src/Gui/Transform.h +++ b/src/Gui/Transform.h @@ -23,10 +23,10 @@ #ifndef GUI_TRANSFORM_H #define GUI_TRANSFORM_H +#include #include #include -#include "InputVector.h" #include "Selection.h" #include "TaskView/TaskDialog.h" #include "TaskView/TaskView.h" @@ -68,7 +68,7 @@ private: }; class Ui_Placement; -class GuiExport Transform : public Gui::LocationDialog +class GuiExport Transform : public QDialog { Q_OBJECT @@ -81,7 +81,7 @@ public: void setTransformStrategy(TransformStrategy* ts); protected: - Base::Vector3d getDirection() const override; + Base::Vector3d getDirection() const; void changeEvent(QEvent *e) override; public Q_SLOTS: @@ -92,14 +92,9 @@ private Q_SLOTS: private: Base::Placement getPlacementData() const; - void directionActivated(int) override; - -Q_SIGNALS: - void directionChanged(); private: - using Ui_TransformComp = Gui::LocationUi; - Ui_TransformComp* ui; + Ui_Placement* ui; Base::Placement pm; std::set selection; TransformStrategy* strategy;