X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Arc.cpp;h=2b0a6c96f495ffcb0b9532939af9f290197cddb9;hb=cdbbde4803e9c320204d537d22af4ac7ef024962;hp=6c5f2e884b6c4dde43be996800c57226b22e3fbf;hpb=7074394f8f08413d885f63be01df6bd5007b868c;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 6c5f2e884..2b0a6c96f 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SketchPlugin_Arc.h" @@ -53,9 +52,9 @@ // for sqrt on Linux #include -const double tolerance = 1e-7; -const double paramTolerance = 1.e-4; -const double PI = 3.141592653589793238463; +static const double tolerance = 1e-7; +static const double paramTolerance = 1.e-4; +static const double PI = 3.141592653589793238463; SketchPlugin_Arc::SketchPlugin_Arc() @@ -119,52 +118,43 @@ void SketchPlugin_Arc::execute() aCircleForArc->parameter(anEndAttr->pnt(), paramTolerance, myParamBefore); } - GeomShapePtr anArcShape; + bool isReversed = boolean(REVERSED_ID())->value(); + + GeomEdgePtr anArcShape; if (fabs(myParamBefore - 2.0 * PI) < paramTolerance) { anArcShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aStart->distance(aCenter)); myParamBefore = 0; } else { - anArcShape = boolean(REVERSED_ID())->value() ? + anArcShape = isReversed ? GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal) : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal); } + // calculate tolerances for start and end points of the arc and set them to the result shape + // (this is done to fix gaps which appear because of inaccurate computation of arcs in PlaneGCS, + // which leads to difference in SketchPlugin_Arc attributes and boundary points of result shape) + if (anArcShape) { + for (int ind = 0; ind < 2; ++ind) { + bool isFirst = ind == 0; + GeomPointPtr anArcBndPoint = isFirst == isReversed ? anEnd : aStart; + GeomPointPtr aShapePoint = isFirst ? anArcShape->firstPoint() : anArcShape->lastPoint(); + double aDistance = anArcBndPoint->distance(aShapePoint); + // avoid setting too high tolerance because it may be caused by incomplete update of an arc + if (aDistance > tolerance && aDistance < 100. * tolerance) { + if (isFirst) + anArcShape->setFirstPointTolerance(aDistance); + else + anArcShape->setLastPointTolerance(aDistance); + } + } + } + std::shared_ptr aResult = document()->createConstruction(data(), 1); aResult->setShape(anArcShape); aResult->setIsInHistory(false); setResult(aResult, 1); } -void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) -{ - std::shared_ptr aData = data(); - if(!aData->isValid()) { - return; - } - - bool aWasBlocked = aData->blockSendAttributeUpdated(true); - - std::shared_ptr aCenter = std::dynamic_pointer_cast( - attribute(CENTER_ID())); - if(aCenter->isInitialized()) { - aCenter->move(theDeltaX, theDeltaY); - } - - std::shared_ptr aStart = std::dynamic_pointer_cast( - attribute(START_ID())); - if(aStart->isInitialized()) { - aStart->move(theDeltaX, theDeltaY); - } - - std::shared_ptr anEnd = std::dynamic_pointer_cast( - attribute(END_ID())); - if(anEnd->isInitialized()) { - anEnd->move(theDeltaX, theDeltaY); - } - - aData->blockSendAttributeUpdated(aWasBlocked); -} - bool SketchPlugin_Arc::isFixed() { return data()->selection(EXTERNAL_ID())->context().get() != NULL;