diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 509eefab6..c259c1cb5 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include #include @@ -120,14 +122,12 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); - connect(ui->spinOffset, SIGNAL(valueChanged(double)), - this, SLOT(onOffsetChanged(double))); - connect(ui->spinOffset2, SIGNAL(valueChanged(double)), - this, SLOT(onOffset2Changed(double))); - connect(ui->spinOffset3, SIGNAL(valueChanged(double)), - this, SLOT(onOffset3Changed(double))); - connect(ui->spinAngle, SIGNAL(valueChanged(double)), - this, SLOT(onAngleChanged(double))); + connect(ui->superplacementX, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementXChanged(double))); + connect(ui->superplacementY, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementYChanged(double))); + connect(ui->superplacementZ, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementZChanged(double))); + connect(ui->superplacementYaw, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementYawChanged(double))); + connect(ui->superplacementPitch, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementPitchChanged(double))); + connect(ui->superplacementRoll, SIGNAL(valueChanged(double)), this, SLOT(onSuperplacementRollChanged(double))); connect(ui->checkBoxFlip, SIGNAL(toggled(bool)), this, SLOT(onCheckFlip(bool))); connect(ui->buttonRef1, SIGNAL(clicked(bool)), @@ -152,10 +152,6 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p this->groupLayout()->addWidget(proxy); // Temporarily prevent unnecessary feature recomputes - ui->spinOffset->blockSignals(true); - ui->spinOffset2->blockSignals(true); - ui->spinOffset3->blockSignals(true); - ui->spinAngle->blockSignals(true); ui->checkBoxFlip->blockSignals(true); ui->buttonRef1->blockSignals(true); ui->lineRef1->blockSignals(true); @@ -172,20 +168,7 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p //std::vector refs = pcDatum->Support.getValues(); std::vector refnames = pcDatum->Support.getSubValues(); - //bool checked1 = pcDatum->Checked.getValue(); - double offset = pcDatum->superPlacement.getValue().getPosition().z; - double offset2 = pcDatum->superPlacement.getValue().getPosition().y; - double offset3 = pcDatum->superPlacement.getValue().getPosition().x; - double angle = 0; - Base::Vector3d val; - pcDatum->superPlacement.getValue().getRotation().getValue(val, angle); - - // Fill data into dialog elements - ui->spinOffset->setValue(offset); - ui->spinOffset2->setValue(offset2); - ui->spinOffset3->setValue(offset3); - ui->spinAngle->setValue(angle); - //ui->checkBoxFlip->setChecked(checked1); + ui->checkBoxFlip->setChecked(pcDatum->MapReversed.getValue()); std::vector refstrings; makeRefStrings(refstrings, refnames); ui->lineRef1->setText(refstrings[0]); @@ -198,10 +181,6 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p ui->lineRef4->setProperty("RefName", QByteArray(refnames[3].c_str())); // activate and de-activate dialog elements as appropriate - ui->spinOffset->blockSignals(false); - ui->spinOffset2->blockSignals(false); - ui->spinOffset3->blockSignals(false); - ui->spinAngle->blockSignals(false); ui->checkBoxFlip->blockSignals(false); ui->buttonRef1->blockSignals(false); ui->lineRef1->blockSignals(false); @@ -220,7 +199,11 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p autoNext = false; } - updateUI(); + ui->superplacementX->bind(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Base.x"))); + ui->superplacementY->bind(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Base.y"))); + ui->superplacementZ->bind(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Base.z"))); + updateSuperplacementUI(); + updateReferencesUI(); updateListOfModes(eMapMode(pcDatum->MapMode.getValue())); updatePreview(); @@ -290,22 +273,10 @@ const QString makeHintText(std::set hint) return result; } -void TaskDatumParameters::updateUI() +void TaskDatumParameters::updateReferencesUI() { - ui->checkBoxFlip->setVisible(false); - - ui->labelOffset->setVisible(true); - ui->spinOffset->setVisible(true); - ui->labelOffset2->setVisible(true); - ui->spinOffset2->setVisible(true); - ui->labelOffset3->setVisible(true); - ui->spinOffset3->setVisible(true); Part::Datum* pcDatum = static_cast(DatumView->getObject()); - if (pcDatum->isDerivedFrom(Part::Datum::getClassTypeId())) { - ui->labelAngle->setVisible(true); - ui->spinAngle->setVisible(true); - } std::vector refs = pcDatum->Support.getValues(); completed = false; @@ -326,13 +297,6 @@ void TaskDatumParameters::updateUI() completed = true; } - double angle = 0; - Base::Vector3d val; - pcDatum->superPlacement.getValue().getRotation().getValue(val, angle); - - ui->labelAngle->setEnabled(true); - ui->spinAngle->setEnabled(true); - updateRefButton(0); updateRefButton(1); updateRefButton(2); @@ -343,6 +307,7 @@ bool TaskDatumParameters::updatePreview() { Part::Datum* pcDatum = static_cast(DatumView->getObject()); QString errMessage; + bool attached; try{ pcDatum->positionBySupport(); } catch (Base::Exception &err){ @@ -355,18 +320,22 @@ bool TaskDatumParameters::updatePreview() if (errMessage.length()>0){ ui->message->setText(tr("Attachment mode failed: %1").arg(errMessage)); ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}")); - return false; + attached = false; } else { if (pcDatum->MapMode.getValue() == mmDeactivated){ ui->message->setText(tr("Not attached")); ui->message->setStyleSheet(QString()); + attached = false; } else { std::vector strs = AttacherGui::getUIStrings(pcDatum->attacher().getTypeId(),eMapMode(pcDatum->MapMode.getValue())); ui->message->setText(tr("Attached with mode %1").arg(strs[0])); ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: green;}")); + attached = true; } - return true; } + QString splmLabelText = attached ? tr("Extra placement:") : tr("Extra placement (inactive - not attached):"); + ui->label_superplacement->setText(splmLabelText); + return attached; } QLineEdit* TaskDatumParameters::getLine(unsigned idx) @@ -460,60 +429,73 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg) } } - updateUI(); + updateReferencesUI(); } } -void TaskDatumParameters::onOffsetChanged(double val) +void TaskDatumParameters::onSuperplacementChanged(double val, int idx) { Part::Datum* pcDatum = static_cast(DatumView->getObject()); Base::Placement pl = pcDatum->superPlacement.getValue(); - Base::Vector3d pos = pl.getPosition(); - pos.z = val; - pl.setPosition(pos); - pcDatum->superPlacement.setValue(pl); - pcDatum->getDocument()->recomputeFeature(pcDatum); - updateUI(); -} -void TaskDatumParameters::onOffset2Changed(double val) -{ - Part::Datum* pcDatum = static_cast(DatumView->getObject()); - Base::Placement pl = pcDatum->superPlacement.getValue(); Base::Vector3d pos = pl.getPosition(); - pos.y = val; - pl.setPosition(pos); - pcDatum->superPlacement.setValue(pl); - pcDatum->getDocument()->recomputeFeature(pcDatum); - updateUI(); -} + if (idx == 0) { + pos.x = ui->superplacementX->value().getValueAs(Base::Quantity::MilliMetre); + } + if (idx == 1) { + pos.y = ui->superplacementY->value().getValueAs(Base::Quantity::MilliMetre); + } + if (idx == 2) { + pos.z = ui->superplacementZ->value().getValueAs(Base::Quantity::MilliMetre); + } + if (idx >= 0 && idx <= 2){ + pl.setPosition(pos); + } -void TaskDatumParameters::onOffset3Changed(double val) -{ - Part::Datum* pcDatum = static_cast(DatumView->getObject()); - Base::Placement pl = pcDatum->superPlacement.getValue(); - Base::Vector3d pos = pl.getPosition(); - pos.x = val; - pl.setPosition(pos); - pcDatum->superPlacement.setValue(pl); - pcDatum->getDocument()->recomputeFeature(pcDatum); - updateUI(); -} - -void TaskDatumParameters::onAngleChanged(double val) -{ - Part::Datum* pcDatum = static_cast(DatumView->getObject()); - Base::Placement pl = pcDatum->superPlacement.getValue(); Base::Rotation rot = pl.getRotation(); - Base::Vector3d ax; - double ang; - rot.getValue(ax,ang); - ang = val; - rot.setValue(ax,ang); - pl.setRotation(rot); + double yaw, pitch, roll; + rot.getYawPitchRoll(yaw, pitch, roll); + if (idx == 3) { + yaw = ui->superplacementYaw->value().getValueAs(Base::Quantity::Degree); + } + if (idx == 4) { + pitch = ui->superplacementPitch->value().getValueAs(Base::Quantity::Degree); + } + if (idx == 5) { + roll = ui->superplacementRoll->value().getValueAs(Base::Quantity::Degree); + } + if (idx >= 3 && idx <= 5){ + rot.setYawPitchRoll(yaw,pitch,roll); + pl.setRotation(rot); + } + pcDatum->superPlacement.setValue(pl); - pcDatum->getDocument()->recomputeFeature(pcDatum); - updateUI(); + updatePreview(); +} + +void TaskDatumParameters::onSuperplacementXChanged(double val) +{ + onSuperplacementChanged(val, 0); +} +void TaskDatumParameters::onSuperplacementYChanged(double val) +{ + onSuperplacementChanged(val, 1); +} +void TaskDatumParameters::onSuperplacementZChanged(double val) +{ + onSuperplacementChanged(val, 2); +} +void TaskDatumParameters::onSuperplacementYawChanged(double val) +{ + onSuperplacementChanged(val, 3); +} +void TaskDatumParameters::onSuperplacementPitchChanged(double val) +{ + onSuperplacementChanged(val, 4); +} +void TaskDatumParameters::onSuperplacementRollChanged(double val) +{ + onSuperplacementChanged(val, 5); } void TaskDatumParameters::onCheckFlip(bool on) @@ -594,7 +576,7 @@ void TaskDatumParameters::onRefName(const QString& text, unsigned idx) ui->lineRef3->setProperty("RefName", QByteArray(newrefnames[2].c_str())); ui->lineRef4->setText(refstrings[3]); ui->lineRef4->setProperty("RefName", QByteArray(newrefnames[3].c_str())); - updateUI(); + updateReferencesUI(); return; } @@ -662,7 +644,7 @@ void TaskDatumParameters::onRefName(const QString& text, unsigned idx) updateListOfModes(); pcDatum->MapMode.setValue(getActiveMapMode()); - updateUI(); + updateReferencesUI(); } void TaskDatumParameters::updateRefButton(int idx) @@ -698,6 +680,59 @@ void TaskDatumParameters::updateRefButton(int idx) } } +void TaskDatumParameters::updateSuperplacementUI() +{ + Part::Datum* pcDatum = static_cast(DatumView->getObject()); + Base::Placement pl = pcDatum->superPlacement.getValue(); + Base::Vector3d pos = pl.getPosition(); + Base::Rotation rot = pl.getRotation(); + double yaw, pitch, roll; + rot.getYawPitchRoll(yaw, pitch, roll); + + bool bBlock = true; + ui->superplacementX->blockSignals(bBlock); + ui->superplacementY->blockSignals(bBlock); + ui->superplacementZ->blockSignals(bBlock); + ui->superplacementYaw->blockSignals(bBlock); + ui->superplacementPitch->blockSignals(bBlock); + ui->superplacementRoll->blockSignals(bBlock); + + ui->superplacementX->setValue(Base::Quantity(pos.x,Base::Unit::Length)); + ui->superplacementY->setValue(Base::Quantity(pos.y,Base::Unit::Length)); + ui->superplacementZ->setValue(Base::Quantity(pos.z,Base::Unit::Length)); + ui->superplacementYaw->setValue(yaw); + ui->superplacementPitch->setValue(pitch); + ui->superplacementRoll->setValue(roll); + + auto expressions = pcDatum->ExpressionEngine.getExpressions(); + bool bRotationBound = false; + bRotationBound = bRotationBound || + expressions.find(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Rotation.Angle"))) != expressions.end(); + bRotationBound = bRotationBound || + expressions.find(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Rotation.Axis.x"))) != expressions.end(); + bRotationBound = bRotationBound || + expressions.find(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Rotation.Axis.y"))) != expressions.end(); + bRotationBound = bRotationBound || + expressions.find(App::ObjectIdentifier::parse(pcDatum,std::string("superPlacement.Rotation.Axis.z"))) != expressions.end(); + + ui->superplacementYaw->setEnabled(!bRotationBound); + ui->superplacementPitch->setEnabled(!bRotationBound); + ui->superplacementRoll->setEnabled(!bRotationBound); + + QString tooltip = bRotationBound ? tr("Not editable because rotation part of superplacement is bound by expressions.") : QString(); + ui->superplacementYaw->setToolTip(tooltip); + ui->superplacementPitch->setToolTip(tooltip); + ui->superplacementRoll->setToolTip(tooltip); + + bBlock = false; + ui->superplacementX->blockSignals(bBlock); + ui->superplacementY->blockSignals(bBlock); + ui->superplacementZ->blockSignals(bBlock); + ui->superplacementYaw->blockSignals(bBlock); + ui->superplacementPitch->blockSignals(bBlock); + ui->superplacementRoll->blockSignals(bBlock); +} + void TaskDatumParameters::updateListOfModes(eMapMode curMode) { //first up, remember currently selected mode. @@ -807,25 +842,6 @@ void TaskDatumParameters::onRefName4(const QString &text) onRefName(text, 3); } -double TaskDatumParameters::getOffset() const -{ - return ui->spinOffset->value(); -} - -double TaskDatumParameters::getOffset2() const -{ - return ui->spinOffset2->value(); -} - -double TaskDatumParameters::getOffset3() const -{ - return ui->spinOffset3->value(); -} - -double TaskDatumParameters::getAngle() const -{ - return ui->spinAngle->value(); -} bool TaskDatumParameters::getFlip() const { @@ -836,10 +852,6 @@ void TaskDatumParameters::changeEvent(QEvent *e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { - ui->spinOffset->blockSignals(true); - ui->spinOffset2->blockSignals(true); - ui->spinOffset3->blockSignals(true); - ui->spinAngle->blockSignals(true); ui->checkBoxFlip->blockSignals(true); ui->buttonRef1->blockSignals(true); ui->lineRef1->blockSignals(true); @@ -859,12 +871,7 @@ void TaskDatumParameters::changeEvent(QEvent *e) ui->lineRef3->setText(refstrings[2]); ui->lineRef3->setText(refstrings[3]); updateListOfModes(); - // TODO: Translate DatumView->datumType ? - ui->spinOffset->blockSignals(false); - ui->spinOffset2->blockSignals(false); - ui->spinOffset3->blockSignals(false); - ui->spinAngle->blockSignals(false); ui->checkBoxFlip->blockSignals(false); ui->buttonRef1->blockSignals(false); ui->lineRef1->blockSignals(false); @@ -974,16 +981,22 @@ bool TaskDlgDatumParameters::accept() } try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement.Base.z = %f",name.c_str(),parameter->getOffset()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement.Base.y = %f",name.c_str(),parameter->getOffset2()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement.Base.x = %f",name.c_str(),parameter->getOffset3()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement.Rotation.Angle = %f",name.c_str(),parameter->getAngle()); - //Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Checked = %i",name.c_str(),parameter->getCheckBox1()?1:0); + //DeepSOIC: changed this to heavily rely on dialog constantly updating feature properties + if (pcDatum->superPlacement.isTouched()){ + Base::Placement plm = pcDatum->superPlacement.getValue(); + double yaw, pitch, roll; + plm.getRotation().getYawPitchRoll(yaw,pitch,roll); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.superPlacement = App.Placement(App.Vector(%.10f, %.10f, %.10f), App.Rotation(%.10f, %.10f, %.10f))", + name.c_str(), + plm.getPosition().x, plm.getPosition().y, plm.getPosition().z, + yaw, pitch, roll); + } + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MapReversed = %s", name.c_str(), pcDatum->MapReversed.getValue() ? "True" : "False"); - //here it is assumed that the support was already assigned, it just outputs a dummy Python command to the console Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Support = %s", name.c_str(), pcDatum->Support.getPyReprString().c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MapMode = '%s'", name.c_str(), AttachEngine::getModeName(parameter->getActiveMapMode()).c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MapMode = '%s'", name.c_str(), AttachEngine::getModeName(eMapMode(pcDatum->MapMode.getValue())).c_str()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); if (!DatumView->getObject()->isValid()) diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.h b/src/Mod/PartDesign/Gui/TaskDatumParameters.h index 2f169da5e..f422b04ae 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.h @@ -54,10 +54,6 @@ public: TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *parent = 0); ~TaskDatumParameters(); - double getOffset(void) const; - double getOffset2(void) const; - double getOffset3(void) const; - double getAngle(void) const; bool getFlip(void) const; /** @@ -70,10 +66,13 @@ public: const bool isCompleted() const { return completed; } private Q_SLOTS: - void onOffsetChanged(double); - void onOffset2Changed(double); - void onOffset3Changed(double); - void onAngleChanged(double); + void onSuperplacementChanged(double, int idx); + void onSuperplacementXChanged(double); + void onSuperplacementYChanged(double); + void onSuperplacementZChanged(double); + void onSuperplacementYawChanged(double); + void onSuperplacementPitchChanged(double); + void onSuperplacementRollChanged(double); void onCheckFlip(bool); void onRefName1(const QString& text); void onRefName2(const QString& text); @@ -92,7 +91,7 @@ private: void resetViewMode(); void objectDeleted(const Gui::ViewProviderDocumentObject&); void onSelectionChanged(const Gui::SelectionChanges& msg); - void updateUI(); + void updateReferencesUI(); /** * @brief updatePreview: calculate attachment, update 3d view, update status message @@ -105,6 +104,7 @@ private: void onButtonRef(const bool checked, unsigned idx); void onRefName(const QString& text, unsigned idx); void updateRefButton(int idx); + void updateSuperplacementUI(); /** * @brief updateListOfModes Fills the mode list with modes that apply to diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.ui b/src/Mod/PartDesign/Gui/TaskDatumParameters.ui index fcb4e49bd..8c234ac5b 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.ui @@ -7,7 +7,7 @@ 0 0 272 - 560 + 583 @@ -109,28 +109,38 @@ + + + + Mirror of superPlacement property. Extra placement is expressed in local space of object being attached. + + + Extra placement: + + + + + + 0 + 0 + + - OffsetZ + X - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 1.000000000000000 - - - 0.000000000000000 + + + + 0 + 0 + @@ -140,24 +150,24 @@ + + + 0 + 0 + + - OffsetY + Y - - - -999999999.000000000000000 - - - 999999999.000000000000000 - - - 1.000000000000000 - - - 0.000000000000000 + + + + 0 + 0 + @@ -167,23 +177,62 @@ + + + 0 + 0 + + - OffsetX + Z - - - -999999999.000000000000000 + + + + 0 + 0 + - - 999999999.000000000000000 + + + + + + + + + + + 0 + 0 + - - 1.000000000000000 + + Yaw - + + + + + + + 0 + 0 + + + + deg + + + -360.000000000000000 + + + 360.000000000000000 + + 0.000000000000000 @@ -191,26 +240,77 @@ - + - + + + + 0 + 0 + + - RotateXY + Pitch - - + + + + 0 + 0 + + + + deg + + -360.000000000000000 - + 360.000000000000000 - - 1.000000000000000 + + 0.000000000000000 - + + + + + + + + + + + 0 + 0 + + + + Roll + + + + + + + + 0 + 0 + + + + deg + + + -360.000000000000000 + + + 360.000000000000000 + + 0.000000000000000 @@ -226,6 +326,18 @@ + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+ + Gui::PrefQuantitySpinBox + QWidget +
Gui/PrefWidgets.h
+
+