From 6a1aed66e2576dc349903aca66c5064afb06e030 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 29 Oct 2018 11:51:12 +0100 Subject: [PATCH] Sketcher: Refactor code relating to dimensional constraint checks --- src/Mod/Sketcher/App/SketchObject.cpp | 49 +++---------------- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 8 +-- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 8 +-- .../Sketcher/Gui/TaskSketcherConstrains.cpp | 22 +++------ src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 8 +-- 5 files changed, 17 insertions(+), 78 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index c0d4383aa3..63646962b5 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -298,15 +298,9 @@ int SketchObject::setDatum(int ConstrId, double Datum) if (ConstrId < 0 || ConstrId >= int(vals.size())) return -1; ConstraintType type = vals[ConstrId]->Type; - if (type != Distance && - type != DistanceX && - type != DistanceY && - type != Radius && - type != Diameter && - type != Angle && + if (!vals[ConstrId]->isDimensional() && type != Tangent && //for tangent, value==0 is autodecide, value==Pi/2 is external and value==-Pi/2 is internal - type != Perpendicular && - type != SnellsLaw) + type != Perpendicular) return -1; if ((type == Distance || type == Radius || type == Diameter) && Datum <= 0) @@ -334,16 +328,8 @@ int SketchObject::setDriving(int ConstrId, bool isdriving) if (ConstrId < 0 || ConstrId >= int(vals.size())) return -1; - - ConstraintType type = vals[ConstrId]->Type; - if (type != Distance && - type != DistanceX && - type != DistanceY && - type != Radius && - type != Diameter && - type != Angle && - type != SnellsLaw) + if (!vals[ConstrId]->isDimensional()) return -2; if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && isdriving==true) @@ -373,15 +359,7 @@ int SketchObject::getDriving(int ConstrId, bool &isdriving) if (ConstrId < 0 || ConstrId >= int(vals.size())) return -1; - ConstraintType type = vals[ConstrId]->Type; - - if (type != Distance && - type != DistanceX && - type != DistanceY && - type != Radius && - type != Diameter && - type != Angle && - type != SnellsLaw) + if (!vals[ConstrId]->isDimensional()) return -1; isdriving=vals[ConstrId]->isDriving; @@ -394,16 +372,8 @@ int SketchObject::toggleDriving(int ConstrId) if (ConstrId < 0 || ConstrId >= int(vals.size())) return -1; - - ConstraintType type = vals[ConstrId]->Type; - if (type != Distance && - type != DistanceX && - type != DistanceY && - type != Radius && - type != Diameter && - type != Angle && - type != SnellsLaw) + if (!vals[ConstrId]->isDimensional()) return -2; if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && vals[ConstrId]->isDriving==false) @@ -933,14 +903,7 @@ int SketchObject::addCopyOfConstraints(const SketchObject &orig) this->Constraints.setValues(newVals); for(std::size_t i = valssize, j = 0; iisDriving && ( - newVals[i]->Type == Sketcher::Distance || - newVals[i]->Type == Sketcher::DistanceX || - newVals[i]->Type == Sketcher::DistanceY || - newVals[i]->Type == Sketcher::Radius || - newVals[i]->Type == Sketcher::Diameter || - newVals[i]->Type == Sketcher::Angle || - newVals[i]->Type == Sketcher::SnellsLaw)) { + if ( newVals[i]->isDriving && newVals[i]->isDimensional()) { App::ObjectIdentifier spath = orig.Constraints.createPath(j); diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 5b85d231c0..b6d26e41b0 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -92,13 +92,7 @@ void openEditDatumDialog(Sketcher::SketchObject* sketch, int ConstrNbr) Sketcher::Constraint* Constr = Constraints[ConstrNbr]; // Return if constraint doesn't have editable value - if (Constr->Type == Sketcher::Distance || - Constr->Type == Sketcher::DistanceX || - Constr->Type == Sketcher::DistanceY || - Constr->Type == Sketcher::Radius || - Constr->Type == Sketcher::Diameter || - Constr->Type == Sketcher::Angle || - Constr->Type == Sketcher::SnellsLaw) { + if (Constr->isDimensional()) { QDialog dlg(Gui::getMainWindow()); Ui::InsertDatum ui_ins_datum; diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index e2a2dbd9b8..eec1b16301 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -73,13 +73,7 @@ void EditDatumDialog::customEvent(QEvent*) void EditDatumDialog::exec(bool atCursor) { // Return if constraint doesn't have editable value - if (Constr->Type == Sketcher::Distance || - Constr->Type == Sketcher::DistanceX || - Constr->Type == Sketcher::DistanceY || - Constr->Type == Sketcher::Radius || - Constr->Type == Sketcher::Diameter || - Constr->Type == Sketcher::Angle || - Constr->Type == Sketcher::SnellsLaw) { + if (Constr->isDimensional()) { if (sketch->hasConflicts()) { QMessageBox::critical(qApp->activeWindow(), QObject::tr("Distance constraint"), diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index cbc4caa5f1..603ba57afc 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -317,6 +317,12 @@ public: } return false; } + + bool isDimensional() const { + assert(ConstraintNbr >= 0 && ConstraintNbr < sketch->Constraints.getSize()); + + return (sketch->Constraints[ConstraintNbr])->isDimensional(); + } bool isDriving() const { assert(ConstraintNbr >= 0 && ConstraintNbr < sketch->Constraints.getSize()); @@ -422,13 +428,7 @@ void ConstraintView::contextMenuEvent (QContextMenuEvent* event) ConstraintItem *it = dynamic_cast(item); if (it) { // if its the right constraint - if ((it->constraintType() == Sketcher::Distance || - it->constraintType() == Sketcher::DistanceX || - it->constraintType() == Sketcher::DistanceY || - it->constraintType() == Sketcher::Radius || - it->constraintType() == Sketcher::Diameter || - it->constraintType() == Sketcher::Angle || - it->constraintType() == Sketcher::SnellsLaw)) { + if (it->isDimensional()) { isQuantity = true; if (it->isEnforceable()) @@ -732,13 +732,7 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemActivated(QListWidgetI if (!it) return; // if its the right constraint - if (it->constraintType() == Sketcher::Distance || - it->constraintType() == Sketcher::DistanceX || - it->constraintType() == Sketcher::DistanceY || - it->constraintType() == Sketcher::Radius || - it->constraintType() == Sketcher::Diameter || - it->constraintType() == Sketcher::Angle || - it->constraintType() == Sketcher::SnellsLaw) { + if (it->isDimensional()) { EditDatumDialog *editDatumDialog = new EditDatumDialog(this->sketchView, it->ConstraintNbr); editDatumDialog->exec(false); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index a2dc477468..eb82280cef 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1005,13 +1005,7 @@ void ViewProviderSketch::editDoubleClicked(void) Constraint *Constr = constrlist[*it]; // if its the right constraint - if ((Constr->Type == Sketcher::Distance || - Constr->Type == Sketcher::DistanceX || - Constr->Type == Sketcher::DistanceY || - Constr->Type == Sketcher::Radius || - Constr->Type == Sketcher::Diameter || - Constr->Type == Sketcher::Angle || - Constr->Type == Sketcher::SnellsLaw)) { + if (Constr->isDimensional()) { if(!Constr->isDriving) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)",