Sketcher: Python Interface for Constraint Virtual Space
======================================================= set/get/toggle python interface to enable to set the virtual space status of a constraint via SketchObject.
This commit is contained in:
@@ -417,6 +417,62 @@ int SketchObject::toggleDriving(int ConstrId)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::setVirtualSpace(int ConstrId, bool isinvirtualspace)
|
||||
{
|
||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size()))
|
||||
return -1;
|
||||
|
||||
// copy the list
|
||||
std::vector<Constraint *> newVals(vals);
|
||||
|
||||
// clone the changed Constraint
|
||||
Constraint *constNew = vals[ConstrId]->clone();
|
||||
constNew->isInVirtualSpace = isinvirtualspace;
|
||||
newVals[ConstrId] = constNew;
|
||||
|
||||
this->Constraints.setValues(newVals);
|
||||
|
||||
delete constNew;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::getVirtualSpace(int ConstrId, bool &isinvirtualspace)
|
||||
{
|
||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size()))
|
||||
return -1;
|
||||
|
||||
isinvirtualspace=vals[ConstrId]->isInVirtualSpace;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::toggleVirtualSpace(int ConstrId)
|
||||
{
|
||||
const std::vector<Constraint *> &vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size()))
|
||||
return -1;
|
||||
|
||||
// copy the list
|
||||
std::vector<Constraint *> newVals(vals);
|
||||
|
||||
// clone the changed Constraint
|
||||
Constraint *constNew = vals[ConstrId]->clone();
|
||||
constNew->isInVirtualSpace = !constNew->isInVirtualSpace;
|
||||
newVals[ConstrId] = constNew;
|
||||
|
||||
this->Constraints.setValues(newVals);
|
||||
|
||||
delete constNew;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SketchObject::setUpSketch()
|
||||
{
|
||||
return solvedSketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
|
||||
|
||||
@@ -169,6 +169,12 @@ public:
|
||||
int getDriving(int ConstrId, bool &isdriving);
|
||||
/// toggle the driving status of this constraint
|
||||
int toggleDriving(int ConstrId);
|
||||
/// set the driving status of this constraint and solve
|
||||
int setVirtualSpace(int ConstrId, bool isinvirtualspace);
|
||||
/// get the driving status of this constraint
|
||||
int getVirtualSpace(int ConstrId, bool &isinvirtualspace);
|
||||
/// toggle the driving status of this constraint
|
||||
int toggleVirtualSpace(int ConstrId);
|
||||
/// move this point to a new location and solve
|
||||
int movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative=false, bool updateGeoBeforeMoving=false);
|
||||
/// retrieves the coordinates of a point
|
||||
|
||||
@@ -102,7 +102,22 @@
|
||||
<Documentation>
|
||||
<UserDocu>toggle the Driving status of a datum constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
</Methode>
|
||||
<Methode Name="setVirtualSpace">
|
||||
<Documentation>
|
||||
<UserDocu>set the VirtualSpace status of a constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getVirtualSpace">
|
||||
<Documentation>
|
||||
<UserDocu>Get the VirtualSpace status of a constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="toggleVirtualSpace">
|
||||
<Documentation>
|
||||
<UserDocu>toggle the VirtualSpace status of a constraint</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="movePoint">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -743,6 +743,56 @@ PyObject* SketchObjectPy::toggleDriving(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::setVirtualSpace(PyObject *args)
|
||||
{
|
||||
PyObject* invirtualspace;
|
||||
int constrid;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &invirtualspace))
|
||||
return 0;
|
||||
|
||||
if (this->getSketchObjectPtr()->setVirtualSpace(constrid, PyObject_IsTrue(invirtualspace) ? true : false)) {
|
||||
std::stringstream str;
|
||||
str << "Not able set virtual space for constraint with the given index: " << constrid;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::getVirtualSpace(PyObject *args)
|
||||
{
|
||||
int constrid;
|
||||
bool invirtualspace;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &constrid))
|
||||
return 0;
|
||||
|
||||
if (this->getSketchObjectPtr()->getVirtualSpace(constrid, invirtualspace)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Py::new_reference_to(Py::Boolean(invirtualspace));
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::toggleVirtualSpace(PyObject *args)
|
||||
{
|
||||
int constrid;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &constrid))
|
||||
return 0;
|
||||
|
||||
if (this->getSketchObjectPtr()->toggleVirtualSpace(constrid)) {
|
||||
std::stringstream str;
|
||||
str << "Not able toggle virtual space for constraint with the given index: " << constrid;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::movePoint(PyObject *args)
|
||||
{
|
||||
|
||||
@@ -4036,6 +4036,8 @@ Restart:
|
||||
rebuildConstraintsVisual();
|
||||
assert(int(constrlist.size()) == edit->constrGroup->getNumChildren());
|
||||
assert(int(edit->vConstrType.size()) == edit->constrGroup->getNumChildren());
|
||||
// update the virtual space
|
||||
updateVirtualSpace();
|
||||
// go through the constraints and update the position
|
||||
i = 0;
|
||||
for (std::vector<Sketcher::Constraint *>::const_iterator it=constrlist.begin();
|
||||
@@ -5132,8 +5134,6 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
|
||||
sep->unref();
|
||||
mat->unref();
|
||||
}
|
||||
|
||||
updateVirtualSpace();
|
||||
}
|
||||
|
||||
void ViewProviderSketch::updateVirtualSpace(void)
|
||||
|
||||
Reference in New Issue
Block a user