Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Arc.cpp
index 7600903953f4cdd55607e11e3c5242c31dfa1864..0cb74987a0e63c5a060f709a26142415cdce9834 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());
@@ -128,6 +130,7 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
                 if (!anAIS)
                   anAIS = AISObjectPtr(new GeomAPI_AISObject);
                 anAIS->createShape(aCompound);
+                anAIS->setWidth(3);
                 return anAIS;
               }
             }
@@ -187,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() != NULL;
 }
 
 bool SketchPlugin_Arc::isFeatureValid()
@@ -236,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;
   }
 }