Sketcher: assign the old geometries' GeometryId[s] to new geometries after scaling (#22263)

* Reassign facade ids after scale operation if deleting geometries

* Fix failing CI
This commit is contained in:
theo-vt
2025-07-14 11:39:03 -04:00
committed by GitHub
parent e38fe196d5
commit c8bddd2f2b
5 changed files with 118 additions and 10 deletions

View File

@@ -11631,6 +11631,24 @@ std::vector<Base::Vector3d> SketchObject::getOpenVertices() const
// SketchGeometryExtension interface
size_t setGeometryIdHelper(int GeoId, long id, std::vector<Part::Geometry*>& newVals, size_t searchOffset = 0, bool returnOnMatch = false)
{
// deep copy
for (size_t i = searchOffset; i < newVals.size(); i++) {
newVals[i] = newVals[i]->clone();
if ((int)i == GeoId) {
auto gf = GeometryFacade::getFacade(newVals[i]);
gf->setId(id);
if (returnOnMatch) {
return i;
}
}
}
return 0;
}
int SketchObject::setGeometryId(int GeoId, long id)
{
// no need to check input data validity as this is an sketchobject managed operation.
@@ -11641,18 +11659,34 @@ int SketchObject::setGeometryId(int GeoId, long id)
const std::vector<Part::Geometry*>& vals = getInternalGeometry();
std::vector<Part::Geometry*> newVals(vals);
setGeometryIdHelper(GeoId, id, newVals);
// There is not actual internal transaction going on here, however neither the geometry indices
// nor the vertices need to be updated so this is a convenient way of preventing it.
{
Base::StateLocker lock(internaltransaction, true);
this->Geometry.setValues(std::move(newVals));
}
return 0;
}
int SketchObject::setGeometryIds(std::vector<std::pair<int, long>> GeoIdsToIds)
{
Base::StateLocker lock(managedoperation, true);
std::sort(GeoIdsToIds.begin(), GeoIdsToIds.end());
size_t searchOffset = 0;
const std::vector<Part::Geometry*>& vals = getInternalGeometry();
std::vector<Part::Geometry*> newVals(vals);
// deep copy
for (size_t i = 0; i < newVals.size(); i++) {
newVals[i] = newVals[i]->clone();
if ((int)i == GeoId) {
auto gf = GeometryFacade::getFacade(newVals[i]);
gf->setId(id);
}
for (size_t i = 0; i < GeoIdsToIds.size(); ++i) {
int GeoId = GeoIdsToIds[i].first;
long id = GeoIdsToIds[i].second;
searchOffset = setGeometryIdHelper(GeoId, id, newVals, searchOffset, i != GeoIdsToIds.size()-1);
}
// There is not actual internal transaction going on here, however neither the geometry indices