Salome HOME
Constriction type for all sketch entities
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Arc.cpp
index d6a6facfae37ceaa3eeaef964b49e10d53eedbaf..f4bc7f93e3e5aca6c75a8b88e3d620cbcc6ab5fd 100644 (file)
@@ -23,7 +23,7 @@
 const double tolerance = 1e-7;
 
 SketchPlugin_Arc::SketchPlugin_Arc()
-    : SketchPlugin_Feature()
+    : SketchPlugin_SketchEntity()
 {
   myStartUpdate = false;
   myEndUpdate = false;
@@ -31,6 +31,8 @@ SketchPlugin_Arc::SketchPlugin_Arc()
 
 void SketchPlugin_Arc::initAttributes()
 {
+  SketchPlugin_SketchEntity::initAttributes();
+
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
@@ -188,7 +190,7 @@ double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& t
 }
 
 bool SketchPlugin_Arc::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context();
+  return data()->selection(EXTERNAL_ID())->context().get();
 }
 
 bool SketchPlugin_Arc::isFeatureValid()
@@ -237,5 +239,14 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
     if (aProjection && aStartAttr->pnt()->distance(aProjection) > tolerance)
       aStartAttr->setValue(aProjection);
     myStartUpdate = false;
+  } else if (theID == CENTER_ID() && !myEndUpdate) {
+    myEndUpdate = 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);
+    myEndUpdate = false;
   }
 }