From: azv Date: Fri, 19 Feb 2016 12:24:08 +0000 (+0300) Subject: Update all attributes of circle when changing any (issue #1316) X-Git-Tag: V_2.2.0~89 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=31352237d1ac0cd952200e11f23aa52beeb7482a;p=modules%2Fshaper.git Update all attributes of circle when changing any (issue #1316) --- diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 4159df870..a57a9f4a1 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -24,6 +24,8 @@ #include #include +const double tolerance = 1e-7; + namespace { static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS() { @@ -117,6 +119,8 @@ void SketchPlugin_Circle::execute() aConstr2->setShape(aCircleShape); aConstr2->setIsInHistory(false); setResult(aConstr2, 1); + + adjustThreePoints(); } } } @@ -218,31 +222,11 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) { if (aType == CIRCLE_TYPE_THREE_POINTS()) return; - std::shared_ptr aCenterAttr = - std::dynamic_pointer_cast(attribute(CENTER_ID())); - if (!aCenterAttr->isInitialized()) - return; - AttributeDoublePtr aRadiusAttr = - std::dynamic_pointer_cast(attribute(RADIUS_ID())); - if (!aRadiusAttr->isInitialized()) - return; - // check the execute() was called and the shape was built if (!lastResult()) return; - data()->blockSendAttributeUpdated(true); - std::shared_ptr aFirstPnt = - std::dynamic_pointer_cast(attribute(FIRST_POINT_ID())); - std::shared_ptr aSecondPnt = - std::dynamic_pointer_cast(attribute(SECOND_POINT_ID())); - std::shared_ptr aThirdPnt = - std::dynamic_pointer_cast(attribute(THIRD_POINT_ID())); - double aRadius = aRadiusAttr->value(); - aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y()); - aSecondPnt->setValue(aCenterAttr->x(), aCenterAttr->y() + aRadius); - aThirdPnt->setValue(aCenterAttr->x() - aRadius, aCenterAttr->y()); - data()->blockSendAttributeUpdated(false); + adjustThreePoints(); } else if (theID == FIRST_POINT_ID() || theID == SECOND_POINT_ID() || theID == THIRD_POINT_ID()) { std::string aType = std::dynamic_pointer_cast( @@ -289,3 +273,33 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) { data()->blockSendAttributeUpdated(false); } } + +void SketchPlugin_Circle::adjustThreePoints() +{ + std::shared_ptr aCenterAttr = + std::dynamic_pointer_cast(attribute(CENTER_ID())); + if (!aCenterAttr->isInitialized()) + return; + AttributeDoublePtr aRadiusAttr = + std::dynamic_pointer_cast(attribute(RADIUS_ID())); + if (!aRadiusAttr->isInitialized()) + return; + + data()->blockSendAttributeUpdated(true); + std::shared_ptr aFirstPnt = + std::dynamic_pointer_cast(attribute(FIRST_POINT_ID())); + std::shared_ptr aSecondPnt = + std::dynamic_pointer_cast(attribute(SECOND_POINT_ID())); + std::shared_ptr aThirdPnt = + std::dynamic_pointer_cast(attribute(THIRD_POINT_ID())); + double aRadius = aRadiusAttr->value(); + + if (fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance || + fabs(aSecondPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance || + fabs(aThirdPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance) { + aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y()); + aSecondPnt->setValue(aCenterAttr->x(), aCenterAttr->y() + aRadius); + aThirdPnt->setValue(aCenterAttr->x() - aRadius, aCenterAttr->y()); + } + data()->blockSendAttributeUpdated(false); +} diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index b6d01897e..d931beb9a 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -86,6 +86,9 @@ protected: private: /// Returns true if all obligatory attributes are initialized bool isFeatureValid(); + + /// Update coordinates of representation by three points + void adjustThreePoints(); }; #endif