Sketcher: expose the LabelDistance and LabelPosition members of Constraint to Python
This commit is contained in:
@@ -88,5 +88,17 @@
|
||||
</Documentation>
|
||||
<Parameter Name="IsActive" Type="Boolean"/>
|
||||
</Attribute>
|
||||
<Attribute Name="LabelDistance" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Label distance</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="LabelDistance" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="LabelPosition" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>Label position</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="LabelPosition" Type="Float"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
|
||||
@@ -822,6 +822,16 @@ Py::Float ConstraintPy::getValue() const
|
||||
return Py::Float(this->getConstraintPtr()->getValue());
|
||||
}
|
||||
|
||||
Py::Float ConstraintPy::getLabelDistance() const
|
||||
{
|
||||
return Py::Float(this->getConstraintPtr()->LabelDistance);
|
||||
}
|
||||
|
||||
Py::Float ConstraintPy::getLabelPosition() const
|
||||
{
|
||||
return Py::Float(this->getConstraintPtr()->LabelPosition);
|
||||
}
|
||||
|
||||
Py::Boolean ConstraintPy::getDriving() const
|
||||
{
|
||||
return Py::Boolean(this->getConstraintPtr()->isDriving);
|
||||
|
||||
@@ -592,6 +592,74 @@ int SketchObject::toggleActive(int ConstrId)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::setLabelPosition(int ConstrId, float value)
|
||||
{
|
||||
Base::StateLocker lock(managedoperation, true);
|
||||
|
||||
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->LabelPosition = value;
|
||||
newVals[ConstrId] = constNew;
|
||||
this->Constraints.setValues(std::move(newVals));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::getLabelPosition(int ConstrId, float& value)
|
||||
{
|
||||
const std::vector<Constraint*>& vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size())) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = vals[ConstrId]->LabelPosition;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::setLabelDistance(int ConstrId, float value)
|
||||
{
|
||||
Base::StateLocker lock(managedoperation, true);
|
||||
|
||||
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->LabelDistance = value;
|
||||
newVals[ConstrId] = constNew;
|
||||
this->Constraints.setValues(std::move(newVals));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SketchObject::getLabelDistance(int ConstrId, float& value)
|
||||
{
|
||||
const std::vector<Constraint*>& vals = this->Constraints.getValues();
|
||||
|
||||
if (ConstrId < 0 || ConstrId >= int(vals.size())) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = vals[ConstrId]->LabelDistance;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// Make all dimensionals Driving/non-Driving
|
||||
int SketchObject::setDatumsDriving(bool isdriving)
|
||||
|
||||
@@ -264,6 +264,15 @@ public:
|
||||
/// toggle the driving status of this constraint
|
||||
int toggleActive(int ConstrId);
|
||||
|
||||
/// set the label position of the constraint
|
||||
int setLabelPosition(int ConstrId, float value);
|
||||
/// get the label position of the constraint
|
||||
int getLabelPosition(int ConstrId, float& value);
|
||||
/// set the label distance of the constraint
|
||||
int setLabelDistance(int ConstrId, float value);
|
||||
/// get the label distance of the constraint
|
||||
int getLabelDistance(int ConstrId, float& value);
|
||||
|
||||
/// Make all dimensionals Driving/non-Driving
|
||||
int setDatumsDriving(bool isdriving);
|
||||
/// Move Dimensional constraints at the end of the properties array
|
||||
|
||||
@@ -418,6 +418,62 @@ toggleActive(constraintIndex:int)
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getLabelPosition" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Get label position of the constraint.
|
||||
|
||||
getLabelPosition(constraintIndex:int)
|
||||
|
||||
Args:
|
||||
constraintIndex: The zero-based index of the constraint to query.
|
||||
|
||||
Returns:
|
||||
float with the current value.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setLabelPosition">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Set label position of the constraint.
|
||||
|
||||
setLabelPosition(constraintIndex:int, value:float)
|
||||
|
||||
Args:
|
||||
constraintIndex: The zero-based index of the constraint to query.
|
||||
value: Value of the label position.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getLabelDistance" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Get label distance of the constraint.
|
||||
|
||||
getLabelDistance(constraintIndex:int)
|
||||
|
||||
Args:
|
||||
constraintIndex: The zero-based index of the constraint to query.
|
||||
|
||||
Returns:
|
||||
float with the current value.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setLabelDistance">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
Set label distance of the constraint.
|
||||
|
||||
setLabelDistance(constraintIndex:int, value:float)
|
||||
|
||||
Args:
|
||||
constraintIndex: The zero-based index of the constraint to query.
|
||||
value: Value of the label position.
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="movePoint">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -1041,6 +1041,74 @@ PyObject* SketchObjectPy::toggleActive(PyObject* args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::getLabelPosition(PyObject* args)
|
||||
{
|
||||
int constrid {};
|
||||
float pos {};
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &constrid)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->getSketchObjectPtr()->getLabelPosition(constrid, pos)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Py::new_reference_to(Py::Float(pos));
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::setLabelPosition(PyObject* args)
|
||||
{
|
||||
int constrid {};
|
||||
float pos {};
|
||||
|
||||
if (!PyArg_ParseTuple(args, "if", &constrid, &pos)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->getSketchObjectPtr()->setLabelPosition(constrid, pos)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::getLabelDistance(PyObject* args)
|
||||
{
|
||||
int constrid {};
|
||||
float dist {};
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &constrid)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->getSketchObjectPtr()->getLabelDistance(constrid, dist)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Py::new_reference_to(Py::Float(dist));
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::setLabelDistance(PyObject* args)
|
||||
{
|
||||
int constrid {};
|
||||
float dist {};
|
||||
|
||||
if (!PyArg_ParseTuple(args, "if", &constrid, &dist)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (this->getSketchObjectPtr()->setLabelDistance(constrid, dist)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* SketchObjectPy::movePoint(PyObject* args)
|
||||
{
|
||||
PyObject* pcObj;
|
||||
|
||||
Reference in New Issue
Block a user