From ca97889e470a1b2562a12dce47b41bb69d71513d Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sat, 29 Jun 2024 15:52:21 +0530 Subject: [PATCH] [Sketcher] Refactor `SketchObject:validateExternalLinks()` --- src/Mod/Sketcher/App/SketchObject.cpp | 35 ++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 3c8f4359b3..d9dcd09d57 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -8112,7 +8112,6 @@ void SketchObject::validateExternalLinks() const std::string SubElement = SubElements[i]; TopoDS_Shape refSubShape; - bool removeBadLink = false; try { if (Obj->isDerivedFrom()) { const Part::Datum* datum = static_cast(Obj); @@ -8126,38 +8125,36 @@ void SketchObject::validateExternalLinks() const Part::TopoShape& refShape = refObj->Shape.getShape(); refSubShape = refShape.getSubShape(SubElement.c_str()); } + continue; // no bad link needs to be removed } catch (Base::IndexError& indexError) { - removeBadLink = true; Base::Console().warning( this->getFullLabel(), (indexError.getMessage() + "\n").c_str()); } catch (Base::ValueError& valueError) { - removeBadLink = true; Base::Console().warning( this->getFullLabel(), (valueError.getMessage() + "\n").c_str()); } catch (Standard_Failure&) { - removeBadLink = true; } - if (removeBadLink) { - rebuild = true; - Objects.erase(Objects.begin() + i); - SubElements.erase(SubElements.begin() + i); - const std::vector& constraints = Constraints.getValues(); - std::vector newConstraints(0); - int GeoId = GeoEnum::RefExt - i; - for (const auto& constr : constraints) { - auto newConstr = getConstraintAfterDeletingGeo(constr, GeoId); - if (newConstr) { - newConstraints.push_back(newConstr.release()); - } + rebuild = true; + Objects.erase(Objects.begin() + i); + SubElements.erase(SubElements.begin() + i); + + const std::vector& constraints = Constraints.getValues(); + std::vector newConstraints; + newConstraints.reserve(constraints.size()); + int GeoId = GeoEnum::RefExt - i; + for (const auto& constr : constraints) { + auto newConstr = getConstraintAfterDeletingGeo(constr, GeoId); + if (newConstr) { + newConstraints.push_back(newConstr.release()); } - - Constraints.setValues(std::move(newConstraints)); - i--;// we deleted an item, so the next one took its place } + + Constraints.setValues(std::move(newConstraints)); + i--;// we deleted an item, so the next one took its place } if (rebuild) {