diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 63e2aa57b0..1fef06a335 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -121,6 +121,11 @@ int EditDatumDialog::exec(bool atCursor) } double datum = Constr->getValue(); + bool showRadiusDiameterBtns = Constr->Type == Sketcher::Radius + || Constr->Type == Sketcher::Diameter; + ui_ins_datum->rbRadius->setVisible(showRadiusDiameterBtns); + ui_ins_datum->rbDiameter->setVisible(showRadiusDiameterBtns); + ui_ins_datum->labelEdit->setEntryName(QByteArray("DatumValue")); if (Constr->Type == Sketcher::Angle) { datum = Base::toDegrees(datum); @@ -138,6 +143,7 @@ int EditDatumDialog::exec(bool atCursor) ui_ins_datum->labelEdit->setParamGrpPath( QByteArray("User parameter:BaseApp/History/SketcherLength") ); + ui_ins_datum->rbRadius->setChecked(true); } else if (Constr->Type == Sketcher::Diameter) { dlg.setWindowTitle(tr("Insert Diameter")); @@ -146,6 +152,7 @@ int EditDatumDialog::exec(bool atCursor) ui_ins_datum->labelEdit->setParamGrpPath( QByteArray("User parameter:BaseApp/History/SketcherLength") ); + ui_ins_datum->rbDiameter->setChecked(true); } else if (Constr->Type == Sketcher::Weight) { dlg.setWindowTitle(tr("Insert Weight")); @@ -194,6 +201,7 @@ int EditDatumDialog::exec(bool atCursor) this, &EditDatumDialog::formEditorOpened ); + connect(ui_ins_datum->rbRadius, &QRadioButton::toggled, this, &EditDatumDialog::typeChanged); connect(&dlg, &QDialog::accepted, this, &EditDatumDialog::accepted); connect(&dlg, &QDialog::rejected, this, &EditDatumDialog::rejected); @@ -217,8 +225,41 @@ int EditDatumDialog::exec(bool atCursor) return QDialog::Rejected; } +void EditDatumDialog::typeChanged(bool checked) +{ + if (!ui_ins_datum->rbRadius->isVisible()) { + return; + } + + // Updates UI labels based on selection, but does NOT change value yet + QWidget* dlg = ui_ins_datum->labelEdit->parentWidget(); + while (dlg && !dlg->isWindow()) { + dlg = dlg->parentWidget(); + } + if (ui_ins_datum->rbRadius->isChecked()) { + ui_ins_datum->label->setText(tr("Radius")); + if (dlg) { + dlg->setWindowTitle(tr("Insert Radius")); + } + } + else { + ui_ins_datum->label->setText(tr("Diameter")); + if (dlg) { + dlg->setWindowTitle(tr("Insert Diameter")); + } + } +} + void EditDatumDialog::accepted() { + // Check if we need to swap Radius <-> Diameter + if (Constr->Type == Sketcher::Radius && ui_ins_datum->rbDiameter->isChecked()) { + Constr->Type = Sketcher::Diameter; + } + else if (Constr->Type == Sketcher::Diameter && ui_ins_datum->rbRadius->isChecked()) { + Constr->Type = Sketcher::Radius; + } + Base::Quantity newQuant = ui_ins_datum->labelEdit->value(); if (Constr->Type == Sketcher::SnellsLaw || Constr->Type == Sketcher::Weight || !newQuant.isDimensionless()) { diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.h b/src/Mod/Sketcher/Gui/EditDatumDialog.h index 8098efe674..53a514bb0f 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.h +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.h @@ -67,6 +67,7 @@ private Q_SLOTS: void drivingToggled(bool); void datumChanged(); void formEditorOpened(bool); + void typeChanged(bool); private: void performAutoScale(double newDatum); diff --git a/src/Mod/Sketcher/Gui/InsertDatum.ui b/src/Mod/Sketcher/Gui/InsertDatum.ui index aaa343ff36..b3c9ccc765 100644 --- a/src/Mod/Sketcher/Gui/InsertDatum.ui +++ b/src/Mod/Sketcher/Gui/InsertDatum.ui @@ -64,6 +64,24 @@ + + + + + + Radius + + + + + + + Diameter + + + + +