From: azv Date: Fri, 19 Feb 2016 14:00:05 +0000 (+0300) Subject: Project end point when arc is under creation (issue #1324) X-Git-Tag: V_2.2.0~86 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e3fb6b3118cdd2a4c147f063b99d7b6a394cbea2;p=modules%2Fshaper.git Project end point when arc is under creation (issue #1324) --- diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 2147cb1dd..606069856 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -523,19 +523,8 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) } if (theID == CENTER_ID()) { - if (!isFeatureValid()) - return; - if (aCenterAttr->pnt()->distance(aStartAttr->pnt()) < tolerance) - return; - data()->blockSendAttributeUpdated(true); - // compute and change the arc end point - std::shared_ptr aCircleForArc( - new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); - std::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); - if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance) - anEndAttr->setValue(aProjection); - updateDependentAttributes(); - data()->blockSendAttributeUpdated(false); + if (isFeatureValid()) + projectEndPoint(); return; } @@ -549,6 +538,11 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) if (anArcType == ARC_TYPE_CENTER_START_END()) { if (!isFeatureValid()) return; + if (theID == END_ID() && isStable()) { + // The arc is under construction, so its end point projected + // on the circle formed by center and start points + projectEndPoint(); + } updateDependentAttributes(); } else if (anArcType == ARC_TYPE_THREE_POINTS() && @@ -806,3 +800,25 @@ void SketchPlugin_Arc::tangencyArcConstraints() Events_Loop::loop()->setFlushed(anUpdateEvent, true); } } + +void SketchPlugin_Arc::projectEndPoint() +{ + std::shared_ptr aCenterAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(CENTER_ID())); + std::shared_ptr aStartAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(START_ID())); + std::shared_ptr anEndAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(END_ID())); + + if (aCenterAttr->pnt()->distance(aStartAttr->pnt()) < tolerance) + return; + data()->blockSendAttributeUpdated(true); + // compute and change the arc end point + std::shared_ptr aCircleForArc( + new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); + std::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); + if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance) + anEndAttr->setValue(aProjection); + updateDependentAttributes(); + data()->blockSendAttributeUpdated(false); +} diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 6accaa209..37d1d8ff6 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -129,6 +129,9 @@ private: /// Compose constraints to build tangency arc void tangencyArcConstraints(); + + /// Project end point of arc to the circle + void projectEndPoint(); }; #endif