From e104304a984dee3e95de68d666ecd8798351f927 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 22 Apr 2019 14:07:09 +0200 Subject: [PATCH] Sketcher: Make PointPos modifiable from Python --- src/Mod/Sketcher/App/ConstraintPy.xml | 22 +++---- src/Mod/Sketcher/App/ConstraintPyImp.cpp | 81 ++++++++++++++++++++---- 2 files changed, 80 insertions(+), 23 deletions(-) diff --git a/src/Mod/Sketcher/App/ConstraintPy.xml b/src/Mod/Sketcher/App/ConstraintPy.xml index 4c264a2635..5ef77d5aaa 100644 --- a/src/Mod/Sketcher/App/ConstraintPy.xml +++ b/src/Mod/Sketcher/App/ConstraintPy.xml @@ -1,13 +1,13 @@  - @@ -28,7 +28,7 @@ - + Position of first geometry index the Constraint refers to @@ -40,7 +40,7 @@ - + Position of second geometry index the Constraint refers to @@ -52,7 +52,7 @@ - + Position of third geometry index the Constraint refers to diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index 99c85f96d8..a309e9c66e 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -31,7 +31,7 @@ using namespace Sketcher; PyObject *ConstraintPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { - // create a new instance of ConstraintPy and the Twin object + // create a new instance of ConstraintPy and the Twin object return new ConstraintPy(new Constraint); } @@ -108,18 +108,18 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) } else if (strstr(ConstraintType,"InternalAlignment") != NULL) { this->getConstraintPtr()->Type = InternalAlignment; - + valid = true; if(strstr(ConstraintType,"EllipseMajorDiameter") != NULL) this->getConstraintPtr()->AlignmentType=EllipseMajorDiameter; else if(strstr(ConstraintType,"EllipseMinorDiameter") != NULL) - this->getConstraintPtr()->AlignmentType=EllipseMinorDiameter; + this->getConstraintPtr()->AlignmentType=EllipseMinorDiameter; else { this->getConstraintPtr()->AlignmentType=Undef; valid = false; } } - + if (valid) { this->getConstraintPtr()->First = FirstIndex; this->getConstraintPtr()->Second = SecondIndex; @@ -200,11 +200,11 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) } else if (strstr(ConstraintType,"InternalAlignment") != NULL) { this->getConstraintPtr()->Type = InternalAlignment; - + valid = true; - + if(strstr(ConstraintType,"EllipseFocus1") != NULL) - this->getConstraintPtr()->AlignmentType=EllipseFocus1; + this->getConstraintPtr()->AlignmentType=EllipseFocus1; else if(strstr(ConstraintType,"EllipseFocus2") != NULL) this->getConstraintPtr()->AlignmentType=EllipseFocus2; else { @@ -324,13 +324,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) valid = true; if(strstr(ConstraintType,"BSplineControlPoint") != NULL) { - this->getConstraintPtr()->AlignmentType=BSplineControlPoint; + this->getConstraintPtr()->AlignmentType=BSplineControlPoint; } else { this->getConstraintPtr()->AlignmentType=Undef; valid = false; } - + if (valid) { this->getConstraintPtr()->First = intArg1; this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2; @@ -338,7 +338,7 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->InternalAlignmentIndex = intArg4; return 0; } - + } if (valid) { this->getConstraintPtr()->First = intArg1; @@ -521,7 +521,7 @@ std::string ConstraintPy::representation(void) const break; case Symmetric : result << "'Symmetric'>"; break; case SnellsLaw : result << "'SnellsLaw'>"; break; - case InternalAlignment : + case InternalAlignment : switch(this->getConstraintPtr()->AlignmentType) { case Undef : result << "'InternalAlignment:Undef'>";break; case EllipseMajorDiameter : result << "'InternalAlignment:EllipseMajorDiameter'>";break; @@ -583,6 +583,25 @@ Py::Long ConstraintPy::getFirstPos(void) const return Py::Long(static_cast(this->getConstraintPtr()->FirstPos)); } +void ConstraintPy::setFirstPos(Py::Long arg) +{ + #if PY_MAJOR_VERSION < 3 + int pos = Py::Int(arg); + #else + int pos = arg; + #endif + + if(pos>=Sketcher::none && pos<=Sketcher::mid) { + this->getConstraintPtr()->FirstPos = (Sketcher::PointPos)pos; + } + else { + std::stringstream str; + str << "Invalid PointPos parameter: " << arg << std::endl; + + PyErr_SetString(PyExc_TypeError, str.str().c_str()); + } +} + Py::Long ConstraintPy::getSecond(void) const { return Py::Long(this->getConstraintPtr()->Second); @@ -602,6 +621,25 @@ Py::Long ConstraintPy::getSecondPos(void) const return Py::Long(static_cast(this->getConstraintPtr()->SecondPos)); } +void ConstraintPy::setSecondPos(Py::Long arg) +{ + #if PY_MAJOR_VERSION < 3 + int pos = Py::Int(arg); + #else + int pos = arg; + #endif + + if(pos>=Sketcher::none && pos<=Sketcher::mid) { + this->getConstraintPtr()->SecondPos = (Sketcher::PointPos)pos; + } + else { + std::stringstream str; + str << "Invalid PointPos parameter: " << arg << std::endl; + + PyErr_SetString(PyExc_TypeError, str.str().c_str()); + } +} + Py::Long ConstraintPy::getThird(void) const { return Py::Long(this->getConstraintPtr()->Third); @@ -621,6 +659,25 @@ Py::Long ConstraintPy::getThirdPos(void) const return Py::Long(static_cast(this->getConstraintPtr()->ThirdPos)); } +void ConstraintPy::setThirdPos(Py::Long arg) +{ + #if PY_MAJOR_VERSION < 3 + int pos = Py::Int(arg); + #else + int pos = arg; + #endif + + if(pos>=Sketcher::none && pos<=Sketcher::mid) { + this->getConstraintPtr()->ThirdPos = (Sketcher::PointPos)pos; + } + else { + std::stringstream str; + str << "Invalid PointPos parameter: " << arg << std::endl; + + PyErr_SetString(PyExc_TypeError, str.str().c_str()); + } +} + Py::String ConstraintPy::getName(void) const { return Py::String(this->getConstraintPtr()->Name); @@ -653,5 +710,5 @@ PyObject *ConstraintPy::getCustomAttributes(const char* /*attr*/) const int ConstraintPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { - return 0; + return 0; }