Sketcher: expose the LabelDistance and LabelPosition members of Constraint to Python

This commit is contained in:
wmayer
2024-02-22 13:56:30 +01:00
committed by wwmayer
parent 41b3be8fb6
commit a2315503fa
6 changed files with 223 additions and 0 deletions

View File

@@ -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>

View File

@@ -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);

View File

@@ -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)

View File

@@ -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

View File

@@ -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>

View File

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