diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index b28bf6cf7c..f6be46daf5 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -886,6 +886,14 @@ int SketchObject::addGeometry(const std::vector &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(geo->copy()); + + return addGeometry(std::move(geoNew),construction); +} + +int SketchObject::addGeometry(std::unique_ptr 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 diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index b7eb2143ea..9447fec986 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -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 newgeo, bool construction=false); + /*! \brief Add multiple geometry elements to a sketch \param geoList - geometry to add