diff --git a/src/Mod/Sketcher/App/CMakeLists.txt b/src/Mod/Sketcher/App/CMakeLists.txt index 013adeedf9..dfb6cc63ad 100644 --- a/src/Mod/Sketcher/App/CMakeLists.txt +++ b/src/Mod/Sketcher/App/CMakeLists.txt @@ -38,6 +38,7 @@ generate_from_xml(SketchObjectSFPy) generate_from_xml(SketchObjectPy) generate_from_xml(SketchGeometryExtensionPy) generate_from_xml(ExternalGeometryExtensionPy) +generate_from_xml(GeometryFacadePy) generate_from_xml(ConstraintPy) generate_from_xml(SketchPy) @@ -69,6 +70,8 @@ SET(Datatypes_SRCS Constraint.h Sketch.cpp Sketch.h + GeometryFacade.cpp + GeometryFacade.h ) SOURCE_GROUP("Datatypes" FILES ${Datatypes_SRCS}) @@ -81,6 +84,8 @@ SET(Python_SRCS SketchGeometryExtensionPyImp.cpp ExternalGeometryExtensionPy.xml ExternalGeometryExtensionPyImp.cpp + GeometryFacadePy.xml + GeometryFacadePyImp.cpp ConstraintPyImp.cpp ConstraintPy.xml SketchPy.xml diff --git a/src/Mod/Sketcher/App/GeometryFacade.cpp b/src/Mod/Sketcher/App/GeometryFacade.cpp new file mode 100644 index 0000000000..405775c00e --- /dev/null +++ b/src/Mod/Sketcher/App/GeometryFacade.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (c) 2020 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ + +#endif + +#include "GeometryFacade.h" + +#include // Only for Debug - To be removed +#include +#include + +#include "GeometryFacadePy.h" + +using namespace Sketcher; + +TYPESYSTEM_SOURCE(Sketcher::GeometryFacade,Part::GeometryExtension) + +GeometryFacade::GeometryFacade(): Geo(nullptr), SketchGeoExtension(nullptr) +{ + +} + +GeometryFacade::GeometryFacade(const Part::Geometry * geometry) +: Geo(geometry) +{ + if(geometry != nullptr) + initExtension(); + else + THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer"); +} + +std::unique_ptr GeometryFacade::getFacade(Part::Geometry * geometry) +{ + return std::unique_ptr(new GeometryFacade(geometry)); + //return std::make_unique(geometry); // make_unique has no access to private constructor +} + +std::unique_ptr GeometryFacade::getFacade(const Part::Geometry * geometry) +{ + return std::unique_ptr(new GeometryFacade(geometry)); + //return std::make_unique(geometry); // make_unique has no access to private constructor +} + +void GeometryFacade::setGeometry(Part::Geometry *geometry) +{ + Geo = geometry; + + if(geometry != nullptr) + initExtension(); + else + THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer"); +} + +void GeometryFacade::initExtension() +{ + if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) { + + getGeo()->setExtension(std::make_unique()); // Create getExtension + + Base::Console().Warning("%s\nSketcher Geometry without Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str()); + } + + SketchGeoExtension = + std::static_pointer_cast( + (Geo->getExtension(SketchGeometryExtension::getClassTypeId())).lock() + ); +} + +void GeometryFacade::initExtension() const +{ + if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) + THROWM(Base::ValueError, "GeometryConstFacade for const::Geometry without SketchGeometryExtension"); + + auto ext = std::static_pointer_cast(Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock()); + + const_cast(this)->SketchGeoExtension = ext; +} + + + +PyObject * GeometryFacade::getPyObject(void) +{ + return new GeometryFacadePy(new GeometryFacade(this->Geo)); +} diff --git a/src/Mod/Sketcher/App/GeometryFacade.h b/src/Mod/Sketcher/App/GeometryFacade.h new file mode 100644 index 0000000000..8d5af28ee8 --- /dev/null +++ b/src/Mod/Sketcher/App/GeometryFacade.h @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (c) 2020 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef SKETCHER_GEOMETRYFACADE_H +#define SKETCHER_GEOMETRYFACADE_H + +#include + +#include // Only for Debug - To be removed +#include + +#include +#include + +namespace Sketcher +{ + +// This class is a Facade to handle geometry and sketcher geometry extensions with a single sketcher specific interface +// +// +// +// It is intended to have a separate type (not being a Geometry type). +// it is intended to have the relevant interface for the sketcher only +// It is intended to work on borrowed memory allocation. +class SketcherExport GeometryFacade : public Base::BaseClass, ISketchGeometryExtension +{ +TYPESYSTEM_HEADER_WITH_OVERRIDE(); + +private: + GeometryFacade(const Part::Geometry * geometry); + +public: + GeometryFacade(); // As TYPESYSTEM requirement for Python object construction + +public: // Factory methods + static std::unique_ptr getFacade(Part::Geometry * geometry); + static std::unique_ptr getFacade(const Part::Geometry * geometry); + +public: + void setGeometry(Part::Geometry *geometry); + + // Geometry Extension Interface + inline virtual long getId() const override {return getGeoExt()->getId();} + virtual void setId(long id) override {getGeoExt()->setId(id);} + + // Geometry Extension Information + inline const std::string &getExtensionName () const {return SketchGeoExtension->getName();} + + // Geometry Element + template < typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value + >::type + > + GeometryT * getGeometry() {return dynamic_cast(const_cast(Geo));} + + // Geometry Element + template < typename GeometryT = Part::Geometry, + typename = typename std::enable_if< + std::is_base_of::type>::value + >::type + > + GeometryT * getGeometry() const {return dynamic_cast(Geo);} + + virtual PyObject *getPyObject(void) override; + + // Geometry Interface + TopoDS_Shape toShape() const {return getGeo()->toShape();}; + const Handle(Geom_Geometry)& handle() const {return getGeo()->handle();}; + Part::Geometry *copy(void) const {return getGeo()->copy();}; + Part::Geometry *clone(void) const {return getGeo()->clone();}; + inline bool getConstruction(void) const {return getGeo()->getConstruction();}; + inline void setConstruction(bool construction) {getGeo()->setConstruction(construction);}; + boost::uuids::uuid getTag() const {return getGeo()->getTag();}; + + std::vector> getExtensions() const {return getGeo()->getExtensions();}; + bool hasExtension(Base::Type type) const {return getGeo()->hasExtension(type);}; + bool hasExtension(std::string name) const {return getGeo()->hasExtension(name);}; + std::weak_ptr getExtension(Base::Type type) const {return getGeo()->getExtension(type);}; + std::weak_ptr getExtension(std::string name) const {return getGeo()->getExtension(name);}; + void setExtension(std::unique_ptr &&geo) {return getGeo()->setExtension(std::move(geo));}; + void deleteExtension(Base::Type type) {return getGeo()->deleteExtension(type);}; + void deleteExtension(std::string name) {return getGeo()->deleteExtension(name);}; + + void mirror(Base::Vector3d point) {return getGeo()->mirror(point);}; + void mirror(Base::Vector3d point, Base::Vector3d dir) {return getGeo()->mirror(point, dir);}; + void rotate(Base::Placement plm) {return getGeo()->rotate(plm);}; + void scale(Base::Vector3d vec, double scale) {return getGeo()->scale(vec, scale);}; + void transform(Base::Matrix4D mat) {return getGeo()->transform(mat);}; + void translate(Base::Vector3d vec) {return getGeo()->translate(vec);}; + +private: + void initExtension(void); + void initExtension(void) const; + + const Part::Geometry * getGeo(void) const {return Geo;} + Part::Geometry * getGeo(void) {return const_cast(Geo);} + + std::shared_ptr getGeoExt(void) const {return SketchGeoExtension;} + std::shared_ptr getGeoExt (void) {return std::const_pointer_cast(SketchGeoExtension);} + +private: + const Part::Geometry * Geo; + std::shared_ptr SketchGeoExtension; +}; + + + + +} //namespace Sketcher + + +#endif // SKETCHER_GEOMETRYFACADE_H diff --git a/src/Mod/Sketcher/App/GeometryFacadePy.xml b/src/Mod/Sketcher/App/GeometryFacadePy.xml new file mode 100644 index 0000000000..fdb1aa5bc4 --- /dev/null +++ b/src/Mod/Sketcher/App/GeometryFacadePy.xml @@ -0,0 +1,111 @@ + + + + + + Describes a GeometryFacade + + + + + returns the Id of the SketchGeometryExtension. + + + + + + + Performs the symmetrical transformation of this geometric object + + + + + Rotates this geometric object at angle Ang (in radians) about axis + + + + + Applies a scaling transformation on this geometric object with a center and scaling factor + + + + + Applies a transformation to this geometric object + + + + + Translates this geometric object + + + + + Returns a boolean indicating whether a geometry extension of the type indicated as a string exists. + + + + + Returns a boolean indicating whether a geometry extension with the name indicated as a string exists. + + + + + Gets the first geometry extension of the type indicated by the string. + + + + + Gets the first geometry extension of the name indicated by the string. + + + + + Sets a geometry extension of the indicated type. + + + + + Deletes all extensions of the indicated type. + + + + + Deletes all extensions of the indicated name. + + + + + Returns a list with information about the geometry extensions. + + + + + Defines this geometry as a construction one which +means that it is not part of a later built shape. + + + + + + Gives the tag of the geometry as string. + + + + + + Gives the tag of the geometry as string. + + + + + diff --git a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp new file mode 100644 index 0000000000..d38e077192 --- /dev/null +++ b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp @@ -0,0 +1,441 @@ +/*************************************************************************** + * Copyright (c) 2019 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +//#ifndef _PreComp_ +//# include +//#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "SketchObject.h" +#include "GeometryFacadePy.h" +#include "GeometryFacadePy.cpp" + +using namespace Sketcher; + +// returns a string which represents the object e.g. when printed in python +std::string GeometryFacadePy::representation(void) const +{ + std::stringstream str; + str << "getExtensionName().size()>0) + str << "\'" << getGeometryFacadePtr()->getExtensionName() << "\', "; + + str << "Id="; + + str << getGeometryFacadePtr()->getId() << ") >"; + return str.str(); +} + +PyObject *GeometryFacadePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of PointPy and the Twin object + return new GeometryFacadePy(new GeometryFacade()); +} + +// constructor method +int GeometryFacadePy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + PyObject *object; + if (PyArg_ParseTuple(args,"O!",&(Part::GeometryPy::Type), &object)) { + Part::Geometry * geo = static_cast(object)->getGeometryPtr(); + + getGeometryFacadePtr()->setGeometry(geo->clone()); + + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Sketcher::GeometryFacade constructor accepts:\n" + "-- Part.Geometry\n" + ); + return -1; +} + +Py::Long GeometryFacadePy::getId(void) const +{ + return Py::Long(this->getGeometryFacadePtr()->getId()); +} + +void GeometryFacadePy::setId(Py::Long Id) +{ + this->getGeometryFacadePtr()->setId(long(Id)); +} + +PyObject* GeometryFacadePy::mirror(PyObject *args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) { + Base::Vector3d vec = static_cast(o)->value(); + getGeometryFacadePtr()->mirror(vec); + Py_Return; + } + + PyErr_Clear(); + PyObject* axis; + if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type),&o, + &(Base::VectorPy::Type),&axis)) { + Base::Vector3d pnt = static_cast(o)->value(); + Base::Vector3d dir = static_cast(axis)->value(); + getGeometryFacadePtr()->mirror(pnt, dir); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either a point (vector) or axis (vector, vector) must be given"); + return 0; +} + +PyObject* GeometryFacadePy::rotate(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type),&o)) + return 0; + + Base::Placement* plm = static_cast(o)->getPlacementPtr(); + getGeometryFacadePtr()->rotate(*plm); + Py_Return; +} + +PyObject* GeometryFacadePy::scale(PyObject *args) +{ + PyObject* o; + double scale; + Base::Vector3d vec; + if (PyArg_ParseTuple(args, "O!d", &(Base::VectorPy::Type),&o, &scale)) { + vec = static_cast(o)->value(); + getGeometryFacadePtr()->scale(vec, scale); + Py_Return; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) { + vec = Base::getVectorFromTuple(o); + getGeometryFacadePtr()->scale(vec, scale); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple and float expected"); + return 0; +} + +PyObject* GeometryFacadePy::transform(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&o)) + return 0; + Base::Matrix4D mat = static_cast(o)->value(); + getGeometryFacadePtr()->transform(mat); + Py_Return; +} + +PyObject* GeometryFacadePy::translate(PyObject *args) +{ + PyObject* o; + Base::Vector3d vec; + if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) { + vec = static_cast(o)->value(); + getGeometryFacadePtr()->translate(vec); + Py_Return; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &PyTuple_Type,&o)) { + vec = Base::getVectorFromTuple(o); + getGeometryFacadePtr()->translate(vec); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple expected"); + return 0; +} + +PyObject* GeometryFacadePy::setExtension(PyObject *args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(Part::GeometryExtensionPy::Type),&o)) { + Part::GeometryExtension * ext; + ext = static_cast(o)->getGeometryExtensionPtr(); + + // make copy of Python managed memory and wrap it in smart pointer + auto cpy = ext->copy(); + + this->getGeometryFacadePtr()->setExtension(std::move(cpy)); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "A geometry extension object was expected"); + return 0; +} + +PyObject* GeometryFacadePy::getExtensionOfType(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + std::shared_ptr ext(this->getGeometryFacadePtr()->getExtension(type)); + + // we create a copy and transfer this copy's memory management responsibility to Python + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + + return cpy; + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + catch(const std::bad_weak_ptr&) { + PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not exist anymore."); + return 0; + } + } + else + { + PyErr_SetString(Part::PartExceptionOCCError, "Exception type does not exist"); + return 0; + } + + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the geometry extension type was expected"); + return 0; +} + +PyObject* GeometryFacadePy::getExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + std::shared_ptr ext(this->getGeometryFacadePtr()->getExtension(std::string(o))); + + // we create a copy and transfer this copy's memory management responsibility to Python + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + + return cpy; + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + catch(const std::bad_weak_ptr&) { + PyErr_SetString(Part::PartExceptionOCCError, "Geometry extension does not exist anymore."); + return 0; + } + + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the geometry extension was expected"); + return 0; +} + +PyObject* GeometryFacadePy::hasExtensionOfType(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + return Py::new_reference_to(Py::Boolean(this->getGeometryFacadePtr()->hasExtension(type))); + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + } + else + { + PyErr_SetString(Part::PartExceptionOCCError, "Exception type does not exist"); + return 0; + } + + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with the type of the geometry extension was expected"); + return 0; +} + +PyObject* GeometryFacadePy::hasExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + return Py::new_reference_to(Py::Boolean(this->getGeometryFacadePtr()->hasExtension(std::string(o)))); + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with the type of the geometry extension was expected"); + return 0; +} + +PyObject* GeometryFacadePy::deleteExtensionOfType(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + Base::Type type = Base::Type::fromName(o); + + if(type != Base::Type::badType()) { + try { + this->getGeometryFacadePtr()->deleteExtension(type); + Py_Return; + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + } + else + { + PyErr_SetString(Part::PartExceptionOCCError, "Type does not exist"); + return 0; + } + + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with a type object was expected"); + return 0; +} + +PyObject* GeometryFacadePy::deleteExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + this->getGeometryFacadePtr()->deleteExtension(std::string(o)); + Py_Return; + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + } + + PyErr_SetString(Part::PartExceptionOCCError, "A string with the name of the extension was expected"); + return 0; +} + +PyObject* GeometryFacadePy::getExtensions(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")){ + PyErr_SetString(Part::PartExceptionOCCError, "No arguments were expected"); + return NULL; + } + + try { + const std::vector> ext = this->getGeometryFacadePtr()->getExtensions(); + + PyObject* list = PyList_New(ext.size()); + + Py::Tuple tuple(ext.size()); + + for (std::size_t i=0; i p = ext[i].lock(); + + if(p) { + // we create a python copy and add it to the list + PyObject* cpy = static_cast(std::const_pointer_cast(p)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + + PyList_SetItem( list, i, cpy); + } + } + + return list; + } + catch(const Base::ValueError& e) { + PyErr_SetString(Part::PartExceptionOCCError, e.what()); + return 0; + } + +} + +Py::Boolean GeometryFacadePy::getConstruction(void) const +{ + return Py::Boolean(getGeometryFacadePtr()->getConstruction()); +} + +void GeometryFacadePy::setConstruction(Py::Boolean arg) +{ + if (getGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) + getGeometryFacadePtr()->setConstruction(arg); +} + +Py::String GeometryFacadePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getGeometryFacadePtr()->getTag()); + return Py::String(tmp); +} + +Py::Object GeometryFacadePy::getGeometry(void) const +{ + // We return a clone + return Py::Object(getGeometryFacadePtr()->getGeometry()->clone()->getPyObject(),true); +} + +void GeometryFacadePy::setGeometry(Py::Object arg) +{ + if (PyObject_TypeCheck(arg.ptr(), &(Part::GeometryPy::Type))) { + Part::GeometryPy * gp = static_cast(arg.ptr()); + + getGeometryFacadePtr()->setGeometry(gp->getGeometryPtr()->clone()); + } +} + + +PyObject *GeometryFacadePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int GeometryFacadePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index d7cefa156a..44a50b8fcd 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -450,5 +450,13 @@ If there is no such constraint an exception is raised. + + + + Return a list of GeometryFacade objects corresponding to the PropertyGeometryList + + + + diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index d9a10413a3..162f608f14 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -27,6 +27,8 @@ # include #endif +#include + #include #include #include @@ -45,6 +47,8 @@ #include "SketchObjectPy.cpp" // other python types #include "ConstraintPy.h" +#include "GeometryFacade.h" +#include "GeometryFacadePy.h" using namespace Sketcher; @@ -1750,6 +1754,44 @@ Py::Long SketchObjectPy::getAxisCount(void) const return Py::Long(this->getSketchObjectPtr()->getAxisCount()); } + +Py::List SketchObjectPy::getGeometryFacadeList(void) const +{ + Py::List list; + + for (int i = 0; i < getSketchObjectPtr()->Geometry.getSize(); i++) { + + // we create a python copy and add it to the list + std::unique_ptr geofacade = GeometryFacade::getFacade(getSketchObjectPtr()->Geometry[i]->clone()); + + Py::Object gfp = Py::Object(new GeometryFacadePy(geofacade.release()),true); + + list.append(gfp); + } + return list; +} + +void SketchObjectPy::setGeometryFacadeList(Py::List value) +{ + std::vector list; + list.reserve(value.size()); + + for (const auto & ti : value) { + if (PyObject_TypeCheck(ti.ptr(), &(GeometryFacadePy::Type))) { + + GeometryFacadePy * gfp = static_cast(ti.ptr()); + + GeometryFacade * gf = gfp->getGeometryFacadePtr(); + + Part::Geometry * geo = gf->getGeometry()->clone(); + + list.push_back(geo); + } + } + + getSketchObjectPtr()->Geometry.setValues(std::move(list)); +} + PyObject *SketchObjectPy::getCustomAttributes(const char* /*attr*/) const { return 0;