From e9e8724cb16ca77a8584feb8472d01c5a558de7e Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 1 Nov 2020 07:40:46 +0100 Subject: [PATCH] Sketcher: Facade for geometry and external geometry extension --- src/Mod/Sketcher/App/AppSketcher.cpp | 10 +- src/Mod/Sketcher/App/CMakeLists.txt | 5 + .../Sketcher/App/ExternalGeometryFacade.cpp | 142 +++++ src/Mod/Sketcher/App/ExternalGeometryFacade.h | 151 ++++++ .../Sketcher/App/ExternalGeometryFacadePy.xml | 129 +++++ .../App/ExternalGeometryFacadePyImp.cpp | 497 ++++++++++++++++++ 6 files changed, 933 insertions(+), 1 deletion(-) create mode 100644 src/Mod/Sketcher/App/ExternalGeometryFacade.cpp create mode 100644 src/Mod/Sketcher/App/ExternalGeometryFacade.h create mode 100644 src/Mod/Sketcher/App/ExternalGeometryFacadePy.xml create mode 100644 src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp diff --git a/src/Mod/Sketcher/App/AppSketcher.cpp b/src/Mod/Sketcher/App/AppSketcher.cpp index 5fd624f950..c5ba7c20a8 100644 --- a/src/Mod/Sketcher/App/AppSketcher.cpp +++ b/src/Mod/Sketcher/App/AppSketcher.cpp @@ -33,12 +33,16 @@ #include "SketchObject.h" #include "SketchGeometryExtension.h" #include "ExternalGeometryExtension.h" +#include "GeometryFacade.h" +#include "ExternalGeometryFacade.h" #include "Constraint.h" #include "Sketch.h" #include "ConstraintPy.h" #include "SketchPy.h" #include "SketchGeometryExtensionPy.h" #include "ExternalGeometryExtensionPy.h" +#include "GeometryFacadePy.h" +#include "ExternalGeometryFacadePy.h" #include "PropertyConstraintList.h" @@ -65,7 +69,9 @@ PyMOD_INIT_FUNC(Sketcher) Base::Interpreter().addType(&Sketcher::ConstraintPy ::Type,sketcherModule,"Constraint"); Base::Interpreter().addType(&Sketcher::SketchPy ::Type,sketcherModule,"Sketch"); Base::Interpreter().addType(&Sketcher::ExternalGeometryExtensionPy ::Type,sketcherModule,"ExternalGeometryExtension"); - Base::Interpreter().addType(&Sketcher::SketchGeometryExtensionPy ::Type,sketcherModule,"SketchGeometryExtension"); + Base::Interpreter().addType(&Sketcher::SketchGeometryExtensionPy ::Type,sketcherModule,"SketchGeometryExtension"); + Base::Interpreter().addType(&Sketcher::GeometryFacadePy ::Type,sketcherModule,"GeometryFacade"); + Base::Interpreter().addType(&Sketcher::ExternalGeometryFacadePy ::Type,sketcherModule,"ExternalGeometryFacade"); // NOTE: To finish the initialization of our own type objects we must @@ -74,6 +80,8 @@ PyMOD_INIT_FUNC(Sketcher) Sketcher::SketchGeometryExtension ::init(); Sketcher::ExternalGeometryExtension ::init(); + Sketcher::GeometryFacade ::init(); + Sketcher::ExternalGeometryFacade ::init(); Sketcher::SketchObjectSF ::init(); Sketcher::SketchObject ::init(); Sketcher::SketchObjectPython ::init(); diff --git a/src/Mod/Sketcher/App/CMakeLists.txt b/src/Mod/Sketcher/App/CMakeLists.txt index dfb6cc63ad..4ab1022875 100644 --- a/src/Mod/Sketcher/App/CMakeLists.txt +++ b/src/Mod/Sketcher/App/CMakeLists.txt @@ -39,6 +39,7 @@ generate_from_xml(SketchObjectPy) generate_from_xml(SketchGeometryExtensionPy) generate_from_xml(ExternalGeometryExtensionPy) generate_from_xml(GeometryFacadePy) +generate_from_xml(ExternalGeometryFacadePy) generate_from_xml(ConstraintPy) generate_from_xml(SketchPy) @@ -72,6 +73,8 @@ SET(Datatypes_SRCS Sketch.h GeometryFacade.cpp GeometryFacade.h + ExternalGeometryFacade.cpp + ExternalGeometryFacade.h ) SOURCE_GROUP("Datatypes" FILES ${Datatypes_SRCS}) @@ -86,6 +89,8 @@ SET(Python_SRCS ExternalGeometryExtensionPyImp.cpp GeometryFacadePy.xml GeometryFacadePyImp.cpp + ExternalGeometryFacadePy.xml + ExternalGeometryFacadePyImp.cpp ConstraintPyImp.cpp ConstraintPy.xml SketchPy.xml diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp new file mode 100644 index 0000000000..3fe4850ed7 --- /dev/null +++ b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp @@ -0,0 +1,142 @@ +/*************************************************************************** + * 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 "ExternalGeometryFacade.h" + +#include // Only for Debug - To be removed +#include +#include + +#include "ExternalGeometryFacadePy.h" + +using namespace Sketcher; + +TYPESYSTEM_SOURCE(Sketcher::ExternalGeometryFacade,Part::GeometryExtension) + +ExternalGeometryFacade::ExternalGeometryFacade(): Geo(nullptr), SketchGeoExtension(nullptr), ExternalGeoExtension(nullptr) +{ + +} + +ExternalGeometryFacade::ExternalGeometryFacade(const Part::Geometry * geometry) +: Geo(geometry) +{ + if(geometry != nullptr) + initExtensions(); + else + THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); +} + +std::unique_ptr ExternalGeometryFacade::getFacade(Part::Geometry * geometry) +{ + return std::unique_ptr(new ExternalGeometryFacade(geometry)); + //return std::make_unique(geometry); // make_unique has no access to private constructor +} + +std::unique_ptr ExternalGeometryFacade::getFacade(const Part::Geometry * geometry) +{ + return std::unique_ptr(new ExternalGeometryFacade(geometry)); + //return std::make_unique(geometry); // make_unique has no access to private constructor +} + +void ExternalGeometryFacade::setGeometry(Part::Geometry *geometry) +{ + Geo = geometry; + + if(geometry != nullptr) + initExtensions(); + else + THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); +} + +void ExternalGeometryFacade::initExtensions() +{ + if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) { + + getGeo()->setExtension(std::make_unique()); // Create getExtension + + Base::Console().Warning("%s\nSketcher External Geometry without Geometry Extension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str()); + } + + if(!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) { + + getGeo()->setExtension(std::make_unique()); // Create getExtension + + Base::Console().Warning("%s\nSketcher External Geometry without ExternalGeometryExtension: %s \n", boost::uuids::to_string(Geo->getTag()).c_str()); + } + + SketchGeoExtension = + std::static_pointer_cast( + (Geo->getExtension(SketchGeometryExtension::getClassTypeId())).lock() + ); + + ExternalGeoExtension = + std::static_pointer_cast( + (Geo->getExtension(ExternalGeometryExtension::getClassTypeId())).lock() + ); +} + +void ExternalGeometryFacade::initExtensions() const +{ + if(!Geo->hasExtension(SketchGeometryExtension::getClassTypeId())) + THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without SketchGeometryExtension"); + + if(!Geo->hasExtension(ExternalGeometryExtension::getClassTypeId())) + THROWM(Base::ValueError, "ExternalGeometryFacade for const::Geometry without ExternalGeometryExtension"); + + auto ext = std::static_pointer_cast(Geo->getExtension(SketchGeometryExtension::getClassTypeId()).lock()); + + const_cast(this)->SketchGeoExtension = ext; + + auto extext = std::static_pointer_cast(Geo->getExtension(ExternalGeometryExtension::getClassTypeId()).lock()); + + const_cast(this)->ExternalGeoExtension = extext; +} + +void ExternalGeometryFacade::ensureSketchGeometryExtensions(Part::Geometry * geometry) +{ + if(!geometry->hasExtension(SketchGeometryExtension::getClassTypeId())) { + geometry->setExtension(std::make_unique()); // Create geoExtension + } + + if(!geometry->hasExtension(ExternalGeometryExtension::getClassTypeId())) { + geometry->setExtension(std::make_unique()); // Create external geoExtension + } +} + +void ExternalGeometryFacade::copyId(const Part::Geometry * src, Part::Geometry * dst) +{ + auto gfsrc = ExternalGeometryFacade::getFacade(src); + auto gfdst = ExternalGeometryFacade::getFacade(dst); + gfdst->setId(gfsrc->getId()); +} + +PyObject * ExternalGeometryFacade::getPyObject(void) +{ + return new ExternalGeometryFacadePy(new ExternalGeometryFacade(this->Geo)); +} diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacade.h b/src/Mod/Sketcher/App/ExternalGeometryFacade.h new file mode 100644 index 0000000000..af0aca758b --- /dev/null +++ b/src/Mod/Sketcher/App/ExternalGeometryFacade.h @@ -0,0 +1,151 @@ +/*************************************************************************** + * 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_GEOMETRYEXTERNALFACADE_H +#define SKETCHER_GEOMETRYEXTERNALFACADE_H + +#include + +#include // Only for Debug - To be removed +#include + +#include +#include +#include + +namespace Sketcher +{ + +// This class is a Facade to handle external geometry 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 ExternalGeometryFacade : public Base::BaseClass, public ISketchGeometryExtension, public ISketchExternalGeometryExtension +{ +TYPESYSTEM_HEADER_WITH_OVERRIDE(); + +private: + ExternalGeometryFacade(const Part::Geometry * geometry); + +public: + ExternalGeometryFacade(); // 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: // Utility methods + static void ensureSketchGeometryExtensions(Part::Geometry * geometry); + static void copyId(const Part::Geometry * src, Part::Geometry * dst); + +public: + void setGeometry(Part::Geometry *geometry); + + /** External GeometryExtension Interface **/ + virtual bool testFlag(int flag) const override { return getExternalGeoExt()->testFlag(flag); } + virtual void setFlag(int flag, bool v=true) override { getExternalGeoExt()->setFlag(flag, v); } + + virtual bool isClear() const override {return getExternalGeoExt()->isClear();} + virtual size_t flagSize() const override {return getExternalGeoExt()->flagSize();} + + virtual const std::string& getRef() const override {return getExternalGeoExt()->getRef();} + virtual void setRef(const std::string & ref) override {getExternalGeoExt()->setRef(ref);} + + /** GeometryExtension 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 &getSketchExtensionName () const {return SketchGeoExtension->getName();} + inline const std::string &getExternalExtensionName () const {return ExternalGeoExtension->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 initExtensions(void); + void initExtensions(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);} + + std::shared_ptr getExternalGeoExt(void) const {return ExternalGeoExtension;} + std::shared_ptr getExternalGeoExt (void) {return std::const_pointer_cast(ExternalGeoExtension);} + +private: + const Part::Geometry * Geo; + std::shared_ptr SketchGeoExtension; + std::shared_ptr ExternalGeoExtension; +}; + + + + +} //namespace Sketcher + + +#endif // SKETCHER_GEOMETRYEXTERNALFACADE_H diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePy.xml b/src/Mod/Sketcher/App/ExternalGeometryFacadePy.xml new file mode 100644 index 0000000000..9209b9b42c --- /dev/null +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePy.xml @@ -0,0 +1,129 @@ + + + + + + Describes a GeometryFacade + + + + + returns the Id of the SketchGeometryExtension. + + + + + + + returns a boolean indicating whether the given bit is set. + + + + + sets the given bit to true/false. + + + + + + returns the reference string of this external geometry. + + + + + + + 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/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp new file mode 100644 index 0000000000..8c19125f54 --- /dev/null +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -0,0 +1,497 @@ +/*************************************************************************** + * 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_ +//# include +//#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "SketchObject.h" +#include "ExternalGeometryFacadePy.h" +#include "ExternalGeometryFacadePy.cpp" + +using namespace Sketcher; + +// returns a string which represents the object e.g. when printed in python +std::string ExternalGeometryFacadePy::representation(void) const +{ + std::stringstream str; + str << ""; + return str.str(); +} + +PyObject *ExternalGeometryFacadePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of PointPy and the Twin object + return new ExternalGeometryFacadePy(new ExternalGeometryFacade()); +} + +// constructor method +int ExternalGeometryFacadePy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + PyObject *object; + if (PyArg_ParseTuple(args,"O!",&(Part::GeometryPy::Type), &object)) { + Part::Geometry * geo = static_cast(object)->getGeometryPtr(); + + getExternalGeometryFacadePtr()->setGeometry(geo->clone()); + + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Sketcher::ExternalGeometryFacade constructor accepts:\n" + "-- Part.Geometry\n" + ); + return -1; +} + +PyObject* ExternalGeometryFacadePy::testFlag(PyObject *args) +{ + char* flag; + if (PyArg_ParseTuple(args, "s",&flag)) { + + auto pos = std::find_if(getExternalGeometryFacadePtr()->flag2str.begin(), + getExternalGeometryFacadePtr()->flag2str.end(), + [flag](const char * val) { return strcmp(val,flag) == 0;}); + + if( pos != getExternalGeometryFacadePtr()->flag2str.end()) { + int index = std::distance( getExternalGeometryFacadePtr()->flag2str.begin(), pos ); + + return new_reference_to(Py::Boolean(this->getExternalGeometryFacadePtr()->testFlag(index))); + } + + PyErr_SetString(PyExc_TypeError, "Flag string does not exist."); + return NULL; + + } + + PyErr_SetString(PyExc_TypeError, "No flag string provided."); + return NULL; +} + +PyObject* ExternalGeometryFacadePy::setFlag(PyObject *args) +{ + char * flag; + PyObject * bflag = Py_True; + if (PyArg_ParseTuple(args, "s|O!", &flag, &PyBool_Type, &bflag)) { + + auto pos = std::find_if(getExternalGeometryFacadePtr()->flag2str.begin(), + getExternalGeometryFacadePtr()->flag2str.end(), + [flag](const char * val) { + return strcmp(val,flag)==0;} + ); + + if( pos != getExternalGeometryFacadePtr()->flag2str.end()) { + int index = std::distance( getExternalGeometryFacadePtr()->flag2str.begin(), pos ); + + this->getExternalGeometryFacadePtr()->setFlag(index,PyObject_IsTrue(bflag) ? true : false); + Py_Return; + } + + PyErr_SetString(PyExc_TypeError, "Flag string does not exist."); + return NULL; + } + + PyErr_SetString(PyExc_TypeError, "No flag string provided."); + Py_Return; +} + +Py::String ExternalGeometryFacadePy::getRef(void) const +{ + return Py::String(this->getExternalGeometryFacadePtr()->getRef()); +} + +void ExternalGeometryFacadePy::setRef(Py::String value) +{ + this->getExternalGeometryFacadePtr()->setRef(value.as_std_string()); +} + +Py::Long ExternalGeometryFacadePy::getId(void) const +{ + return Py::Long(this->getExternalGeometryFacadePtr()->getId()); +} + +void ExternalGeometryFacadePy::setId(Py::Long Id) +{ + this->getExternalGeometryFacadePtr()->setId(long(Id)); +} + +PyObject* ExternalGeometryFacadePy::mirror(PyObject *args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) { + Base::Vector3d vec = static_cast(o)->value(); + getExternalGeometryFacadePtr()->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(); + getExternalGeometryFacadePtr()->mirror(pnt, dir); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either a point (vector) or axis (vector, vector) must be given"); + return 0; +} + +PyObject* ExternalGeometryFacadePy::rotate(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type),&o)) + return 0; + + Base::Placement* plm = static_cast(o)->getPlacementPtr(); + getExternalGeometryFacadePtr()->rotate(*plm); + Py_Return; +} + +PyObject* ExternalGeometryFacadePy::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(); + getExternalGeometryFacadePtr()->scale(vec, scale); + Py_Return; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) { + vec = Base::getVectorFromTuple(o); + getExternalGeometryFacadePtr()->scale(vec, scale); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple and float expected"); + return 0; +} + +PyObject* ExternalGeometryFacadePy::transform(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&o)) + return 0; + Base::Matrix4D mat = static_cast(o)->value(); + getExternalGeometryFacadePtr()->transform(mat); + Py_Return; +} + +PyObject* ExternalGeometryFacadePy::translate(PyObject *args) +{ + PyObject* o; + Base::Vector3d vec; + if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type),&o)) { + vec = static_cast(o)->value(); + getExternalGeometryFacadePtr()->translate(vec); + Py_Return; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &PyTuple_Type,&o)) { + vec = Base::getVectorFromTuple(o); + getExternalGeometryFacadePtr()->translate(vec); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "either vector or tuple expected"); + return 0; +} + +PyObject* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->setExtension(std::move(cpy)); + Py_Return; + } + + PyErr_SetString(Part::PartExceptionOCCError, "A geometry extension object was expected"); + return 0; +} + +PyObject* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::getExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + std::shared_ptr ext(this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::hasExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + return Py::new_reference_to(Py::Boolean(this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::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->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::deleteExtensionOfName(PyObject *args) +{ + char* o; + if (PyArg_ParseTuple(args, "s", &o)) { + + try { + this->getExternalGeometryFacadePtr()->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* ExternalGeometryFacadePy::getExtensions(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")){ + PyErr_SetString(Part::PartExceptionOCCError, "No arguments were expected"); + return NULL; + } + + try { + const std::vector> ext = this->getExternalGeometryFacadePtr()->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 ExternalGeometryFacadePy::getConstruction(void) const +{ + return Py::Boolean(getExternalGeometryFacadePtr()->getConstruction()); +} + +void ExternalGeometryFacadePy::setConstruction(Py::Boolean arg) +{ + if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) + getExternalGeometryFacadePtr()->setConstruction(arg); +} + +Py::String ExternalGeometryFacadePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getExternalGeometryFacadePtr()->getTag()); + return Py::String(tmp); +} + +Py::Object ExternalGeometryFacadePy::getGeometry(void) const +{ + // We return a clone + return Py::Object(getExternalGeometryFacadePtr()->getGeometry()->clone()->getPyObject(),true); +} + +void ExternalGeometryFacadePy::setGeometry(Py::Object arg) +{ + if (PyObject_TypeCheck(arg.ptr(), &(Part::GeometryPy::Type))) { + Part::GeometryPy * gp = static_cast(arg.ptr()); + + getExternalGeometryFacadePtr()->setGeometry(gp->getGeometryPtr()->clone()); + } +} + + +PyObject *ExternalGeometryFacadePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int ExternalGeometryFacadePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}