Skip to content

Commit

Permalink
Sketcher: [skip ci] add method SketchObject::delGeometries
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 5, 2020
1 parent a5b3386 commit 9801b36
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -1000,6 +1000,82 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo)
return 0;
}

int SketchObject::delGeometries(const std::vector<int>& GeoIds)
{
std::vector<int> sGeoIds(GeoIds);
std::sort(sGeoIds.begin(), sGeoIds.end());
if (sGeoIds.empty())
return 0;

Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.

const std::vector< Part::Geometry * > &vals = getInternalGeometry();
if (sGeoIds.front() < 0 || sGeoIds.back() >= int(vals.size()))
return -1;


std::vector< Part::Geometry * > newVals(vals);
for (auto it = sGeoIds.rbegin(); it != sGeoIds.rend(); ++it) {
int GeoId = *it;
newVals.erase(newVals.begin() + GeoId);

// Find coincident points to replace the points of the deleted geometry
std::vector<int> GeoIdList;
std::vector<PointPos> PosIdList;
for (PointPos PosId = start; PosId != mid; ) {
getDirectlyCoincidentPoints(GeoId, PosId, GeoIdList, PosIdList);
if (GeoIdList.size() > 1) {
delConstraintOnPoint(GeoId, PosId, true /* only coincidence */);
transferConstraints(GeoIdList[0], PosIdList[0], GeoIdList[1], PosIdList[1]);
}
PosId = (PosId == start) ? end : mid; // loop through [start, end, mid]
}
}

// Copy the original constraints
std::vector< Constraint* > constraints;
for (const auto ptr : this->Constraints.getValues())
constraints.push_back(ptr->clone());
std::vector< Constraint* > filteredConstraints(0);
for (auto it = sGeoIds.rbegin(); it != sGeoIds.rend(); ++it) {
int GeoId = *it;
for (std::vector<Constraint*>::const_iterator it = constraints.begin();
it != constraints.end(); ++it) {

Constraint* copiedConstr(*it);
if ((*it)->First != GeoId && (*it)->Second != GeoId && (*it)->Third != GeoId) {
if (copiedConstr->First > GeoId)
copiedConstr->First -= 1;
if (copiedConstr->Second > GeoId)
copiedConstr->Second -= 1;
if (copiedConstr->Third > GeoId)
copiedConstr->Third -= 1;
filteredConstraints.push_back(copiedConstr);
}
else {
delete copiedConstr;
}
}

constraints = filteredConstraints;
filteredConstraints.clear();
}

// Block acceptGeometry in OnChanged to avoid unnecessary checks and updates
{
Base::StateLocker lock(internaltransaction, true);
this->Geometry.setValues(newVals);
this->Constraints.setValues(std::move(constraints));
}
// Update geometry indices and rebuild vertexindex now via onChanged, so that ViewProvider::UpdateData is triggered.
Geometry.touch();

if (noRecomputes) // if we do not have a recompute, the sketch must be solved to update the DoF of the solver
solve();

return 0;
}

int SketchObject::deleteAllGeometry()
{
Base::StateLocker lock(managedoperation, true); // no need to check input data validity as this is an sketchobject managed operation.
Expand Down Expand Up @@ -5409,6 +5485,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m

this->Constraints.setValues(std::move(newcVals));
}

// Trigger update now
// Update geometry indices and rebuild vertexindex now via onChanged, so that ViewProvider::UpdateData is triggered.
Geometry.touch();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -105,6 +105,8 @@ class SketcherExport SketchObject : public Part::Part2DObject
\retval int - 0 if successful
*/
int delGeometry(int GeoId, bool deleteinternalgeo = true);
/// Does the same as \a delGeometry but allows to delete several geometries in one step
int delGeometries(const std::vector<int>& GeoIds);
/// deletes all the elements/constraints of the sketch except for external geometry
int deleteAllGeometry();
/// deletes all the constraints of the sketch
Expand Down

0 comments on commit 9801b36

Please sign in to comment.