From d9a7d92660515db325f8dd786d31d43951aba2e4 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 23 Jun 2016 20:25:05 +0300 Subject: [PATCH] Fix for issue #1594 --- src/SketchPlugin/SketchPlugin_Arc.cpp | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 9825ce9c2..7cf3c0ddf 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -213,19 +213,30 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious) std::shared_ptr aPassedAttr = std::dynamic_pointer_cast(data()->attribute(PASSED_POINT_ID())); if (!aPassedAttr->isInitialized()) { // calculate the appropriate center for the presentation - std::shared_ptr aDir = - aEndAttr->pnt()->xy()->decreased(aStartAttr->pnt()->xy())->multiplied(0.5); - double x = aDir->x(); - double y = aDir->y(); - aDir->setX(x - y); - aDir->setY(y + x); - std::shared_ptr aCenterXY = aStartAttr->pnt()->xy()->added(aDir); - aCenter = aSketch->to3D(aCenterXY->x(), aCenterXY->y()); + // check that center is bad for the current start and end and must be recomputed + std::shared_ptr aCircleForArc(new GeomAPI_Circ2d( + aCenterAttr->pnt(), aStartAttr->pnt())); + std::shared_ptr aProjection = aCircleForArc->project(aEndAttr->pnt()); + if (!aProjection.get() || aEndAttr->pnt()->distance(aProjection) > tolerance) { + std::shared_ptr aDir = + aEndAttr->pnt()->xy()->decreased(aStartAttr->pnt()->xy())->multiplied(0.5); + double x = aDir->x(); + double y = aDir->y(); + aDir->setX(x - y); + aDir->setY(y + x); + std::shared_ptr aCenterXY = aStartAttr->pnt()->xy()->added(aDir); + aCenter = aSketch->to3D(aCenterXY->x(), aCenterXY->y()); + } } } + AttributeBooleanPtr isInversed = + std::dynamic_pointer_cast(attribute(INVERSED_ID())); + + std::shared_ptr aCircleShape = + (isInversed->isInitialized() && isInversed->value()) ? + GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aEndPoint, aStartPoint, aNormal) : + GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); - std::shared_ptr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc( - aCenter, aStartPoint, aEndPoint, aNormal); if (aCircleShape) aShapes.push_back(aCircleShape); } -- 2.39.2