diff --git a/src/Mod/Sketcher/App/ConstraintPy.xml b/src/Mod/Sketcher/App/ConstraintPy.xml index 88e8461ec6..34b1c75ec9 100644 --- a/src/Mod/Sketcher/App/ConstraintPy.xml +++ b/src/Mod/Sketcher/App/ConstraintPy.xml @@ -88,5 +88,17 @@ + + + Label distance + + + + + + Label position + + + diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index 8a15fdb4fb..831f770fea 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -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); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 82a9455b5c..ba972818a1 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -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& vals = this->Constraints.getValues(); + + if (ConstrId < 0 || ConstrId >= int(vals.size())) { + return -1; + } + + // copy the list + std::vector 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& 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& vals = this->Constraints.getValues(); + + if (ConstrId < 0 || ConstrId >= int(vals.size())) { + return -1; + } + + // copy the list + std::vector 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& 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) diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 5e78fe4f16..8a72250b67 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -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 diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index d47884a050..52df924057 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -418,6 +418,62 @@ toggleActive(constraintIndex:int) + + + +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. + + + + + + +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. + + + + + + +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. + + + + + + +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. + + + diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 79f814ce43..ee192870f5 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -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;