diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 29531d61bf..ac03e294ec 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -2982,156 +2982,149 @@ int SketchObject::split(int GeoId, const Base::Vector3d &point) std::vector newGeometries; std::vector newIds; std::vector newConstraints; - bool ok = false; Base::Vector3d startPoint, endPoint, splitPoint; double radius, startAngle, endAngle, splitAngle; unsigned int longestPart = 0; - do { - if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSegm = static_cast(geo); - startPoint = lineSegm->getStartPoint(); - endPoint = lineSegm->getEndPoint(); - splitPoint = point.Perpendicular(startPoint, endPoint - startPoint); - if ((endPoint - splitPoint).Length() > (splitPoint - startPoint).Length()) { - longestPart = 1; - } + bool ok = false; + if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { + const Part::GeomLineSegment *lineSegm = static_cast(geo); - Part::GeomLineSegment *newLine = static_cast(lineSegm->copy()); - newGeometries.push_back(newLine); + startPoint = lineSegm->getStartPoint(); + endPoint = lineSegm->getEndPoint(); + splitPoint = point.Perpendicular(startPoint, endPoint - startPoint); + if ((endPoint - splitPoint).Length() > (splitPoint - startPoint).Length()) { + longestPart = 1; + } - newLine->setPoints(startPoint, splitPoint); - int newId = addGeometry(newLine); - if (newId < 0) { - continue; - } + Part::GeomLineSegment *newLine = static_cast(lineSegm->copy()); + newGeometries.push_back(newLine); + + newLine->setPoints(startPoint, splitPoint); + int newId = addGeometry(newLine); + if (newId >= 0) { newIds.push_back(newId); setConstruction(newId, GeometryFacade::getConstruction(geo)); - newLine = static_cast(lineSegm->copy()); + newLine = static_cast(lineSegm->copy()); newGeometries.push_back(newLine); newLine->setPoints(splitPoint, endPoint); newId = addGeometry(newLine); - if (newId < 0) { - continue; + if (newId >= 0) { + newIds.push_back(newId); + setConstruction(newId, GeometryFacade::getConstruction(geo)); + + Constraint* joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = end; + joint->Second = newIds[1]; + joint->SecondPos = start; + newConstraints.push_back(joint); + + transferConstraints(GeoId, start, newIds[0], start, true); + transferConstraints(GeoId, end, newIds[1], end, true); + ok = true; } - newIds.push_back(newId); - setConstruction(newId, GeometryFacade::getConstruction(geo)); - - Constraint *joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = end; - joint->Second = newIds[1]; - joint->SecondPos = start; - newConstraints.push_back(joint); - - transferConstraints(GeoId, start, newIds[0], start, true); - transferConstraints(GeoId, end, newIds[1], end, true); - ok = true; } - else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = static_cast(geo); + } + else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { + const Part::GeomCircle *circle = static_cast(geo); - Base::Vector3d center(circle->getLocation()); - Base::Vector3d dir(point - center); - radius = circle->getRadius(); + Base::Vector3d center(circle->getLocation()); + Base::Vector3d dir(point - center); + radius = circle->getRadius(); - splitAngle = atan2(dir.y, dir.x); - startAngle = splitAngle; - endAngle = splitAngle + M_PI*2.0; + splitAngle = atan2(dir.y, dir.x); + startAngle = splitAngle; + endAngle = splitAngle + M_PI*2.0; - splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); - startPoint = splitPoint; - endPoint = splitPoint; + splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); + startPoint = splitPoint; + endPoint = splitPoint; - Part::GeomArcOfCircle *arc = new Part::GeomArcOfCircle(); - newGeometries.push_back(arc); + Part::GeomArcOfCircle *arc = new Part::GeomArcOfCircle(); + newGeometries.push_back(arc); - arc->setLocation(center); - arc->setRadius(radius); - arc->setRange(startAngle, endAngle, false); - int arcId = addGeometry(arc); - if (arcId < 0) { - continue; - } + arc->setLocation(center); + arc->setRadius(radius); + arc->setRange(startAngle, endAngle, false); + int arcId = addGeometry(arc); + if (arcId >= 0) { newIds.push_back(arcId); setConstruction(arcId, GeometryFacade::getConstruction(geo)); transferConstraints(GeoId, mid, arcId, mid); ok = true; } - else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = static_cast(geo); + } + else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { + const Part::GeomArcOfCircle *arc = static_cast(geo); - startPoint = arc->getStartPoint(); - endPoint = arc->getEndPoint(); + startPoint = arc->getStartPoint(); + endPoint = arc->getEndPoint(); - Base::Vector3d center(arc->getLocation()); - radius = arc->getRadius(); - arc->getRange(startAngle, endAngle, false); + Base::Vector3d center(arc->getLocation()); + radius = arc->getRadius(); + arc->getRange(startAngle, endAngle, false); - Base::Vector3d dir(point - center); - splitAngle = atan2(dir.y, dir.x); - if (splitAngle < startAngle) { - splitAngle += M_PI*2.0; - } - if (endAngle - splitAngle > splitAngle - startAngle) { - longestPart = 1; - } + Base::Vector3d dir(point - center); + splitAngle = atan2(dir.y, dir.x); + if (splitAngle < startAngle) { + splitAngle += M_PI*2.0; + } + if (endAngle - splitAngle > splitAngle - startAngle) { + longestPart = 1; + } - splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); - startPoint = splitPoint; - endPoint = splitPoint; + splitPoint = Base::Vector3d(center.x + radius*cos(splitAngle), center.y + radius*sin(splitAngle)); + startPoint = splitPoint; + endPoint = splitPoint; - Part::GeomArcOfCircle *newArc = static_cast(arc->copy()); - newGeometries.push_back(newArc); + Part::GeomArcOfCircle *newArc = static_cast(arc->copy()); + newGeometries.push_back(newArc); - newArc->setRange(startAngle, splitAngle, false); - int newId = addGeometry(newArc); - if (newId < 0) { - continue; - } + newArc->setRange(startAngle, splitAngle, false); + int newId = addGeometry(newArc); + if (newId >= 0) { newIds.push_back(newId); setConstruction(newId, GeometryFacade::getConstruction(geo)); - newArc = static_cast(arc->copy()); + newArc = static_cast(arc->copy()); newGeometries.push_back(newArc); newArc->setRange(splitAngle, endAngle, false); newId = addGeometry(newArc); - if (newId < 0) { - continue; + if (newId >= 0) { + newIds.push_back(newId); + setConstruction(newId, GeometryFacade::getConstruction(geo)); + + Constraint* joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = end; + joint->Second = newIds[1]; + joint->SecondPos = start; + newConstraints.push_back(joint); + + joint = new Constraint(); + joint->Type = Coincident; + joint->First = newIds[0]; + joint->FirstPos = mid; + joint->Second = newIds[1]; + joint->SecondPos = mid; + newConstraints.push_back(joint); + + transferConstraints(GeoId, start, newIds[0], start, true); + transferConstraints(GeoId, mid, newIds[0], mid); + transferConstraints(GeoId, end, newIds[1], end, true); + ok = true; } - newIds.push_back(newId); - setConstruction(newId, GeometryFacade::getConstruction(geo)); - - Constraint *joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = end; - joint->Second = newIds[1]; - joint->SecondPos = start; - newConstraints.push_back(joint); - - joint = new Constraint(); - joint->Type = Coincident; - joint->First = newIds[0]; - joint->FirstPos = mid; - joint->Second = newIds[1]; - joint->SecondPos = mid; - newConstraints.push_back(joint); - - transferConstraints(GeoId, start, newIds[0], start, true); - transferConstraints(GeoId, mid, newIds[0], mid); - transferConstraints(GeoId, end, newIds[1], end, true); - ok = true; } } - while (false); if (ok) { std::vector oldConstraints;