Salome HOME
setDisplayed has to be called in order to synchronize internal state of the object
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Arc.cpp
index f4bc7f93e3e5aca6c75a8b88e3d620cbcc6ab5fd..5599f3b0b138ce470394780fe97d80fe7faa40de 100644 (file)
@@ -13,6 +13,7 @@
 #include <ModelAPI_Session.h>
 
 #include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Circ.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
@@ -33,10 +34,10 @@ 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());
-  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
@@ -148,10 +149,6 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   if (!aData->isValid())
     return;
 
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      aData->attribute(SketchPlugin_Arc::CENTER_ID()));
-  aPoint1->move(theDeltaX, theDeltaY);
-
   myStartUpdate = true;
   myEndUpdate = true;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -163,6 +160,10 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   aPoint3->move(theDeltaX, theDeltaY);
   myStartUpdate = false;
   myEndUpdate = false;
+
+  std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(SketchPlugin_Arc::CENTER_ID()));
+  aPoint1->move(theDeltaX, theDeltaY);
 }
 
 double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
@@ -190,7 +191,7 @@ double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& t
 }
 
 bool SketchPlugin_Arc::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context().get();
+  return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
 
 bool SketchPlugin_Arc::isFeatureValid()
@@ -209,14 +210,28 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
 {
   std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-  if (!aCenterAttr->isInitialized())
-    return;
   std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(START_ID()));
-  if (!aStartAttr->isInitialized())
-    return;
   std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(END_ID()));
+  if (theID == EXTERNAL_ID()) {
+    std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+    // update arguments due to the selection value
+    if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+      std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
+      if (aCirc.get()) {
+        aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
+        anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+        aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
+      }
+    }
+    return;
+  }
+  if (!aCenterAttr->isInitialized())
+    return;
+  if (!aStartAttr->isInitialized())
+    return;
   if (!anEndAttr->isInitialized())
     return;