[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2026-01-06 01:40:24 +00:00
parent 9791d3f6d5
commit c19eb5c0e0
2 changed files with 183 additions and 148 deletions

View File

@@ -2020,15 +2020,12 @@ int SketchObject::delGeometriesExclusiveList(const std::vector<int>& GeoIds, Del
} }
// clang-format on // clang-format on
void SketchObject::replaceGeometries(std::vector<int> oldGeoIds, void SketchObject::replaceGeometries(std::vector<int> oldGeoIds, std::vector<Part::Geometry*>& newGeos)
std::vector<Part::Geometry*>& newGeos)
{ {
auto& vals = getInternalGeometry(); auto& vals = getInternalGeometry();
auto newVals(vals); auto newVals(vals);
if (std::ranges::any_of(oldGeoIds, [](auto geoId) { if (std::ranges::any_of(oldGeoIds, [](auto geoId) { return geoId < 0; })) {
return geoId < 0;
})) {
THROWM(ValueError, "Cannot replace external geometries and axes."); THROWM(ValueError, "Cannot replace external geometries and axes.");
} }
@@ -3980,11 +3977,13 @@ int SketchObject::split(int GeoId, const Base::Vector3d& point)
return 0; return 0;
} }
int SketchObject::join(int geoId1, int SketchObject::join(
Sketcher::PointPos posId1, int geoId1,
int geoId2, Sketcher::PointPos posId1,
Sketcher::PointPos posId2, int geoId2,
int continuity) Sketcher::PointPos posId2,
int continuity
)
{ {
// No need to check input data validity as this is an sketchobject managed operation // No need to check input data validity as this is an sketchobject managed operation
@@ -4025,9 +4024,11 @@ int SketchObject::join(int geoId1,
// we need the splines to be mutable because we may reverse them // we need the splines to be mutable because we may reverse them
// and/or change their degree // and/or change their degree
std::unique_ptr<Part::GeomBSplineCurve> bsp1( std::unique_ptr<Part::GeomBSplineCurve> bsp1(
geo1->toNurbs(geo1->getFirstParameter(), geo1->getLastParameter())); geo1->toNurbs(geo1->getFirstParameter(), geo1->getLastParameter())
);
std::unique_ptr<Part::GeomBSplineCurve> bsp2( std::unique_ptr<Part::GeomBSplineCurve> bsp2(
geo2->toNurbs(geo2->getFirstParameter(), geo2->getLastParameter())); geo2->toNurbs(geo2->getFirstParameter(), geo2->getLastParameter())
);
if (bsp1->isPeriodic() || bsp2->isPeriodic()) { if (bsp1->isPeriodic() || bsp2->isPeriodic()) {
THROWM(ValueError, "It is only possible to join non-periodic curves."); THROWM(ValueError, "It is only possible to join non-periodic curves.");
@@ -4087,18 +4088,22 @@ int SketchObject::join(int geoId1,
if (makeC1Continuous) { if (makeC1Continuous) {
newPoles.erase(newPoles.end() - 1); newPoles.erase(newPoles.end() - 1);
} }
newPoles.insert(newPoles.end(), newPoles.insert(
std::make_move_iterator(poles2.begin()), newPoles.end(),
std::make_move_iterator(poles2.end())); std::make_move_iterator(poles2.begin()),
std::make_move_iterator(poles2.end())
);
// TODO: Weights might need to be scaled // TODO: Weights might need to be scaled
weights2.erase(weights2.begin()); weights2.erase(weights2.begin());
if (makeC1Continuous) { if (makeC1Continuous) {
newWeights.erase(newWeights.end() - 1); newWeights.erase(newWeights.end() - 1);
} }
newWeights.insert(newWeights.end(), newWeights.insert(
std::make_move_iterator(weights2.begin()), newWeights.end(),
std::make_move_iterator(weights2.end())); std::make_move_iterator(weights2.begin()),
std::make_move_iterator(weights2.end())
);
// knots of the second spline come after all of the first // knots of the second spline come after all of the first
double offset = newKnots.back() - knots2.front(); double offset = newKnots.back() - knots2.front();
@@ -4106,9 +4111,11 @@ int SketchObject::join(int geoId1,
for (auto& knot : knots2) { for (auto& knot : knots2) {
knot += offset; knot += offset;
} }
newKnots.insert(newKnots.end(), newKnots.insert(
std::make_move_iterator(knots2.begin()), newKnots.end(),
std::make_move_iterator(knots2.end())); std::make_move_iterator(knots2.begin()),
std::make_move_iterator(knots2.end())
);
// end knots can have a multiplicity of (degree + 1) // end knots can have a multiplicity of (degree + 1)
if (bsp1->getDegree() < newMults.back()) { if (bsp1->getDegree() < newMults.back()) {
@@ -4119,17 +4126,21 @@ int SketchObject::join(int geoId1,
} }
mults2.erase(mults2.begin()); mults2.erase(mults2.begin());
newMults.insert(newMults.end(), newMults.insert(
std::make_move_iterator(mults2.begin()), newMults.end(),
std::make_move_iterator(mults2.end())); std::make_move_iterator(mults2.begin()),
std::make_move_iterator(mults2.end())
);
auto* newSpline = new Part::GeomBSplineCurve(newPoles, auto* newSpline = new Part::GeomBSplineCurve(
newWeights, newPoles,
newKnots, newWeights,
newMults, newKnots,
bsp1->getDegree(), newMults,
false, bsp1->getDegree(),
true); false,
true
);
// int newGeoId = addGeometry(newSpline); // int newGeoId = addGeometry(newSpline);
std::vector<Part::Geometry*> newGeos {newSpline}; std::vector<Part::Geometry*> newGeos {newSpline};
@@ -4139,10 +4150,10 @@ int SketchObject::join(int geoId1,
setConstruction(geoId1, areOriginalCurvesConstruction); setConstruction(geoId1, areOriginalCurvesConstruction);
// TODO: transfer constraints on the non-connected ends // TODO: transfer constraints on the non-connected ends
auto otherPosId1 = auto otherPosId1 = (Sketcher::PointPos::start == posId1) ? Sketcher::PointPos::end
(Sketcher::PointPos::start == posId1) ? Sketcher::PointPos::end : Sketcher::PointPos::start; : Sketcher::PointPos::start;
auto otherPosId2 = auto otherPosId2 = (Sketcher::PointPos::start == posId2) ? Sketcher::PointPos::end
(Sketcher::PointPos::start == posId2) ? Sketcher::PointPos::end : Sketcher::PointPos::start; : Sketcher::PointPos::start;
transferConstraints(geoId1, otherPosId1, geoId1, PointPos::start, true); transferConstraints(geoId1, otherPosId1, geoId1, PointPos::start, true);
transferConstraints(geoId2, otherPosId2, geoId1, PointPos::end, true); transferConstraints(geoId2, otherPosId2, geoId1, PointPos::end, true);
@@ -4331,10 +4342,12 @@ bool SketchObject::isCarbonCopyAllowed(App::Document* pDoc, App::DocumentObject*
} }
// clang-format on // clang-format on
int SketchObject::addSymmetric(const std::vector<int>& geoIdList, int SketchObject::addSymmetric(
int refGeoId, const std::vector<int>& geoIdList,
Sketcher::PointPos refPosId, int refGeoId,
bool addSymmetryConstraints) Sketcher::PointPos refPosId,
bool addSymmetryConstraints
)
{ {
// no need to check input data validity as this is an sketchobject managed operation. // no need to check input data validity as this is an sketchobject managed operation.
Base::StateLocker lock(managedoperation, true); Base::StateLocker lock(managedoperation, true);
@@ -4348,15 +4361,16 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
// Find out if reference is aligned with V or H axis, // Find out if reference is aligned with V or H axis,
// if so we can keep Vertical and Horizontal constraints in the mirrored geometry. // if so we can keep Vertical and Horizontal constraints in the mirrored geometry.
bool refIsLine = refPosId == Sketcher::PointPos::none; bool refIsLine = refPosId == Sketcher::PointPos::none;
bool refIsAxisAligned = bool refIsAxisAligned = refGeoId == Sketcher::GeoEnum::VAxis
refGeoId == Sketcher::GeoEnum::VAxis || refGeoId == Sketcher::GeoEnum::HAxis || !refIsLine || refGeoId == Sketcher::GeoEnum::HAxis || !refIsLine
|| std::ranges::any_of(constrvals, [&refGeoId](auto* constr) { || std::ranges::any_of(constrvals, [&refGeoId](auto* constr) {
return constr->First == refGeoId return constr->First == refGeoId
&& (constr->Type == Sketcher::Vertical || constr->Type == Sketcher::Horizontal); && (constr->Type == Sketcher::Vertical
}); || constr->Type == Sketcher::Horizontal);
});
std::vector<Part::Geometry*> symgeos = std::vector<Part::Geometry*> symgeos
getSymmetric(geoIdList, geoIdMap, isStartEndInverted, refGeoId, refPosId); = getSymmetric(geoIdList, geoIdMap, isStartEndInverted, refGeoId, refPosId);
{ {
addGeometry(symgeos); addGeometry(symgeos);
@@ -4378,8 +4392,7 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
if (constr->Second == GeoEnum::GeoUndef /*&& constr->Third == GeoEnum::GeoUndef*/) { if (constr->Second == GeoEnum::GeoUndef /*&& constr->Third == GeoEnum::GeoUndef*/) {
if (refIsAxisAligned if (refIsAxisAligned
&& (constr->Type == Sketcher::DistanceX && (constr->Type == Sketcher::DistanceX || constr->Type == Sketcher::DistanceY)) {
|| constr->Type == Sketcher::DistanceY)) {
// In this case we want to keep the Vertical, Horizontal constraints. // In this case we want to keep the Vertical, Horizontal constraints.
// DistanceX and DistanceY constraints should also be possible to keep in // DistanceX and DistanceY constraints should also be possible to keep in
// this case, but keeping them causes segfault, not sure why. // this case, but keeping them causes segfault, not sure why.
@@ -4412,9 +4425,11 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
// Second is also in the list // Second is also in the list
auto flipStartEndIfRelevant = [&isStartEndInverted](int geoId, auto flipStartEndIfRelevant = [&isStartEndInverted](
const Sketcher::PointPos posId, int geoId,
Sketcher::PointPos& posIdNew) { const Sketcher::PointPos posId,
Sketcher::PointPos& posIdNew
) {
if (isStartEndInverted[geoId]) { if (isStartEndInverted[geoId]) {
if (posId == Sketcher::PointPos::start) { if (posId == Sketcher::PointPos::start) {
posIdNew = Sketcher::PointPos::end; posIdNew = Sketcher::PointPos::end;
@@ -4519,14 +4534,18 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
if (!gf->isInternalAligned()) { if (!gf->isInternalAligned()) {
// Note internal aligned lines (ellipse, parabola, hyperbola) are causing // Note internal aligned lines (ellipse, parabola, hyperbola) are causing
// redundant constraint. // redundant constraint.
createSymConstr(geoId1, createSymConstr(
geoId2, geoId1,
PointPos::start, geoId2,
isStartEndInverted[geoId1] ? PointPos::end : PointPos::start); PointPos::start,
createSymConstr(geoId1, isStartEndInverted[geoId1] ? PointPos::end : PointPos::start
geoId2, );
PointPos::end, createSymConstr(
isStartEndInverted[geoId1] ? PointPos::start : PointPos::end); geoId1,
geoId2,
PointPos::end,
isStartEndInverted[geoId1] ? PointPos::start : PointPos::end
);
} }
} }
else if (geo->is<Part::GeomCircle>() || geo->is<Part::GeomEllipse>()) { else if (geo->is<Part::GeomCircle>() || geo->is<Part::GeomEllipse>()) {
@@ -4538,14 +4557,18 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
|| geo->is<Part::GeomArcOfHyperbola>() // || geo->is<Part::GeomArcOfHyperbola>() //
|| geo->is<Part::GeomArcOfParabola>()) { || geo->is<Part::GeomArcOfParabola>()) {
createEqualityConstr(geoId1, geoId2); createEqualityConstr(geoId1, geoId2);
createSymConstr(geoId1, createSymConstr(
geoId2, geoId1,
PointPos::start, geoId2,
isStartEndInverted[geoId1] ? PointPos::end : PointPos::start); PointPos::start,
createSymConstr(geoId1, isStartEndInverted[geoId1] ? PointPos::end : PointPos::start
geoId2, );
PointPos::end, createSymConstr(
isStartEndInverted[geoId1] ? PointPos::start : PointPos::end); geoId1,
geoId2,
PointPos::end,
isStartEndInverted[geoId1] ? PointPos::start : PointPos::end
);
} }
else if (geo->is<Part::GeomPoint>()) { else if (geo->is<Part::GeomPoint>()) {
auto gf = GeometryFacade::getFacade(geo); auto gf = GeometryFacade::getFacade(geo);
@@ -4565,11 +4588,13 @@ int SketchObject::addSymmetric(const std::vector<int>& geoIdList,
return Geometry.getSize() - 1; return Geometry.getSize() - 1;
} }
std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>& geoIdList, std::vector<Part::Geometry*> SketchObject::getSymmetric(
std::map<int, int>& geoIdMap, const std::vector<int>& geoIdList,
std::map<int, bool>& isStartEndInverted, std::map<int, int>& geoIdMap,
int refGeoId, std::map<int, bool>& isStartEndInverted,
Sketcher::PointPos refPosId) int refGeoId,
Sketcher::PointPos refPosId
)
{ {
using std::numbers::pi; using std::numbers::pi;
@@ -4623,7 +4648,8 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
geosymline->setPoints( geosymline->setPoints(
sp + 2.0 * (sp.Perpendicular(refGeoLine->getStartPoint(), vectline) - sp), sp + 2.0 * (sp.Perpendicular(refGeoLine->getStartPoint(), vectline) - sp),
ep + 2.0 * (ep.Perpendicular(refGeoLine->getStartPoint(), vectline) - ep)); ep + 2.0 * (ep.Perpendicular(refGeoLine->getStartPoint(), vectline) - ep)
);
isStartEndInverted.insert(std::make_pair(geoId, false)); isStartEndInverted.insert(std::make_pair(geoId, false));
} }
else if (geosym->is<Part::GeomCircle>()) { else if (geosym->is<Part::GeomCircle>()) {
@@ -4631,7 +4657,8 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
Base::Vector3d cp = geosymcircle->getCenter(); Base::Vector3d cp = geosymcircle->getCenter();
geosymcircle->setCenter( geosymcircle->setCenter(
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp)); cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp)
);
isStartEndInverted.insert(std::make_pair(geoId, false)); isStartEndInverted.insert(std::make_pair(geoId, false));
} }
else if (geosym->is<Part::GeomArcOfCircle>()) { else if (geosym->is<Part::GeomArcOfCircle>()) {
@@ -4640,17 +4667,15 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
Base::Vector3d ep = geoaoc->getEndPoint(true); Base::Vector3d ep = geoaoc->getEndPoint(true);
Base::Vector3d cp = geoaoc->getCenter(); Base::Vector3d cp = geoaoc->getCenter();
Base::Vector3d ssp = Base::Vector3d ssp = sp
sp + 2.0 * (sp.Perpendicular(refGeoLine->getStartPoint(), vectline) - sp); + 2.0 * (sp.Perpendicular(refGeoLine->getStartPoint(), vectline) - sp);
Base::Vector3d sep = Base::Vector3d sep = ep
ep + 2.0 * (ep.Perpendicular(refGeoLine->getStartPoint(), vectline) - ep); + 2.0 * (ep.Perpendicular(refGeoLine->getStartPoint(), vectline) - ep);
Base::Vector3d scp = Base::Vector3d scp = cp
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp);
double theta1 = double theta1 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * std::numbers::pi);
Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * std::numbers::pi); double theta2 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * std::numbers::pi);
double theta2 =
Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * std::numbers::pi);
geoaoc->setCenter(scp); geoaoc->setCenter(scp);
geoaoc->setRange(theta1, theta2, true); geoaoc->setRange(theta1, theta2, true);
@@ -4666,10 +4691,10 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
double df = sqrt(majord * majord - minord * minord); double df = sqrt(majord * majord - minord * minord);
Base::Vector3d f1 = cp + df * majdir; Base::Vector3d f1 = cp + df * majdir;
Base::Vector3d sf1 = Base::Vector3d sf1 = f1
f1 + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1); + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1);
Base::Vector3d scp = Base::Vector3d scp = cp
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp);
geosymellipse->setMajorAxisDir(sf1 - scp); geosymellipse->setMajorAxisDir(sf1 - scp);
@@ -4686,10 +4711,10 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
double df = sqrt(majord * majord - minord * minord); double df = sqrt(majord * majord - minord * minord);
Base::Vector3d f1 = cp + df * majdir; Base::Vector3d f1 = cp + df * majdir;
Base::Vector3d sf1 = Base::Vector3d sf1 = f1
f1 + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1); + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1);
Base::Vector3d scp = Base::Vector3d scp = cp
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp);
geosymaoe->setMajorAxisDir(sf1 - scp); geosymaoe->setMajorAxisDir(sf1 - scp);
@@ -4718,10 +4743,10 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
double df = sqrt(majord * majord + minord * minord); double df = sqrt(majord * majord + minord * minord);
Base::Vector3d f1 = cp + df * majdir; Base::Vector3d f1 = cp + df * majdir;
Base::Vector3d sf1 = Base::Vector3d sf1 = f1
f1 + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1); + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1);
Base::Vector3d scp = Base::Vector3d scp = cp
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp);
geosymaoe->setMajorAxisDir(sf1 - scp); geosymaoe->setMajorAxisDir(sf1 - scp);
@@ -4742,10 +4767,10 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
Base::Vector3d f1 = geosymaoe->getFocus(); Base::Vector3d f1 = geosymaoe->getFocus();
Base::Vector3d sf1 = Base::Vector3d sf1 = f1
f1 + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1); + 2.0 * (f1.Perpendicular(refGeoLine->getStartPoint(), vectline) - f1);
Base::Vector3d scp = Base::Vector3d scp = cp
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp);
geosymaoe->setXAxisDir(sf1 - scp); geosymaoe->setXAxisDir(sf1 - scp);
geosymaoe->setCenter(scp); geosymaoe->setCenter(scp);
@@ -4778,7 +4803,8 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
Base::Vector3d cp = geosympoint->getPoint(); Base::Vector3d cp = geosympoint->getPoint();
geosympoint->setPoint( geosympoint->setPoint(
cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp)); cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp)
);
isStartEndInverted.insert(std::make_pair(geoId, false)); isStartEndInverted.insert(std::make_pair(geoId, false));
} }
else { else {
@@ -4955,14 +4981,16 @@ std::vector<Part::Geometry*> SketchObject::getSymmetric(const std::vector<int>&
return symmetricVals; return symmetricVals;
} }
int SketchObject::addCopy(const std::vector<int>& geoIdList, int SketchObject::addCopy(
const Base::Vector3d& displacement, const std::vector<int>& geoIdList,
bool moveonly, const Base::Vector3d& displacement,
bool clone, bool moveonly,
int csize, bool clone,
int rsize, int csize,
bool constraindisplacement, int rsize,
double perpscale) bool constraindisplacement,
double perpscale
)
{ {
// no need to check input data validity as this is an sketchobject managed operation. // no need to check input data validity as this is an sketchobject managed operation.
Base::StateLocker lock(managedoperation, true); Base::StateLocker lock(managedoperation, true);
@@ -10952,7 +10980,8 @@ void SketchObject::migrateSketch()
} }
auto ext = std::static_pointer_cast<Part::GeometryMigrationExtension>( auto ext = std::static_pointer_cast<Part::GeometryMigrationExtension>(
g->getExtension(Part::GeometryMigrationExtension::getClassTypeId()).lock()); g->getExtension(Part::GeometryMigrationExtension::getClassTypeId()).lock()
);
if (!ext->testMigrationType(Part::GeometryMigrationExtension::Construction)) { if (!ext->testMigrationType(Part::GeometryMigrationExtension::Construction)) {
continue; continue;
@@ -10960,8 +10989,8 @@ void SketchObject::migrateSketch()
// at this point IA geometry is already migrated // at this point IA geometry is already migrated
auto gf = GeometryFacade::getFacade(g); auto gf = GeometryFacade::getFacade(g);
bool oldConstr = bool oldConstr = ext->getConstruction()
ext->getConstruction() || (g->is<Part::GeomPoint>() && !gf->isInternalAligned()); || (g->is<Part::GeomPoint>() && !gf->isInternalAligned());
GeometryFacade::setConstruction(g, oldConstr); GeometryFacade::setConstruction(g, oldConstr);
@@ -10973,8 +11002,7 @@ void SketchObject::migrateSketch()
auto constraints = Constraints.getValues(); auto constraints = Constraints.getValues();
auto geometries = getInternalGeometry(); auto geometries = getInternalGeometry();
bool parabolaFound = bool parabolaFound = std::ranges::any_of(geometries, &Part::Geometry::is<Part::GeomArcOfParabola>);
std::ranges::any_of(geometries, &Part::Geometry::is<Part::GeomArcOfParabola>);
if (!parabolaFound) { if (!parabolaFound) {
return; return;
@@ -11009,21 +11037,24 @@ void SketchObject::migrateSketch()
// look for a line from focusGeoId:start to Geoid:mid_external // look for a line from focusGeoId:start to Geoid:mid_external
std::vector<int> focusGeoIdListGeoIdList; std::vector<int> focusGeoIdListGeoIdList;
std::vector<PointPos> focusPosIdList; std::vector<PointPos> focusPosIdList;
getDirectlyCoincidentPoints(focusGeoId, getDirectlyCoincidentPoints(
Sketcher::PointPos::start, focusGeoId,
focusGeoIdListGeoIdList, Sketcher::PointPos::start,
focusPosIdList); focusGeoIdListGeoIdList,
focusPosIdList
);
std::vector<int> parabGeoIdListGeoIdList; std::vector<int> parabGeoIdListGeoIdList;
std::vector<PointPos> parabposidlist; std::vector<PointPos> parabposidlist;
getDirectlyCoincidentPoints(parabolaGeoId, getDirectlyCoincidentPoints(
Sketcher::PointPos::mid, parabolaGeoId,
parabGeoIdListGeoIdList, Sketcher::PointPos::mid,
parabposidlist); parabGeoIdListGeoIdList,
parabposidlist
);
for (const auto& parabGeoIdListGeoId : parabGeoIdListGeoIdList) { for (const auto& parabGeoIdListGeoId : parabGeoIdListGeoIdList) {
auto iterParabolaGeoId = auto iterParabolaGeoId = std::ranges::find(focusGeoIdListGeoIdList, parabGeoIdListGeoId);
std::ranges::find(focusGeoIdListGeoIdList, parabGeoIdListGeoId);
if (iterParabolaGeoId != focusGeoIdListGeoIdList.end()) { if (iterParabolaGeoId != focusGeoIdListGeoIdList.end()) {
axisGeoId2ParabolaGeoId[*iterParabolaGeoId] = parabolaGeoId; axisGeoId2ParabolaGeoId[*iterParabolaGeoId] = parabolaGeoId;
} }
@@ -11039,15 +11070,15 @@ void SketchObject::migrateSketch()
continue; continue;
} }
auto axisMajorCoincidentFound = auto axisMajorCoincidentFound
std::ranges::any_of(axisGeoId2ParabolaGeoId, [&](const auto& pair) { = std::ranges::any_of(axisGeoId2ParabolaGeoId, [&](const auto& pair) {
auto parabolaGeoId = pair.second; auto parabolaGeoId = pair.second;
auto axisgeoid = pair.first; auto axisgeoid = pair.first;
return (c->First == axisgeoid && c->Second == parabolaGeoId return (c->First == axisgeoid && c->Second == parabolaGeoId
&& c->SecondPos == PointPos::mid) && c->SecondPos == PointPos::mid)
|| (c->Second == axisgeoid && c->First == parabolaGeoId || (c->Second == axisgeoid && c->First == parabolaGeoId
&& c->FirstPos == PointPos::mid); && c->FirstPos == PointPos::mid);
}); });
if (axisMajorCoincidentFound) { if (axisMajorCoincidentFound) {
// we skip this coincident, the other coincident on axis will be substituted // we skip this coincident, the other coincident on axis will be substituted
@@ -11055,16 +11086,15 @@ void SketchObject::migrateSketch()
continue; continue;
} }
auto focusCoincidentFound = auto focusCoincidentFound = std::ranges::find_if(axisGeoId2ParabolaGeoId, [&](const auto& pair) {
std::ranges::find_if(axisGeoId2ParabolaGeoId, [&](const auto& pair) { auto parabolaGeoId = pair.second;
auto parabolaGeoId = pair.second; auto axisgeoid = pair.first;
auto axisgeoid = pair.first; auto focusGeoId = parabolaGeoId2FocusGeoId[parabolaGeoId];
auto focusGeoId = parabolaGeoId2FocusGeoId[parabolaGeoId]; return (c->First == axisgeoid && c->Second == focusGeoId
return (c->First == axisgeoid && c->Second == focusGeoId && c->SecondPos == PointPos::start)
&& c->SecondPos == PointPos::start) || (c->Second == axisgeoid && c->First == focusGeoId
|| (c->Second == axisgeoid && c->First == focusGeoId && c->FirstPos == PointPos::start);
&& c->FirstPos == PointPos::start); });
});
if (focusCoincidentFound != axisGeoId2ParabolaGeoId.end()) { if (focusCoincidentFound != axisGeoId2ParabolaGeoId.end()) {
auto* newConstr = new Sketcher::Constraint(); auto* newConstr = new Sketcher::Constraint();
@@ -11090,9 +11120,12 @@ void SketchObject::migrateSketch()
Base::Console().critical( Base::Console().critical(
this->getFullName(), this->getFullName(),
QT_TRANSLATE_NOOP("Notifications", QT_TRANSLATE_NOOP(
"Parabolas were migrated. Migrated files won't open in previous " "Notifications",
"versions of FreeCAD!!\n")); "Parabolas were migrated. Migrated files won't open in previous "
"versions of FreeCAD!!\n"
)
);
} }
// clang-format off // clang-format off

View File

@@ -133,8 +133,10 @@ TEST_F(SketchObjectTest, testReplaceGeometriesOneToTwo)
Part::GeomLineSegment lineSeg1; Part::GeomLineSegment lineSeg1;
setupLineSegment(lineSeg1); setupLineSegment(lineSeg1);
int geoId1 = getObject()->addGeometry(&lineSeg1); int geoId1 = getObject()->addGeometry(&lineSeg1);
std::vector<Part::Geometry*> newCurves {createTypicalNonPeriodicBSpline().release(), std::vector<Part::Geometry*> newCurves {
createTypicalNonPeriodicBSpline().release()}; createTypicalNonPeriodicBSpline().release(),
createTypicalNonPeriodicBSpline().release()
};
// Act // Act
getObject()->replaceGeometries({geoId1}, newCurves); getObject()->replaceGeometries({geoId1}, newCurves);