Sketcher: Refactor code relating to dimensional constraint checks
This commit is contained in:
committed by
Yorik van Havre
parent
8e2e5d7b6a
commit
6a1aed66e2
@@ -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; i<newVals.size(); i++,j++){
|
||||
if ( newVals[i]->isDriving && (
|
||||
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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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<ConstraintItem*>(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);
|
||||
|
||||
@@ -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)",
|
||||
|
||||
Reference in New Issue
Block a user