Sketcher: SketchObject new addGeometry method for smart pointers

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

This new facility avoids to have to create a new copy() when a user copy is already created.

As the user copy is reused via move semantics, memory management is simplified.

CAVEAT: When this facility is used, the client code has to ensure whether a copy() or a clone() of the Part::Geometry
should be undertaken. The different between both is that the former creates a new uuid (tag), whereas the latter does not.
This commit is contained in:
Abdullah Tahiri
2022-12-11 17:26:35 +01:00
committed by abdullahtahiriyo
parent f49fc46051
commit e5e508c326
2 changed files with 21 additions and 2 deletions

View File

@@ -886,6 +886,14 @@ int SketchObject::addGeometry(const std::vector<Part::Geometry *> &geoList, bool
}
int SketchObject::addGeometry(const Part::Geometry *geo, bool construction/*=false*/)
{
// this copy has a new random tag (see copy() vs clone())
auto geoNew = std::unique_ptr<Part::Geometry>(geo->copy());
return addGeometry(std::move(geoNew),construction);
}
int SketchObject::addGeometry(std::unique_ptr<Part::Geometry> newgeo, bool construction/*=false*/)
{
Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.
@@ -893,7 +901,7 @@ int SketchObject::addGeometry(const Part::Geometry *geo, bool construction/*=fal
std::vector< Part::Geometry * > newVals(vals);
Part::Geometry *geoNew = geo->copy();
auto *geoNew = newgeo.release();
if( geoNew->getTypeId() == Part::GeomPoint::getClassTypeId()) {
// creation mode for points is always construction not to