]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update all attributes of circle when changing any (issue #1316)
authorazv <azv@opencascade.com>
Fri, 19 Feb 2016 12:24:08 +0000 (15:24 +0300)
committerazv <azv@opencascade.com>
Fri, 19 Feb 2016 13:07:03 +0000 (16:07 +0300)
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h

index 4159df870dc818c75cbbec40226aea8e2bc50d6d..a57a9f4a19f916ca4dd11b5df6fe6a80d033ca79 100644 (file)
@@ -24,6 +24,8 @@
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
+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<GeomDataAPI_Point2D> aCenterAttr =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
-    if (!aCenterAttr->isInitialized())
-      return;
-    AttributeDoublePtr aRadiusAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(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<GeomDataAPI_Point2D> aFirstPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<ModelAPI_AttributeString>(
@@ -289,3 +273,33 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
     data()->blockSendAttributeUpdated(false);
   }
 }
+
+void SketchPlugin_Circle::adjustThreePoints()
+{
+  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
+  if (!aCenterAttr->isInitialized())
+    return;
+  AttributeDoublePtr aRadiusAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(attribute(RADIUS_ID()));
+  if (!aRadiusAttr->isInitialized())
+    return;
+
+  data()->blockSendAttributeUpdated(true);
+  std::shared_ptr<GeomDataAPI_Point2D> aFirstPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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);
+}
index b6d01897eb99ee2c0d4af35d41cc6694a6240a4b..d931beb9a0087fe20dd13cc45b1ac37d315bedc5 100644 (file)
@@ -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