]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Project end point when arc is under creation (issue #1324)
authorazv <azv@opencascade.com>
Fri, 19 Feb 2016 14:00:05 +0000 (17:00 +0300)
committerazv <azv@opencascade.com>
Fri, 19 Feb 2016 14:00:05 +0000 (17:00 +0300)
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h

index 2147cb1dd4e639ea576a2ae24a5ba62c1633a69b..6060698560e9d993f662a5e053b92c5ee3fad3f8 100644 (file)
@@ -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<GeomAPI_Circ2d> aCircleForArc(
-        new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
-    std::shared_ptr<GeomAPI_Pnt2d> 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<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> 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<GeomAPI_Circ2d> aCircleForArc(
+      new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
+  std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
+  if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
+    anEndAttr->setValue(aProjection);
+  updateDependentAttributes();
+  data()->blockSendAttributeUpdated(false);
+}
index 6accaa209230d9e7d68e0fdbfeb4f102cb5f7796..37d1d8ff63a9bd62f22352da08949a847ab8d03a 100644 (file)
@@ -129,6 +129,9 @@ private:
 
   /// Compose constraints to build tangency arc
   void tangencyArcConstraints();
+
+  /// Project end point of arc to the circle
+  void projectEndPoint();
 };
 
 #endif