Sketcher: Driving/reference creation improvements and some other fixes

======================================================================

- Changing from Driving to reference does not include unnecessary solvings.
- Added some checks to avoid making Driving constraints when calling directly from python and involving only external geometry (would give redundant constraints).
- New python command toggleDriving to just change the status from reference to Driving
- New UI toolbar Command to toggle constraints
- Fix to allow switching from/to construction mode during continuous mode creation.
- Enable/Disable for constraints in constraints widget has changed to operate on multiselection and now effects "toggle" instead of enable/disable.
- Disable the option to directly create a SnellsLaw non-driving constraint (this constraint does not support direct creation, it can be toggled to non-driving after creation though).
This commit is contained in:
Abdullah Tahiri
2015-05-26 14:37:22 +02:00
committed by wmayer
parent bb00ed2142
commit 4a052bebb5
9 changed files with 180 additions and 52 deletions

View File

@@ -234,7 +234,10 @@ int SketchObject::setDriving(int ConstrId, bool isdriving)
type != Radius &&
type != Angle &&
type != SnellsLaw)
return -1;
return -2;
if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && isdriving==true)
return -3; // a constraint that does not have at least one element as not-external-geometry can never be driving.
// copy the list
std::vector<Constraint *> newVals(vals);
@@ -245,11 +248,7 @@ int SketchObject::setDriving(int ConstrId, bool isdriving)
this->Constraints.setValues(newVals);
delete constNew;
int err = solve();
if (err)
this->Constraints.setValues(vals);
return err;
return 0;
}
int SketchObject::getDriving(int ConstrId, bool &isdriving)
@@ -273,6 +272,38 @@ int SketchObject::getDriving(int ConstrId, bool &isdriving)
return 0;
}
int SketchObject::toggleDriving(int ConstrId)
{
const std::vector<Constraint *> &vals = this->Constraints.getValues();
if (ConstrId < 0 || ConstrId >= int(vals.size()))
return -1;
ConstraintType type = vals[ConstrId]->Type;
if (type != Distance &&
type != DistanceX &&
type != DistanceY &&
type != Radius &&
type != Angle &&
type != SnellsLaw)
return -2;
if (!(vals[ConstrId]->First>=0 || vals[ConstrId]->Second>=0 || vals[ConstrId]->Third>=0) && vals[ConstrId]->isDriving==false)
return -3; // a constraint that does not have at least one element as not-external-geometry can never be driving.
// copy the list
std::vector<Constraint *> newVals(vals);
// clone the changed Constraint
Constraint *constNew = vals[ConstrId]->clone();
constNew->isDriving = !constNew->isDriving;
newVals[ConstrId] = constNew;
this->Constraints.setValues(newVals);
delete constNew;
return 0;
}
int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
{
Sketch sketch;
@@ -489,7 +520,7 @@ int SketchObject::setConstruction(int GeoId, bool on)
newVals[GeoId]=geoNew;
this->Geometry.setValues(newVals);
this->Constraints.acceptGeometry(getCompleteGeometry());
//this->Constraints.acceptGeometry(getCompleteGeometry()); <= This is not necessary for a toggle. Reducing redundant solving. Abdullah
return 0;
}