+ implement Geometry.copy for Python

This commit is contained in:
wmayer 2015-06-15 21:28:29 +02:00
parent f99fd100e6
commit 280019ddf9
2 changed files with 32 additions and 0 deletions

View File

@ -43,6 +43,11 @@ It describes the common behavior of these objects when:
<UserDocu>Translates this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="copy" Const="true">
<Documentation>
<UserDocu>Create a copy of this geometry</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Construction" ReadOnly="false">
<Documentation>
<UserDocu>Defines this geometry as a construction one which

View File

@ -183,6 +183,33 @@ PyObject* GeometryPy::translate(PyObject *args)
return 0;
}
PyObject* GeometryPy::copy(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 copy of geometry");
return 0;
}
Part::GeometryPy* geompy = static_cast<Part::GeometryPy*>(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<Part::Geometry*>(geompy->_pcTwinPointer);
delete clone;
}
geompy->_pcTwinPointer = geom->clone();
return cpy;
}
Py::Boolean GeometryPy::getConstruction(void) const
{
return Py::Boolean(getGeometryPtr()->Construction);