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

View File

@@ -94,12 +94,23 @@ public:
*/
bool isSupportedGeometry(const Part::Geometry *geo) const;
/*!
\brief Add geometry to a sketch
\brief Add geometry to a sketch - It adds a copy with a different uuid (internally uses copy() instead of clone())
\param geo - geometry to add
\param construction - true for construction lines
\retval int - GeoId of added element
*/
int addGeometry(const Part::Geometry *geo, bool construction=false);
/*!
\brief Add geometry to a sketch using up the provided newgeo. Caveat: It will use the provided newgeo with the uuid it has.
This is different from the addGeometry method with a naked pointer, where a different uuid is ensured. The caller is responsible
for provided a new or existing uuid, as necessary.
\param geo - geometry to add
\param construction - true for construction lines
\retval int - GeoId of added element
*/
int addGeometry(std::unique_ptr<Part::Geometry> newgeo, bool construction=false);
/*!
\brief Add multiple geometry elements to a sketch
\param geoList - geometry to add