Part: expose geometry clone support to python

=============================================

>>> geometries = ActiveSketch.Geometry
>>> geo0 = geometries[0]
>>> geo0.Tag
'a2b6883e-64d6-4348-b567-8b5e0a4896a0'
>>> geo1 = geo0.clone()
>>> geo1.Tag
'a2b6883e-64d6-4348-b567-8b5e0a4896a0'
>>> geo1.Radius = 3
>>> geo0.Tag
'a2b6883e-64d6-4348-b567-8b5e0a4896a0'
>>> geo0.Radius
30.157883192724587
>>> geo1.Tag
'a2b6883e-64d6-4348-b567-8b5e0a4896a0'
>>> geo1.Radius
3.0
This commit is contained in:
Abdullah Tahiri
2019-01-27 10:25:36 +01:00
committed by wmayer
parent f4e4f3441f
commit dbbb1df6f8
2 changed files with 43 additions and 11 deletions

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="GeometryPy"
Twin="Geometry"
TwinPointer="Geometry"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
<PythonExport
Father="PyObjectBase"
Name="GeometryPy"
Twin="Geometry"
TwinPointer="Geometry"
Include="Mod/Part/App/Geometry.h"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base"
Constructor="true"
Delete="true">
@@ -48,6 +48,11 @@ It describes the common behavior of these objects when:
<UserDocu>Create a copy of this geometry</UserDocu>
</Documentation>
</Methode>
<Methode Name="clone" Const="true">
<Documentation>
<UserDocu>Create a clone of this geometry with the same Tag</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Construction" ReadOnly="false">
<Documentation>
<UserDocu>Defines this geometry as a construction one which

View File

@@ -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<double>(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<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);
@@ -236,5 +263,5 @@ PyObject *GeometryPy::getCustomAttributes(const char* /*attr*/) const
int GeometryPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
return 0;
}