diff --git a/src/Mod/Part/App/GeometryPy.xml b/src/Mod/Part/App/GeometryPy.xml index 16bb3baf9d..7a6178bc4c 100644 --- a/src/Mod/Part/App/GeometryPy.xml +++ b/src/Mod/Part/App/GeometryPy.xml @@ -1,13 +1,13 @@ - @@ -48,6 +48,11 @@ It describes the common behavior of these objects when: Create a copy of this geometry + + + Create a clone of this geometry with the same Tag + + 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 5ccd9ed732..53fff64a52 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -114,7 +114,7 @@ PyObject* GeometryPy::rotate(PyObject *args) rot.getValue(dir, angle); pnt = plm->getPosition(); - + gp_Ax1 ax1(gp_Pnt(pnt.x,pnt.y,pnt.z), gp_Dir(dir.x,dir.y,dir.z)); getGeometryPtr()->handle()->Rotate(ax1, angle); Py_Return; @@ -131,7 +131,7 @@ PyObject* GeometryPy::scale(PyObject *args) getGeometryPtr()->handle()->Scale(pnt, scale); Py_Return; } - + PyErr_Clear(); if (PyArg_ParseTuple(args, "O!d", &PyTuple_Type,&o, &scale)) { vec = Base::getVectorFromTuple(o); @@ -212,6 +212,33 @@ PyObject* GeometryPy::copy(PyObject *args) return cpy; } +PyObject* GeometryPy::clone(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + Part::Geometry* geom = this->getGeometryPtr(); + PyTypeObject* type = this->GetType(); + PyObject* cpy = 0; + // let the type object decide + if (type->tp_new) + cpy = type->tp_new(type, this, 0); + if (!cpy) { + PyErr_SetString(PyExc_TypeError, "failed to create clone of geometry"); + return 0; + } + + Part::GeometryPy* geompy = static_cast(cpy); + // the PyMake function must have created the corresponding instance of the 'Geometry' subclass + // so delete it now to avoid a memory leak + if (geompy->_pcTwinPointer) { + Part::Geometry* clone = static_cast(geompy->_pcTwinPointer); + delete clone; + } + geompy->_pcTwinPointer = geom->clone(); + return cpy; +} + Py::Boolean GeometryPy::getConstruction(void) const { return Py::Boolean(getGeometryPtr()->Construction); @@ -236,5 +263,5 @@ PyObject *GeometryPy::getCustomAttributes(const char* /*attr*/) const int GeometryPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { - return 0; + return 0; }