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;
}

View File

@@ -114,6 +114,8 @@ public:
int setDriving(int ConstrId, bool isdriving);
/// get the driving status of this constraint
int getDriving(int ConstrId, bool &isdriving);
/// toggle the driving status of this constraint
int toggleDriving(int ConstrId);
/// move this point to a new location and solve
int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false);
/// retrieves the coordinates of a point

View File

@@ -87,6 +87,11 @@
<Documentation>
<UserDocu>Get the Driving status of a datum constraint</UserDocu>
</Documentation>
</Methode>
<Methode Name="toggleDriving">
<Documentation>
<UserDocu>toggle the Driving status of a datum constraint</UserDocu>
</Documentation>
</Methode>
<Methode Name="movePoint">
<Documentation>

View File

@@ -49,7 +49,7 @@ using namespace Sketcher;
// returns a string which represents the object e.g. when printed in python
std::string SketchObjectPy::representation(void) const
{
{
return "<Sketcher::SketchObject>";
}
@@ -578,7 +578,7 @@ PyObject* SketchObjectPy::setDriving(PyObject *args)
if (this->getSketchObjectPtr()->setDriving(constrid, PyObject_IsTrue(driving) ? true : false)) {
std::stringstream str;
str << "Not able set Driving for constraint with the given index: " << constrid;
str << "Not able set Driving/reference for constraint with the given index: " << constrid;
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
@@ -603,6 +603,23 @@ PyObject* SketchObjectPy::getDriving(PyObject *args)
return Py::new_reference_to(Py::Boolean(driving));
}
PyObject* SketchObjectPy::toggleDriving(PyObject *args)
{
int constrid;
if (!PyArg_ParseTuple(args, "i", &constrid))
return 0;
if (this->getSketchObjectPtr()->toggleDriving(constrid)) {
std::stringstream str;
str << "Not able toggle Driving for constraint with the given index: " << constrid;
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
}
Py_Return;
}
PyObject* SketchObjectPy::movePoint(PyObject *args)
{