[Sketcher] Constraint driving/driven status integration in dimension edition dialog
This integrates the ability to manage dimensional constraint driving/driven status in the constraint edition dialog box. It adds a checkbox in the dialog to show/select whether a constraint is driving or driven. When the constraint value is modified, it is automatically set as driving. Main focus is to allow to edit name (alias) of reference (driven) constraints directly in the constraint edition box. Resolves #3793, #3978
This commit is contained in:
@@ -39,7 +39,6 @@
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include "ViewProviderSketch.h"
|
||||
#include "ui_InsertDatum.h"
|
||||
#include "EditDatumDialog.h"
|
||||
#include "CommandConstraints.h"
|
||||
|
||||
@@ -63,11 +62,11 @@ EditDatumDialog::EditDatumDialog(Sketcher::SketchObject* pcSketch, int ConstrNbr
|
||||
|
||||
EditDatumDialog::~EditDatumDialog(){}
|
||||
|
||||
void EditDatumDialog::customEvent(QEvent*)
|
||||
/*void EditDatumDialog::customEvent(QEvent*)
|
||||
{
|
||||
this->exec();
|
||||
this->deleteLater();
|
||||
}
|
||||
}*/
|
||||
|
||||
void EditDatumDialog::exec(bool atCursor)
|
||||
{
|
||||
@@ -83,7 +82,6 @@ void EditDatumDialog::exec(bool atCursor)
|
||||
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
|
||||
QDialog dlg(mdi);
|
||||
|
||||
Ui::InsertDatum ui_ins_datum;
|
||||
ui_ins_datum.setupUi(&dlg);
|
||||
double datum = Constr->getValue();
|
||||
Base::Quantity init_val;
|
||||
@@ -119,65 +117,103 @@ void EditDatumDialog::exec(bool atCursor)
|
||||
ui_ins_datum.labelEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/SketcherLength"));
|
||||
}
|
||||
|
||||
|
||||
//ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum");
|
||||
|
||||
init_val.setValue(datum);
|
||||
|
||||
// Enable label if we are modifying a driving constraint
|
||||
ui_ins_datum.labelEdit->setEnabled(Constr->isDriving);
|
||||
|
||||
ui_ins_datum.labelEdit->setValue(init_val);
|
||||
ui_ins_datum.labelEdit->pushToHistory();
|
||||
ui_ins_datum.labelEdit->selectNumber();
|
||||
ui_ins_datum.labelEdit->bind(sketch->Constraints.createPath(ConstrNbr));
|
||||
ui_ins_datum.name->setText(Base::Tools::fromStdString(Constr->Name));
|
||||
|
||||
ui_ins_datum.cbDriving->setChecked(! Constr->isDriving);
|
||||
|
||||
connect(ui_ins_datum.cbDriving, SIGNAL(toggled(bool)), this, SLOT(drivingToggled(bool)));
|
||||
connect(ui_ins_datum.labelEdit, SIGNAL(valueChanged(const Base::Quantity&)), this, SLOT(datumChanged()));
|
||||
connect(ui_ins_datum.labelEdit, SIGNAL(showFormulaDialog(bool)), this, SLOT(formEditorOpened(bool)));
|
||||
connect(&dlg, SIGNAL(accepted()), this, SLOT(accepted()));
|
||||
connect(&dlg, SIGNAL(rejected()), this, SLOT(rejected()));
|
||||
|
||||
if (atCursor)
|
||||
dlg.setGeometry(QCursor::pos().x() - dlg.geometry().width() / 2, QCursor::pos().y(), dlg.geometry().width(), dlg.geometry().height());
|
||||
|
||||
dlg.exec();
|
||||
this->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
Gui::Command::openCommand("Modify sketch constraints");
|
||||
|
||||
if (dlg.exec()) {
|
||||
Base::Quantity newQuant = ui_ins_datum.labelEdit->value();
|
||||
if (newQuant.isQuantity() || (Constr->Type == Sketcher::SnellsLaw && newQuant.isDimensionless())) {
|
||||
// save the value for the history
|
||||
ui_ins_datum.labelEdit->pushToHistory();
|
||||
|
||||
double newDatum = newQuant.getValue();
|
||||
|
||||
try {
|
||||
|
||||
if (Constr->isDriving) {
|
||||
if (ui_ins_datum.labelEdit->hasExpression())
|
||||
ui_ins_datum.labelEdit->apply();
|
||||
else
|
||||
Gui::cmdAppObjectArgs(sketch, "setDatum(%i,App.Units.Quantity('%f %s'))",
|
||||
ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8());
|
||||
}
|
||||
|
||||
QString constraintName = ui_ins_datum.name->text().trimmed();
|
||||
if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) {
|
||||
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData());
|
||||
Gui::cmdAppObjectArgs(sketch, "renameConstraint(%d, u'%s')",
|
||||
ConstrNbr, escapedstr.c_str());
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
if (sketch->noRecomputes && sketch->ExpressionEngine.depsAreTouched()) {
|
||||
sketch->ExpressionEngine.execute();
|
||||
sketch->solve();
|
||||
}
|
||||
|
||||
tryAutoRecompute(sketch);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what()));
|
||||
Gui::Command::abortCommand();
|
||||
}
|
||||
void EditDatumDialog::accepted()
|
||||
{
|
||||
Base::Quantity newQuant = ui_ins_datum.labelEdit->value();
|
||||
if (newQuant.isQuantity() || (Constr->Type == Sketcher::SnellsLaw && newQuant.isDimensionless())) {
|
||||
// save the value for the history
|
||||
ui_ins_datum.labelEdit->pushToHistory();
|
||||
|
||||
double newDatum = newQuant.getValue();
|
||||
|
||||
try {
|
||||
|
||||
/*if (ui_ins_datum.cbDriving->isChecked() == Constr->isDriving) {
|
||||
Gui::cmdAppObjectArgs(sketch, "toggleDriving(%i)", ConstrNbr);
|
||||
}*/
|
||||
|
||||
if (! ui_ins_datum.cbDriving->isChecked()) {
|
||||
if (ui_ins_datum.labelEdit->hasExpression())
|
||||
ui_ins_datum.labelEdit->apply();
|
||||
else
|
||||
Gui::cmdAppObjectArgs(sketch, "setDatum(%i,App.Units.Quantity('%f %s'))",
|
||||
ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8());
|
||||
}
|
||||
} else {
|
||||
|
||||
QString constraintName = ui_ins_datum.name->text().trimmed();
|
||||
if (Base::Tools::toStdString(constraintName) != sketch->Constraints[ConstrNbr]->Name) {
|
||||
std::string escapedstr = Base::Tools::escapedUnicodeFromUtf8(constraintName.toUtf8().constData());
|
||||
Gui::cmdAppObjectArgs(sketch, "renameConstraint(%d, u'%s')",
|
||||
ConstrNbr, escapedstr.c_str());
|
||||
}
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
if (sketch->noRecomputes && sketch->ExpressionEngine.depsAreTouched()) {
|
||||
sketch->ExpressionEngine.execute();
|
||||
sketch->solve();
|
||||
}
|
||||
|
||||
tryAutoRecompute(sketch);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what()));
|
||||
Gui::Command::abortCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditDatumDialog::rejected()
|
||||
{
|
||||
Gui::Command::abortCommand();
|
||||
}
|
||||
|
||||
void EditDatumDialog::drivingToggled(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
ui_ins_datum.labelEdit->setToLastUsedValue();
|
||||
}
|
||||
sketch->setDriving(ConstrNbr, !state);
|
||||
}
|
||||
|
||||
void EditDatumDialog::datumChanged()
|
||||
{
|
||||
if (ui_ins_datum.labelEdit->text() != ui_ins_datum.labelEdit->getHistory()[0]) {
|
||||
ui_ins_datum.cbDriving->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void EditDatumDialog::formEditorOpened(bool state)
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
ui_ins_datum.cbDriving->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_EditDatumDialog.cpp"
|
||||
|
||||
Reference in New Issue
Block a user