[Sketcher] Refactor SketchObject::delGeometry()

Just dropped cognitive complexity to 25.
This commit is contained in:
Ajinkya Dahale
2024-06-18 01:14:43 +05:30
parent 5f86d7f5a8
commit 4cc21e26e1
2 changed files with 14 additions and 15 deletions

View File

@@ -1667,6 +1667,15 @@ int SketchObject::addGeometry(std::unique_ptr<Part::Geometry> newgeo, bool const
return Geometry.getSize() - 1;
}
bool SketchObject::hasInternalGeometry(const Part::Geometry* geo)
{
return (geo->is<Part::GeomEllipse>()
|| geo->is<Part::GeomArcOfEllipse>()
|| geo->is<Part::GeomArcOfHyperbola>()
|| geo->is<Part::GeomArcOfParabola>()
|| geo->is<Part::GeomBSplineCurve>());
}
int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo)
{
if (GeoId < 0) {
@@ -1682,19 +1691,10 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo)
if (GeoId < 0 || GeoId >= int(vals.size()))
return -1;
if (deleteinternalgeo) {
const Part::Geometry* geo = getGeometry(GeoId);
if (deleteinternalgeo && hasInternalGeometry(getGeometry(GeoId))) {
// Only for supported types
if ((geo->is<Part::GeomEllipse>()
|| geo->is<Part::GeomArcOfEllipse>()
|| geo->is<Part::GeomArcOfHyperbola>()
|| geo->is<Part::GeomArcOfParabola>()
|| geo->is<Part::GeomBSplineCurve>())) {
this->deleteUnusedInternalGeometry(GeoId, true);
return 0;
}
this->deleteUnusedInternalGeometry(GeoId, true);
return 0;
}
std::vector<Part::Geometry*> newVals(vals);
@@ -1703,14 +1703,12 @@ int SketchObject::delGeometry(int GeoId, bool deleteinternalgeo)
// Find coincident points to replace the points of the deleted geometry
std::vector<int> GeoIdList;
std::vector<PointPos> PosIdList;
for (PointPos PosId = PointPos::start; PosId != PointPos::mid;) {
for (PointPos PosId: {PointPos::start, PointPos::end, PointPos::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]);
}
// loop through [start, end, mid]
PosId = (PosId == PointPos::start) ? PointPos::end : PointPos::mid;
}
const std::vector<Constraint*>& constraints = this->Constraints.getValues();

View File

@@ -447,6 +447,7 @@ public:
double perpscale = 1.0);
int removeAxesAlignment(const std::vector<int>& geoIdList);
static bool hasInternalGeometry(const Part::Geometry* geo);
/// Exposes all internal geometry of an object supporting internal geometry
/*!
* \return -1 on error