Salome HOME
Issue #353 constraint on 2 segments from not acive sketches
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Point.cpp
index cd862a6adbd46ccac051ffca6eea0b5b02500994..3fd71b5609e3429a5102ac7b9e314d69982802d2 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 // File:    SketchPlugin_Point.cpp
 // Created: 07 May 2014
 // Author:  Artem ZHIDKOV
@@ -12,7 +14,7 @@
 #include <ModelAPI_Session.h>
 
 #include <GeomAPI_Pnt2d.h>
-
+#include <GeomAPI_Vertex.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_PointBuilder.h>
 
@@ -68,5 +70,18 @@ double SketchPlugin_Point::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>&
 }
 
 bool SketchPlugin_Point::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context();
+  return data()->selection(EXTERNAL_ID())->context().get();
+}
+
+void SketchPlugin_Point::attributeChanged(const std::string& theID) {
+  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->isVertex()) {
+      std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aSelection));
+      std::shared_ptr<GeomDataAPI_Point2D> aCoordAttr = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(COORD_ID()));
+      aCoordAttr->setValue(sketch()->to2D(aVertex->point()));
+    }
+  }
 }