Part: Geometry extension set with unique id (type+name) and list based getExtensions python

This commit is contained in:
Abdullah Tahiri
2019-02-11 17:42:43 +01:00
committed by wmayer
parent 8618dfd3c6
commit 331817d1b7
3 changed files with 12 additions and 10 deletions

View File

@@ -311,13 +311,15 @@ void Geometry::setExtension(std::unique_ptr<GeometryExtension> && geo)
bool hasext=false;
for( auto & ext : extensions) {
if(ext->getTypeId() == geo->getTypeId()){
// if same type and name, this modifies the existing extension.
if( ext->getTypeId() == geo->getTypeId() &&
ext->getName() == geo->getName()){
ext = std::move(geo);
hasext = true;
}
}
if(!hasext)
if(!hasext) // new type-name unique id, so add.
extensions.push_back(std::move(geo));
}

View File

@@ -88,7 +88,7 @@ It describes the common behavior of these objects when:
<UserDocu>Deletes all extensions of the indicated name.</UserDocu>
</Documentation>
</Methode>
<Methode Name="showExtensions" Const="true">
<Methode Name="getExtensions" Const="true">
<Documentation>
<UserDocu>Returns a list with information about the geometry extensions.</UserDocu>
</Documentation>

View File

@@ -247,7 +247,8 @@ PyObject* GeometryPy::setExtension(PyObject *args)
Part::GeometryExtension * ext;
ext = static_cast<GeometryExtensionPy *>(o)->getGeometryExtensionPtr();
std::unique_ptr<GeometryExtension> cpy = ext->copy(); // allocate new extension in memory
// make copy of Python managed memory and wrap it in smart pointer
auto cpy = ext->copy();
this->getGeometryPtr()->setExtension(std::move(cpy));
Py_Return;
@@ -417,7 +418,7 @@ PyObject* GeometryPy::deleteExtensionOfName(PyObject *args)
return 0;
}
PyObject* GeometryPy::showExtensions(PyObject *args)
PyObject* GeometryPy::getExtensions(PyObject *args)
{
if (!PyArg_ParseTuple(args, "")){
PyErr_SetString(PartExceptionOCCError, "No arguments were expected");
@@ -427,21 +428,20 @@ PyObject* GeometryPy::showExtensions(PyObject *args)
try {
const std::vector<std::weak_ptr<GeometryExtension>> ext = this->getGeometryPtr()->getExtensions();
PyObject* list = PyList_New(ext.size());
Py::Tuple tuple(ext.size());
for (std::size_t i=0; i<ext.size(); ++i) {
std::stringstream str;
std::shared_ptr<GeometryExtension> p = ext[i].lock();
if(p) {
str << "<" << p->getTypeId().getName() << ", \"" << p->getName() << "\">";
tuple.setItem(i, Py::String(str.str()));
PyList_SetItem( list, i, p->getPyObject());
}
}
return Py::new_reference_to(tuple);
return list;
}
catch(Base::ValueError e) {
PyErr_SetString(PartExceptionOCCError, e.what());