Sketcher: Sketch - extraction of geometry as GeoList with owned memory allocation

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

Apart from simplifying code, the allocated memory is not managed by the lifetime of the unique pointer owned by the GeometryFacade, preventing memory leaks.
This commit is contained in:
Abdullah Tahiri
2021-12-21 20:27:44 +01:00
committed by abdullahtahiriyo
parent bc6e4c1355
commit e91dcf39c1
2 changed files with 20 additions and 0 deletions

View File

@@ -1425,6 +1425,22 @@ std::vector<Part::Geometry *> Sketch::extractGeometry(bool withConstructionEleme
return temp;
}
GeoListFacade Sketch::extractGeoListFacade() const
{
std::vector<GeometryFacadeUniquePtr> temp;
temp.reserve(Geoms.size());
int internalGeometryCount = 0;
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it) {
auto gf = GeometryFacade::getFacade(it->geo->clone(), true); // GeometryFacade is the owner of this allocation
if(!it->external)
internalGeometryCount++;
temp.push_back(std::move(gf));
}
return GeoListFacade::getGeoListModel(std::move(temp), internalGeometryCount);
}
void Sketch::updateExtension(int geoId, std::unique_ptr<Part::GeometryExtension> && ext)
{
geoId = checkGeoId(geoId);

View File

@@ -27,6 +27,7 @@
#include <App/PropertyFile.h>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/TopoShape.h>
#include "GeoList.h"
#include "Constraint.h"
#include "planegcs/GCS.h"
@@ -36,6 +37,7 @@
namespace Sketcher
{
class SketcherExport Sketch :public Base::Persistence
{
TYPESYSTEM_HEADER();
@@ -89,6 +91,8 @@ public:
std::vector<Part::Geometry *> extractGeometry(bool withConstructionElements=true,
bool withExternalElements=false) const;
GeoListFacade extractGeoListFacade() const;
void updateExtension(int geoId, std::unique_ptr<Part::GeometryExtension> && ext);
/// get the geometry as python objects
Py::Tuple getPyGeometry(void) const;