From 4e2ae6f40828358377fc8ef4ab69883558fbe1ac Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 27 Jan 2019 13:52:52 +0100 Subject: [PATCH] Part: Rearrange inheritance not to use ArcPy ============================================ Inheritance: Geometry - GeomPoint - GeomCurve (GeometryCurvePy) - - GeomBoundedCurve (BoundedCurvePy) - - - GeomBezierCurve (BezierCurvePy) - - - GeomBSplineCurve (BSplineCurvePy) - - - GeomTrimmedCurve (TrimmedCurvePy) - - - - GeomArcOfConic (ArcOfConicPy) - - - - - GeomArcOfCircle (ArcOfCirclePy) - - - - - GeomArcOfEllipse (ArcOfEllipsePy) - - - - - GeomArcOfHyperbola (ArcOfHyperbolaPy) - - - - - GeomArcOfParabola (ArcOfParabolaPy) - - - - GeomLineSegment (LineSegmentPy) - - GeomConic - - - GeomCircle - - - GeomEllipse - - - GeomHyperbola - - - GeomParabola - - GeomLine - - GeomOffsetCurve * Note: ArcPy is also a twinclass of c++ GeomTrimmedCurve, Python ArcPy derives from Python TrimmedCurvePy. Same functionality as before: >>> geometries = ActiveSketch.Geometry >>> line = geometries[1] >>> arc = geometries[2] >>> line >>> arc ArcOfCircle (Radius : 19.3111, Position : (-74.6914, -23.2165, 0), Direction : (0, 0, 1), Parameter : (1.82335, 2.71597)) >>> line.FirstParameter 0.0 >>> line.LastParameter 16.783437032695776 >>> line.setParameterRange(0,20) >>> line.LastParameter 20.0 >>> arc.StartPoint Vector (-79.51683708894876, -4.517938119394778, 0.0) >>> arc.EndPoint Vector (-92.27963885411512, -15.243140671641918, 0.0) >>> arc.setParameterRange(1.5,3) >>> arc ArcOfCircle (Radius : 19.3111, Position : (-74.6914, -23.2165, 0), Direction : (0, 0, 1), Parameter : (1.5, 3)) >>> geometries[1] = line >>> geometries[2] = arc >>> ActiveSketch.Geometry = geometries >>> ActiveSketch.solve() 0 >>> --- src/Mod/Part/App/ArcOfConicPy.xml | 4 +- src/Mod/Part/App/ArcPy.xml | 11 +-- src/Mod/Part/App/ArcPyImp.cpp | 25 ------- src/Mod/Part/App/BoundedCurvePyImp.cpp | 2 +- src/Mod/Part/App/CMakeLists.txt | 3 + src/Mod/Part/App/LineSegmentPy.xml | 4 +- src/Mod/Part/App/TrimmedCurvePy.xml | 28 ++++++++ src/Mod/Part/App/TrimmedCurvePyImp.cpp | 93 ++++++++++++++++++++++++++ 8 files changed, 131 insertions(+), 39 deletions(-) create mode 100644 src/Mod/Part/App/TrimmedCurvePy.xml create mode 100644 src/Mod/Part/App/TrimmedCurvePyImp.cpp diff --git a/src/Mod/Part/App/ArcOfConicPy.xml b/src/Mod/Part/App/ArcOfConicPy.xml index 487afdc330..43745ba0fe 100644 --- a/src/Mod/Part/App/ArcOfConicPy.xml +++ b/src/Mod/Part/App/ArcOfConicPy.xml @@ -1,14 +1,14 @@ diff --git a/src/Mod/Part/App/ArcPy.xml b/src/Mod/Part/App/ArcPy.xml index 0e09e690d0..32948233c9 100644 --- a/src/Mod/Part/App/ArcPy.xml +++ b/src/Mod/Part/App/ArcPy.xml @@ -1,14 +1,14 @@ @@ -29,12 +29,5 @@ const Geom_Ellipse & value(void) const {return *getGeom_EllipsePtr();} --> - - - - Re-trims this curve to the provided parameter range ([Float=First, Float=Last]) - - - diff --git a/src/Mod/Part/App/ArcPyImp.cpp b/src/Mod/Part/App/ArcPyImp.cpp index bd6f217269..47348a19e8 100644 --- a/src/Mod/Part/App/ArcPyImp.cpp +++ b/src/Mod/Part/App/ArcPyImp.cpp @@ -197,31 +197,6 @@ int ArcPy::PyInit(PyObject* args, PyObject* /*kwd*/) return -1; } -PyObject* ArcPy::setParameterRange(PyObject * args) -{ - Handle(Geom_Geometry) g = getGeomTrimmedCurvePtr()->handle(); - Handle(Geom_TrimmedCurve) c = Handle(Geom_TrimmedCurve)::DownCast(g); - try { - if (!c.IsNull()) { - double u,v; - u=c->FirstParameter(); - v=c->LastParameter(); - if (!PyArg_ParseTuple(args, "|dd", &u,&v)) - return 0; - getGeomTrimmedCurvePtr()->setRange(u,v); - Py_Return; - } - } - catch (Base::CADKernelError& e) { - PyErr_SetString(PartExceptionOCCError, e.what()); - return 0; - } - - PyErr_SetString(PartExceptionOCCError, "Geometry is not a trimmed curve"); - return 0; -} - - PyObject *ArcPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/Part/App/BoundedCurvePyImp.cpp b/src/Mod/Part/App/BoundedCurvePyImp.cpp index 1e0b65acb2..47e9c2b0f3 100644 --- a/src/Mod/Part/App/BoundedCurvePyImp.cpp +++ b/src/Mod/Part/App/BoundedCurvePyImp.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2009 Werner Mayer * + * Copyright (c) 2019 Abdullah Tahiri diff --git a/src/Mod/Part/App/TrimmedCurvePy.xml b/src/Mod/Part/App/TrimmedCurvePy.xml new file mode 100644 index 0000000000..5749c3ca46 --- /dev/null +++ b/src/Mod/Part/App/TrimmedCurvePy.xml @@ -0,0 +1,28 @@ + + + + + + + The abstract class TrimmedCurve is the root class of all trimmed curve objects. + + + + + + Re-trims this curve to the provided parameter range ([Float=First, Float=Last]) + + + + + diff --git a/src/Mod/Part/App/TrimmedCurvePyImp.cpp b/src/Mod/Part/App/TrimmedCurvePyImp.cpp new file mode 100644 index 0000000000..40a365905d --- /dev/null +++ b/src/Mod/Part/App/TrimmedCurvePyImp.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (c) 2019 Abdullah Tahiri +#endif + +#include +#include + +#include "OCCError.h" + +#include "Geometry.h" +#include "TrimmedCurvePy.h" +#include "TrimmedCurvePy.cpp" + + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string TrimmedCurvePy::representation(void) const +{ + return ""; +} + +PyObject *TrimmedCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // never create such objects with the constructor + PyErr_SetString(PyExc_RuntimeError, + "You cannot create an instance of the abstract class 'BoundedCurve'."); + return 0; +} + +// constructor method +int TrimmedCurvePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) +{ + return 0; +} + +PyObject* TrimmedCurvePy::setParameterRange(PyObject * args) +{ + Handle(Geom_Geometry) g = getGeomTrimmedCurvePtr()->handle(); + Handle(Geom_TrimmedCurve) c = Handle(Geom_TrimmedCurve)::DownCast(g); + try { + if (!c.IsNull()) { + double u,v; + u=c->FirstParameter(); + v=c->LastParameter(); + if (!PyArg_ParseTuple(args, "|dd", &u,&v)) + return 0; + getGeomTrimmedCurvePtr()->setRange(u,v); + Py_Return; + } + } + catch (Base::CADKernelError& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a trimmed curve"); + return 0; +} + +PyObject *TrimmedCurvePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int TrimmedCurvePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}