From ef30cc2527f58e8e2af5fdeda89a6d88d6aba67c Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 20 Jan 2019 12:29:53 +0100 Subject: [PATCH] Part: Geometry Python interface to get/set an extension --- src/Mod/Part/App/CMakeLists.txt | 3 ++ src/Mod/Part/App/GeometryPy.xml | 10 ++++++ src/Mod/Part/App/GeometryPyImp.cpp | 52 +++++++++++++++++++++++++++ src/Mod/Sketcher/App/CMakeLists.txt | 3 ++ src/Mod/Sketcher/App/SketchObject.cpp | 13 ++++++- src/Mod/Sketcher/App/SketchObject.h | 2 ++ 6 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 3ce90d77d9..b6b0865d13 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -51,6 +51,7 @@ generate_from_xml(ArcOfHyperbolaPy) generate_from_xml(ParabolaPy) generate_from_xml(OffsetCurvePy) generate_from_xml(GeometryPy) +generate_from_xml(GeometryExtensionPy) generate_from_xml(GeometryCurvePy) generate_from_xml(BoundedCurvePy) generate_from_xml(TrimmedCurvePy) @@ -211,6 +212,8 @@ SET(Python_SRCS OffsetCurvePyImp.cpp GeometryPy.xml GeometryPyImp.cpp + GeometryExtensionPy.xml + GeometryExtensionPyImp.cpp GeometryCurvePy.xml GeometryCurvePyImp.cpp BoundedCurvePy.xml diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index 7a6178bc4c..1862eb89d8 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -53,6 +53,16 @@ It describes the common behavior of these objects when: Create a clone of this geometry with the same Tag + + + Gets a geometry extension of the indicated type. + + + + + Sets a geometry extension of the indicated type. + + Defines this geometry as a construction one which diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index c97c8d6d22..5ce069cd2d 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -51,6 +51,7 @@ #include "GeometryPy.h" #include "GeometryPy.cpp" +#include "GeometryExtensionPy.h" #include "TopoShape.h" #include "TopoShapePy.h" @@ -239,6 +240,57 @@ PyObject* GeometryPy::clone(PyObject *args) return cpy; } +PyObject* GeometryPy::setExtension(PyObject *args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(GeometryExtensionPy::Type),&o)) { + Part::GeometryExtension * ext; + ext = static_cast(o)->getGeometryExtensionPtr(); + + std::unique_ptr cpy = ext->copy(); // allocate new extension in memory + + this->getGeometryPtr()->setExtension(std::move(cpy)); + Py_Return; + } + + PyErr_SetString(PartExceptionOCCError, "A geometry extension object was expected"); + return 0; +} + +PyObject* GeometryPy::getExtension(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + const std::weak_ptr ext = this->getGeometryPtr()->getExtension(type); + + std::unique_ptr cext = ext.lock()->copy(); + + GeometryExtension * pcext = cext.release(); + + return pcext->getPyObject(); + } + catch(Base::ValueError e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + } + else + { + PyErr_SetString(PartExceptionOCCError, "Exception type does not exist"); + return 0; + } + + } + + PyErr_SetString(PartExceptionOCCError, "A string with the name of the geometry extension type was expected"); + return 0; +} + Py::Boolean GeometryPy::getConstruction(void) const { return Py::Boolean(getGeometryPtr()->Construction); diff --git a/src/Mod/Sketcher/App/CMakeLists.txt b/src/Mod/Sketcher/App/CMakeLists.txt index 54ab8d78e4..d45ed552da 100644 --- a/src/Mod/Sketcher/App/CMakeLists.txt +++ b/src/Mod/Sketcher/App/CMakeLists.txt @@ -36,6 +36,7 @@ set(Sketcher_LIBS generate_from_xml(SketchObjectSFPy) generate_from_xml(SketchObjectPy) +generate_from_xml(SketchGeometryExtensionPy) generate_from_xml(ConstraintPy) generate_from_xml(SketchPy) @@ -71,6 +72,8 @@ SET(Python_SRCS SketchObjectSFPyImp.cpp SketchObjectPy.xml SketchObjectPyImp.cpp + SketchGeometryExtensionPy.xml + SketchGeometryExtensionPyImp.cpp ConstraintPyImp.cpp ConstraintPy.xml SketchPy.xml diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index e59a6f95e1..7b93d45dc6 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -80,6 +80,7 @@ #include "SketchObject.h" #include "Sketch.h" #include +#include #undef DEBUG @@ -92,6 +93,16 @@ using namespace Base; TYPESYSTEM_SOURCE(Sketcher::SketchGeometryExtension,Part::GeometryExtension) +SketchGeometryExtension::SketchGeometryExtension():id(0) +{ + +} + +SketchGeometryExtension::SketchGeometryExtension(long cid):id(cid) +{ + +} + SketchGeometryExtension::~SketchGeometryExtension() { } @@ -125,7 +136,7 @@ std::unique_ptr SketchGeometryExtension::copy(void) con PyObject * SketchGeometryExtension::getPyObject(void) { - return 0; + return new SketchGeometryExtensionPy(new SketchGeometryExtension(this->id)); } diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 164e721204..fe26a8cad8 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -45,6 +45,8 @@ class SketcherExport SketchGeometryExtension : public Part::GeometryExtension { TYPESYSTEM_HEADER(); public: + SketchGeometryExtension(); + SketchGeometryExtension(long cid); virtual ~SketchGeometryExtension(); // Persistence implementer ---------------------