From 8ff14c8fdb787a2df4d6c82f213374ea9f714e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 10 May 2014 08:37:47 +0200 Subject: [PATCH] port the placement dialog to the inputfield --- src/Gui/InputField.cpp | 15 +++ src/Gui/InputField.h | 13 ++- src/Gui/Placement.cpp | 124 ++++++++++++++----------- src/Gui/Placement.h | 1 + src/Gui/Placement.ui | 205 +++++++++++------------------------------ src/Gui/Transform.cpp | 37 ++++---- 6 files changed, 168 insertions(+), 227 deletions(-) diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 6b8ecc6c9..27f4215ae 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -160,6 +160,7 @@ void InputField::newInput(const QString & text) QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height())); iconLabel->setPixmap(pixmap); parseError(QString::fromAscii(ErrorText.c_str())); + validInput = false; return; } @@ -169,6 +170,7 @@ void InputField::newInput(const QString & text) QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height())); iconLabel->setPixmap(pixmap); parseError(QString::fromAscii("Wrong unit")); + validInput = false; return; } @@ -176,6 +178,7 @@ void InputField::newInput(const QString & text) QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height())); iconLabel->setPixmap(pixmap); ErrorText = ""; + validInput = true; if (res.getValue() > Maximum){ res.setValue(Maximum); @@ -325,13 +328,25 @@ void InputField::setValue(const Base::Quantity& quant) double dFactor; setText(quant.getUserString(dFactor,actUnitStr)); actUnitValue = quant.getValue()/dFactor; + validInput = true; } +void InputField::setValue(const double& value) +{ + setValue(Base::Quantity(value, actUnit)); +} + + void InputField::setUnit(const Base::Unit& unit) { actUnit = unit; } +Base::Unit InputField::getUnit() +{ + return actUnit; +} + /// get the value of the singleStep property double InputField::singleStep(void)const { diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index 8084a627d..7fbab4c25 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2013 Juergen Riegel * + * Copyright (c) 2013 Juergen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * @@ -65,8 +65,17 @@ public: /// set the field with a quantity void setValue(const Base::Quantity&); + //set a numerical value which gets converted to a quantity with the currently set unit type + void setValue(const double&); + /// get the current value Base::Quantity getQuantity(void)const{return this->actQuantity;} + + /// gives the current state of the user input, gives true if it is a valid input with correct quantity + /// (shown by the green pixmap), returns false if the input is a unparsable string or has a wrong unit + /// (shown by the red pixmap in the gui) + bool hasValidInput() { return validInput;}; + /** sets the Unit this field is working with. * After setting the Unit the field will only accept * user input with this unit type. Or if the user input @@ -74,6 +83,7 @@ public: * Quantity. */ void setUnit(const Base::Unit&); + Base::Unit getUnit(); /// set the input field to the last used value (works only if the setParamGrpPath() was called) void setToLastUsedValue(void); @@ -153,6 +163,7 @@ private: QLabel* iconLabel; QByteArray m_sPrefGrp; std::string ErrorText; + bool validInput; /// handle to the parameter group for defaults and history ParameterGrp::handle _handle; diff --git a/src/Gui/Placement.cpp b/src/Gui/Placement.cpp index 1d003b141..720eadb27 100644 --- a/src/Gui/Placement.cpp +++ b/src/Gui/Placement.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #include #include +#include #include "Placement.h" #include "ui_Placement.h" @@ -81,22 +82,17 @@ Placement::Placement(QWidget* parent, Qt::WFlags fl) propertyName = "Placement"; // default name ui = new Ui_PlacementComp(this); ui->applyPlacementChange->hide(); - - ui->xPos->setDecimals(Base::UnitsApi::getDecimals()); - ui->yPos->setDecimals(Base::UnitsApi::getDecimals()); - ui->zPos->setDecimals(Base::UnitsApi::getDecimals()); - ui->xCnt->setDecimals(Base::UnitsApi::getDecimals()); - ui->yCnt->setDecimals(Base::UnitsApi::getDecimals()); - ui->zCnt->setDecimals(Base::UnitsApi::getDecimals()); - ui->yawAngle->setDecimals(Base::UnitsApi::getDecimals()); - ui->pitchAngle->setDecimals(Base::UnitsApi::getDecimals()); - ui->rollAngle->setDecimals(Base::UnitsApi::getDecimals()); - ui->angle->setDecimals(Base::UnitsApi::getDecimals()); - - ui->angle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->yawAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->pitchAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->rollAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); + + ui->xPos->setUnit(Base::Unit::Length); + ui->yPos->setUnit(Base::Unit::Length); + ui->zPos->setUnit(Base::Unit::Length); + ui->xCnt->setValue(Base::Quantity(0, Base::Unit::Length)); + ui->yCnt->setValue(Base::Quantity(0, Base::Unit::Length)); + ui->zCnt->setValue(Base::Quantity(0, Base::Unit::Length)); + ui->angle->setUnit(Base::Unit::Angle); + ui->yawAngle->setUnit(Base::Unit::Angle); + ui->pitchAngle->setUnit(Base::Unit::Angle); + ui->rollAngle->setUnit(Base::Unit::Angle); // create a signal mapper in order to have one slot to perform the change signalMapper = new QSignalMapper(this); @@ -136,6 +132,17 @@ void Placement::slotActiveDocument(const Gui::Document& doc) documents.insert(doc.getDocument()->getName()); } +bool Placement::hasValidInputs() +{ + QList sb = this->findChildren(); + for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { + if(!(*it)->hasValidInput()) + return false; + } + return true; +} + + void Placement::revertTransformation() { for (std::set::iterator it = documents.begin(); it != documents.end(); ++it) { @@ -290,6 +297,15 @@ void Placement::accept() void Placement::on_applyButton_clicked() { + //only process things when we have valid inputs! + if(!hasValidInputs()) { + QMessageBox msg; + msg.setIcon(QMessageBox::Critical); + msg.setText(QString::fromAscii("There are input fields with incorrect input, please ensure valid placement values!")); + msg.exec(); + return; + } + // If there are listeners to the 'placementChanged' signal we rely // on that the listener updates any placement. If no listeners // are connected the placement is applied to all selected objects @@ -302,10 +318,10 @@ void Placement::on_applyButton_clicked() /*emit*/ placementChanged(data, incr, true); if (ui->applyIncrementalPlacement->isChecked()) { - QList sb = this->findChildren(); - for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { + QList sb = this->findChildren(); + for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { (*it)->blockSignals(true); - (*it)->setValue(0.0); + (*it)->setValue(0); (*it)->blockSignals(false); } } @@ -313,10 +329,10 @@ void Placement::on_applyButton_clicked() void Placement::on_resetButton_clicked() { - QList sb = this->findChildren(); - for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { + QList sb = this->findChildren(); + for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { (*it)->blockSignals(true); - (*it)->setValue(0.0); + (*it)->setValue(0); (*it)->blockSignals(false); } @@ -343,22 +359,22 @@ void Placement::setPlacement(const Base::Placement& p) void Placement::setPlacementData(const Base::Placement& p) { signalMapper->blockSignals(true); - ui->xPos->setValue(p.getPosition().x); - ui->yPos->setValue(p.getPosition().y); - ui->zPos->setValue(p.getPosition().z); + ui->xPos->setValue(Base::Quantity(p.getPosition().x, Base::Unit::Length)); + ui->yPos->setValue(Base::Quantity(p.getPosition().y, Base::Unit::Length)); + ui->zPos->setValue(Base::Quantity(p.getPosition().z, Base::Unit::Length)); double Y,P,R; p.getRotation().getYawPitchRoll(Y,P,R); - ui->yawAngle->setValue(Y); - ui->pitchAngle->setValue(P); - ui->rollAngle->setValue(R); + ui->yawAngle->setValue(Base::Quantity(Y, Base::Unit::Angle)); + 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); - ui->angle->setValue(angle*180.0/D_PI); + 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); @@ -398,18 +414,18 @@ Base::Placement Placement::getPlacementData() const Base::Vector3d pos; Base::Vector3d cnt; - pos = Base::Vector3d(ui->xPos->value(),ui->yPos->value(),ui->zPos->value()); - cnt = Base::Vector3d(ui->xCnt->value(),ui->yCnt->value(),ui->zCnt->value()); + pos = Base::Vector3d(ui->xPos->getQuantity().getValue(),ui->yPos->getQuantity().getValue(),ui->zPos->getQuantity().getValue()); + cnt = Base::Vector3d(ui->xCnt->getQuantity().getValue(),ui->yCnt->getQuantity().getValue(),ui->zCnt->getQuantity().getValue()); if (index == 0) { Base::Vector3d dir = getDirection(); - rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),Base::toRadians(ui->angle->value())); + rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),Base::toRadians(ui->angle->getQuantity().getValue())); } else if (index == 1) { rot.setYawPitchRoll( - ui->yawAngle->value(), - ui->pitchAngle->value(), - ui->rollAngle->value()); + ui->yawAngle->getQuantity().getValue(), + ui->pitchAngle->getQuantity().getValue(), + ui->rollAngle->getQuantity().getValue()); } Base::Placement p(pos, rot, cnt); @@ -425,29 +441,29 @@ QString Placement::getPlacementString() const Base::Vector3d dir = getDirection(); cmd = QString::fromAscii( "App.Placement(App.Vector(%1,%2,%3), App.Rotation(App.Vector(%4,%5,%6),%7), App.Vector(%8,%9,%10))") - .arg(ui->xPos->value(),0,'g',ui->xPos->decimals()) - .arg(ui->yPos->value(),0,'g',ui->yPos->decimals()) - .arg(ui->zPos->value(),0,'g',ui->zPos->decimals()) - .arg(dir.x,0,'g',Base::UnitsApi::getDecimals()) - .arg(dir.y,0,'g',Base::UnitsApi::getDecimals()) - .arg(dir.z,0,'g',Base::UnitsApi::getDecimals()) - .arg(ui->angle->value(),0,'g',ui->angle->decimals()) - .arg(ui->xCnt->value(),0,'g',ui->xCnt->decimals()) - .arg(ui->yCnt->value(),0,'g',ui->yCnt->decimals()) - .arg(ui->zCnt->value(),0,'g',ui->zCnt->decimals()); + .arg(ui->xPos->getQuantity().getValue()) + .arg(ui->yPos->getQuantity().getValue()) + .arg(ui->zPos->getQuantity().getValue()) + .arg(dir.x) + .arg(dir.y) + .arg(dir.z) + .arg(ui->angle->getQuantity().getValue()) + .arg(ui->xCnt->getQuantity().getValue()) + .arg(ui->yCnt->getQuantity().getValue()) + .arg(ui->zCnt->getQuantity().getValue()); } else if (index == 1) { cmd = QString::fromAscii( "App.Placement(App.Vector(%1,%2,%3), App.Rotation(%4,%5,%6), App.Vector(%7,%8,%9))") - .arg(ui->xPos->value(),0,'g',ui->xPos->decimals()) - .arg(ui->yPos->value(),0,'g',ui->yPos->decimals()) - .arg(ui->zPos->value(),0,'g',ui->zPos->decimals()) - .arg(ui->yawAngle->value(),0,'g',ui->yawAngle->decimals()) - .arg(ui->pitchAngle->value(),0,'g',ui->pitchAngle->decimals()) - .arg(ui->rollAngle->value(),0,'g',ui->rollAngle->decimals()) - .arg(ui->xCnt->value(),0,'g',ui->xCnt->decimals()) - .arg(ui->yCnt->value(),0,'g',ui->yCnt->decimals()) - .arg(ui->zCnt->value(),0,'g',ui->zCnt->decimals()); + .arg(ui->xPos->getQuantity().getValue()) + .arg(ui->yPos->getQuantity().getValue()) + .arg(ui->zPos->getQuantity().getValue()) + .arg(ui->yawAngle->getQuantity().getValue()) + .arg(ui->pitchAngle->getQuantity().getValue()) + .arg(ui->rollAngle->getQuantity().getValue()) + .arg(ui->xCnt->getQuantity().getValue()) + .arg(ui->yCnt->getQuantity().getValue()) + .arg(ui->zCnt->getQuantity().getValue()); } return cmd; diff --git a/src/Gui/Placement.h b/src/Gui/Placement.h index e313bc6cc..6fbcdfa0f 100644 --- a/src/Gui/Placement.h +++ b/src/Gui/Placement.h @@ -73,6 +73,7 @@ private: void applyPlacement(const QString& p, bool incremental); void revertTransformation(); void slotActiveDocument(const Gui::Document&); + bool hasValidInputs(); Q_SIGNALS: void placementChanged(const QVariant &, bool, bool); diff --git a/src/Gui/Placement.ui b/src/Gui/Placement.ui index 84f68c03e..5c0e94a2c 100644 --- a/src/Gui/Placement.ui +++ b/src/Gui/Placement.ui @@ -6,10 +6,16 @@ 0 0 - 271 - 410 + 277 + 474 + + + 0 + 0 + + Placement @@ -26,55 +32,7 @@ 6 - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - - + Qt::Vertical @@ -87,7 +45,7 @@ - + @@ -100,7 +58,7 @@ - + @@ -126,6 +84,15 @@ + + + + + + + + + @@ -141,54 +108,6 @@ 6 - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - - - - - - 0 - 0 - - - - -2147480000.000000000000000 - - - 2147480000.000000000000000 - - - @@ -241,6 +160,15 @@ + + + + + + + + + @@ -277,16 +205,6 @@ 6 - - - - -360.000000000000000 - - - 360.000000000000000 - - - @@ -320,6 +238,9 @@ + + + @@ -340,26 +261,6 @@ 6 - - - - -360.000000000000000 - - - 360.000000000000000 - - - - - - - -360.000000000000000 - - - 360.000000000000000 - - - @@ -373,16 +274,6 @@ - - - - -360.000000000000000 - - - 360.000000000000000 - - - @@ -409,6 +300,15 @@ + + + + + + + + + @@ -458,6 +358,12 @@ + + + 1 + 0 + + Apply incremental changes to object placement @@ -531,19 +437,16 @@ + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
- xPos - yPos - zPos rotationInput direction - angle - yawAngle - pitchAngle - rollAngle - xCnt - yCnt - zCnt applyPlacementChange applyIncrementalPlacement oKButton diff --git a/src/Gui/Transform.cpp b/src/Gui/Transform.cpp index 608e13e65..8d6b55a00 100644 --- a/src/Gui/Transform.cpp +++ b/src/Gui/Transform.cpp @@ -309,11 +309,6 @@ Transform::Transform(QWidget* parent, Qt::WFlags fl) ui->applyPlacementChange->hide(); ui->applyIncrementalPlacement->hide(); - ui->angle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->yawAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->pitchAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->rollAngle->setSuffix(QString::fromUtf8(" \xc2\xb0")); - ui->closeButton->setText(tr("Cancel")); this->setWindowTitle(tr("Transform")); @@ -323,8 +318,8 @@ Transform::Transform(QWidget* parent, Qt::WFlags fl) signalMapper->setMapping(this, 0); int id = 1; - QList sb = this->findChildren(); - for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { + QList sb = this->findChildren(); + for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { connect(*it, SIGNAL(valueChanged(double)), signalMapper, SLOT(map())); signalMapper->setMapping(*it, id++); } @@ -349,9 +344,9 @@ void Transform::setTransformStrategy(TransformStrategy* ts) delete strategy; strategy = ts; Base::Vector3d cnt = strategy->getRotationCenter(); - ui->xCnt->setValue(cnt.x); - ui->yCnt->setValue(cnt.y); - ui->zCnt->setValue(cnt.z); + ui->xCnt->setValue(Base::Quantity(cnt.x, Base::Unit::Length)); + ui->yCnt->setValue(Base::Quantity(cnt.y, Base::Unit::Length)); + ui->zCnt->setValue(Base::Quantity(cnt.z, Base::Unit::Length)); this->setDisabled(strategy->transformObjects().empty()); } @@ -388,17 +383,17 @@ void Transform::on_applyButton_clicked() strategy->commitTransform(mat); // nullify the values - QList sb = this->findChildren(); - for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { + QList sb = this->findChildren(); + for (QList::iterator it = sb.begin(); it != sb.end(); ++it) { (*it)->blockSignals(true); (*it)->setValue(0.0); (*it)->blockSignals(false); } Base::Vector3d cnt = strategy->getRotationCenter(); - ui->xCnt->setValue(cnt.x); - ui->yCnt->setValue(cnt.y); - ui->zCnt->setValue(cnt.z); + ui->xCnt->setValue(Base::Quantity(cnt.x, Base::Unit::Length)); + ui->yCnt->setValue(Base::Quantity(cnt.y, Base::Unit::Length)); + ui->zCnt->setValue(Base::Quantity(cnt.z, Base::Unit::Length)); } void Transform::directionActivated(int index) @@ -420,18 +415,18 @@ Base::Placement Transform::getPlacementData() const Base::Vector3d pos; Base::Vector3d cnt; - pos = Base::Vector3d(ui->xPos->value(),ui->yPos->value(),ui->zPos->value()); - cnt = Base::Vector3d(ui->xCnt->value(),ui->yCnt->value(),ui->zCnt->value()); + pos = Base::Vector3d(ui->xPos->getQuantity().getValue(),ui->yPos->getQuantity().getValue(),ui->zPos->getQuantity().getValue()); + cnt = Base::Vector3d(ui->xCnt->getQuantity().getValue(),ui->yCnt->getQuantity().getValue(),ui->zCnt->getQuantity().getValue()); if (index == 0) { Base::Vector3d dir = getDirection(); - rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value()*D_PI/180.0); + rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->getQuantity().getValue()*D_PI/180.0); } else if (index == 1) { rot.setYawPitchRoll( - ui->yawAngle->value(), - ui->pitchAngle->value(), - ui->rollAngle->value()); + ui->yawAngle->getQuantity().getValue(), + ui->pitchAngle->getQuantity().getValue(), + ui->rollAngle->getQuantity().getValue()); } Base::Placement p(pos, rot, cnt);