From 8b6d5728e724fc6b4eaa0a57bd465aa835583c11 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sun, 29 Dec 2024 03:26:39 +0530 Subject: [PATCH] [Sketcher] Incorporate review of #18665 ...by hyarion on December 29. --- src/Mod/Sketcher/App/SketchObject.cpp | 129 ++++++++++++-------------- 1 file changed, 57 insertions(+), 72 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 1117ec4f22..5b0e5ce044 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1596,7 +1596,7 @@ Base::Axis SketchObject::getAxis(int axId) const if (geo && GeometryFacade::getConstruction(geo) && geo->is()) { if (count == axId) { - Part::GeomLineSegment* lineSeg = static_cast(geo); + auto* lineSeg = static_cast(geo); Base::Vector3d start = lineSeg->getStartPoint(); Base::Vector3d end = lineSeg->getEndPoint(); return Base::Axis(start, end - start); @@ -1771,8 +1771,7 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo) std::vector newConstraints; newConstraints.reserve(constraints.size()); for (const auto& constr : constraints) { - auto newConstr = getConstraintAfterDeletingGeo(constr, GeoId); - if (newConstr) { + if (auto newConstr = getConstraintAfterDeletingGeo(constr, GeoId)) { newConstraints.push_back(newConstr.release()); } } @@ -3604,12 +3603,12 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) // Preexisting point on object constraints get converted to coincidents. // Returns: // - The constraint that should be used to constraint GeoId and cuttingGeoId - auto transformPreexistingConstraint = [this, &isPointAtPosition](const Constraint* constr, - int GeoId, - int cuttingGeoId, - Base::Vector3d& cutPointVec, - int newGeoId, - PointPos newPosId) { + auto transformPreexistingConstraint = [&isPointAtPosition](const Constraint* constr, + int GeoId, + int cuttingGeoId, + Base::Vector3d& cutPointVec, + int newGeoId, + PointPos newPosId) { /* TODO: It is possible that the trimming entity has both a PointOnObject constraint to the * trimmed entity, and a simple Tangent constraint to the trimmed entity. In this case we * want to change to a single end-to-end tangency, i.e we want to ensure that constrType1 @@ -3672,9 +3671,9 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) //******************* Step A => Detection of intersection - Common to all Geometries //****************************************// // GeoIds intersecting the curve around `point` - std::vector cuttingGeoIds(2, GeoEnum::GeoUndef); + std::array cuttingGeoIds {GeoEnum::GeoUndef, GeoEnum::GeoUndef}; // Points at the intersection - std::vector cutPoints(2); + std::array cutPoints; // Using SketchObject wrapper, as Part2DObject version returns GeoId = -1 when intersection not // found, which is wrong for a GeoId (axis). seekTrimPoints returns: @@ -3837,16 +3836,14 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) geoIdsToBeDeleted.insert(con->First); continue; } - std::unique_ptr newConstr = transformPreexistingConstraint( - con, GeoId, cuttingGeoIds[0], cutPoints[0], newIds.front(), PointPos::end); - if (newConstr != nullptr) { + if (auto newConstr = transformPreexistingConstraint( + con, GeoId, cuttingGeoIds[0], cutPoints[0], newIds.front(), PointPos::end)) { newConstraints.push_back(newConstr.release()); isPoint1ConstrainedOnGeoId1 = true; continue; } - newConstr = transformPreexistingConstraint( - con, GeoId, cuttingGeoIds[1], cutPoints[1], newIds.back(), PointPos::start); - if (newConstr != nullptr) { + if (auto newConstr = transformPreexistingConstraint( + con, GeoId, cuttingGeoIds[1], cutPoints[1], newIds.back(), PointPos::start)) { newConstraints.push_back(newConstr.release()); isPoint2ConstrainedOnGeoId2 = true; continue; @@ -4033,7 +4030,7 @@ bool SketchObject::deriveConstraintsForPieces(const int oldId, Base::Vector3d conPoint(getPoint(conId, conPos)); double conParam; - auto geoAsCurve = static_cast(geo); + auto* geoAsCurve = static_cast(geo); geoAsCurve->closestParameter(conPoint, conParam); // Choose based on where the closest point lies // If it's not there, just leave this constraint out @@ -4287,7 +4284,7 @@ int SketchObject::split(int GeoId, const Base::Vector3d& point) }); } else if (geo->is()) { - const Part::GeomBSplineCurve* bsp = static_cast(geo); + const auto* bsp = static_cast(geo); // what to do for periodic b-splines? originalIsPeriodic = bsp->isPeriodic(); @@ -4606,7 +4603,7 @@ bool SketchObject::isCarbonCopyAllowed(App::Document* pDoc, App::DocumentObject* } - SketchObject* psObj = static_cast(pObj); + auto* psObj = static_cast(pObj); // Sketches outside of the Document are NOT allowed if (this->getDocument() != pDoc) { @@ -5485,7 +5482,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = ssp; } else if (geocopy->is()) { - Part::GeomCircle* geosymcircle = static_cast(geocopy); + auto* geosymcircle = static_cast(geocopy); Base::Vector3d cp = geosymcircle->getCenter(); Base::Vector3d scp = cp + double(x) * displacement + double(y) * perpendicularDisplacement; @@ -5496,7 +5493,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = scp; } else if (geocopy->is()) { - Part::GeomArcOfCircle* geoaoc = static_cast(geocopy); + auto* geoaoc = static_cast(geocopy); Base::Vector3d cp = geoaoc->getCenter(); Base::Vector3d scp = cp + double(x) * displacement + double(y) * perpendicularDisplacement; @@ -5507,7 +5504,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = geoaoc->getStartPoint(true); } else if (geocopy->is()) { - Part::GeomEllipse* geosymellipse = static_cast(geocopy); + auto* geosymellipse = static_cast(geocopy); Base::Vector3d cp = geosymellipse->getCenter(); Base::Vector3d scp = cp + double(x) * displacement + double(y) * perpendicularDisplacement; @@ -5518,7 +5515,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = scp; } else if (geocopy->is()) { - Part::GeomArcOfEllipse* geoaoe = static_cast(geocopy); + auto* geoaoe = static_cast(geocopy); Base::Vector3d cp = geoaoe->getCenter(); Base::Vector3d scp = cp + double(x) * displacement + double(y) * perpendicularDisplacement; @@ -5553,7 +5550,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = geoaoe->getStartPoint(true); } else if (geocopy->is()) { - Part::GeomBSplineCurve* geobsp = static_cast(geocopy); + auto* geobsp = static_cast(geocopy); std::vector poles = geobsp->getPoles(); @@ -5571,7 +5568,7 @@ int SketchObject::addCopy(const std::vector& geoIdList, const Base::Vector3 iterfirstpoint = geobsp->getStartPoint(); } else if (geocopy->is()) { - Part::GeomPoint* geopoint = static_cast(geocopy); + auto* geopoint = static_cast(geocopy); Base::Vector3d cp = geopoint->getPoint(); Base::Vector3d scp = cp + double(x) * displacement + double(y) * perpendicularDisplacement; @@ -6041,20 +6038,15 @@ int SketchObject::exposeInternalGeometryForType(const int Geo int currentgeoid = getHighestCurveIndex(); int incrgeo = 0; - Base::Vector3d center; - double majord; - double minord; - Base::Vector3d majdir; - std::vector igeo; std::vector icon; - const Part::GeomEllipse* ellipse = static_cast(geo); + const auto* ellipse = static_cast(geo); - center = ellipse->getCenter(); - majord = ellipse->getMajorRadius(); - minord = ellipse->getMinorRadius(); - majdir = ellipse->getMajorAxisDir(); + Base::Vector3d center {ellipse->getCenter()}; + double majord {ellipse->getMajorRadius()}; + double minord {ellipse->getMinorRadius()}; + Base::Vector3d majdir {ellipse->getMajorAxisDir()}; Base::Vector3d mindir = Vector3d(-majdir.y, majdir.x); @@ -6182,32 +6174,27 @@ int SketchObject::exposeInternalGeometryForType(const in int currentgeoid = getHighestCurveIndex(); int incrgeo = 0; - Base::Vector3d center; - double majord; - double minord; - Base::Vector3d majdir; - std::vector igeo; std::vector icon; - const Part::GeomArcOfEllipse* aoe = static_cast(geo); + const auto* aoe = static_cast(geo); - center = aoe->getCenter(); - majord = aoe->getMajorRadius(); - minord = aoe->getMinorRadius(); - majdir = aoe->getMajorAxisDir(); + Base::Vector3d center {aoe->getCenter()}; + double majord {aoe->getMajorRadius()}; + double minord {aoe->getMinorRadius()}; + Base::Vector3d majdir {aoe->getMajorAxisDir()}; - Base::Vector3d mindir = Vector3d(-majdir.y, majdir.x); + Base::Vector3d mindir {-majdir.y, majdir.x}; - Base::Vector3d majorpositiveend = center + majord * majdir; - Base::Vector3d majornegativeend = center - majord * majdir; - Base::Vector3d minorpositiveend = center + minord * mindir; - Base::Vector3d minornegativeend = center - minord * mindir; + Base::Vector3d majorpositiveend {center + majord * majdir}; + Base::Vector3d majornegativeend {center - majord * majdir}; + Base::Vector3d minorpositiveend {center + minord * mindir}; + Base::Vector3d minornegativeend {center - minord * mindir}; double df = sqrt(majord * majord - minord * minord); - Base::Vector3d focus1P = center + df * majdir; - Base::Vector3d focus2P = center - df * majdir; + Base::Vector3d focus1P {center + df * majdir}; + Base::Vector3d focus2P {center - df * majdir}; if (!major) { Part::GeomLineSegment* lmajor = new Part::GeomLineSegment(); @@ -6319,12 +6306,12 @@ int SketchObject::exposeInternalGeometryForType(const int currentgeoid = getHighestCurveIndex(); int incrgeo = 0; - const Part::GeomArcOfHyperbola* aoh = static_cast(geo); + const auto* aoh = static_cast(geo); - Base::Vector3d center = aoh->getCenter(); - double majord = aoh->getMajorRadius(); - double minord = aoh->getMinorRadius(); - Base::Vector3d majdir = aoh->getMajorAxisDir(); + Base::Vector3d center {aoh->getCenter()}; + double majord {aoh->getMajorRadius()}; + double minord {aoh->getMinorRadius()}; + Base::Vector3d majdir {aoh->getMajorAxisDir()}; std::vector igeo; std::vector icon; @@ -6432,10 +6419,10 @@ int SketchObject::exposeInternalGeometryForType(const i int currentgeoid = getHighestCurveIndex(); int incrgeo = 0; - const Part::GeomArcOfParabola* aop = static_cast(geo); + const auto* aop = static_cast(geo); - Base::Vector3d center = aop->getCenter(); - Base::Vector3d focusp = aop->getFocus(); + Base::Vector3d center {aop->getCenter()}; + Base::Vector3d focusp {aop->getFocus()}; std::vector igeo; std::vector icon; @@ -6494,7 +6481,7 @@ int SketchObject::exposeInternalGeometryForType(const in { const Part::Geometry* geo = getGeometry(GeoId); - const Part::GeomBSplineCurve* bsp = static_cast(geo); + const auto* bsp = static_cast(geo); // First we search what has to be restored std::vector controlpointgeoids(bsp->countPoles(), GeoEnum::GeoUndef); @@ -6502,8 +6489,6 @@ int SketchObject::exposeInternalGeometryForType(const in bool isfirstweightconstrained = false; - std::vector::iterator it; - const std::vector& vals = Constraints.getValues(); // search for existing poles @@ -6844,7 +6829,7 @@ int SketchObject::deleteUnusedInternalGeometryWhenOneFocus(int GeoId, bool delge int SketchObject::deleteUnusedInternalGeometryWhenBSpline(int GeoId, bool delgeoid) { - const Part::GeomBSplineCurve* bsp = static_cast(getGeometry(GeoId)); + const auto* bsp = static_cast(getGeometry(GeoId)); // First we search existing IA std::vector > poleGeoIdsAndConstraints(bsp->countPoles(), {GeoEnum::GeoUndef, 0}); @@ -6980,7 +6965,7 @@ bool SketchObject::convertToNURBS(int GeoId) if (geo->is()) return false; - const Part::GeomCurve* geo1 = static_cast(geo); + const auto* geo1 = static_cast(geo); Part::GeomBSplineCurve* bspline; @@ -6988,7 +6973,7 @@ bool SketchObject::convertToNURBS(int GeoId) bspline = geo1->toNurbs(geo1->getFirstParameter(), geo1->getLastParameter()); if (geo1->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())) { - const Part::GeomArcOfConic* geoaoc = static_cast(geo1); + const auto* geoaoc = static_cast(geo1); if (geoaoc->isReversed()) bspline->reverse(); @@ -7067,7 +7052,7 @@ bool SketchObject::increaseBSplineDegree(int GeoId, int degreeincrement /*= 1*/) if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) return false; - const Part::GeomBSplineCurve* bsp = static_cast(geo); + const auto* bsp = static_cast(geo); const Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(bsp->handle()); @@ -7109,7 +7094,7 @@ bool SketchObject::decreaseBSplineDegree(int GeoId, int degreedecrement /*= 1*/) if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) return false; - const Part::GeomBSplineCurve* bsp = static_cast(geo); + const auto* bsp = static_cast(geo); const Handle(Geom_BSplineCurve) curve = Handle(Geom_BSplineCurve)::DownCast(bsp->handle()); @@ -7175,7 +7160,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m "The Geometry Index (GeoId) provided is not a B-spline.")); } - const Part::GeomBSplineCurve* bsp = static_cast(geo); + const auto* bsp = static_cast(geo); int degree = bsp->getDegree(); @@ -10059,8 +10044,8 @@ double SketchObject::calculateAngleViaPoint(int GeoId1, int GeoId2, double px, d // Temporary sketch based calculation. Slow, but guaranteed consistency with constraints. Sketcher::Sketch sk; - const Part::GeomCurve* p1 = dynamic_cast(this->getGeometry(GeoId1)); - const Part::GeomCurve* p2 = dynamic_cast(this->getGeometry(GeoId2)); + const auto* p1 = dynamic_cast(this->getGeometry(GeoId1)); + const auto* p2 = dynamic_cast(this->getGeometry(GeoId2)); if (p1 && p2) { // TODO: Check if any of these are B-splines