Salome HOME
Constriction type for all sketch entities
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Arc.cpp
index 0ae869322636f9d64f76240aa5a1bc96fc5fee13..f4bc7f93e3e5aca6c75a8b88e3d620cbcc6ab5fd 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 // File:        SketchPlugin_Arc.cpp
 // Created:     26 Apr 2014
 // Author:      Artem ZHIDKOV
@@ -21,7 +23,7 @@
 const double tolerance = 1e-7;
 
 SketchPlugin_Arc::SketchPlugin_Arc()
-    : SketchPlugin_Feature()
+    : SketchPlugin_SketchEntity()
 {
   myStartUpdate = false;
   myEndUpdate = false;
@@ -29,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());
@@ -126,6 +130,7 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
                 if (!anAIS)
                   anAIS = AISObjectPtr(new GeomAPI_AISObject);
                 anAIS->createShape(aCompound);
+                anAIS->setWidth(3);
                 return anAIS;
               }
             }
@@ -185,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()
@@ -234,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;
   }
 }