Salome HOME
Resolve batch runtime errors on debian squeeze
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Point.cpp
index cd862a6adbd46ccac051ffca6eea0b5b02500994..cb2cad6de12cb3e4265aa7664737a340e9348736 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>
 
@@ -24,8 +26,8 @@ SketchPlugin_Point::SketchPlugin_Point()
 
 void SketchPlugin_Point::initAttributes()
 {
-  data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
-  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
 
@@ -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()));
+    }
+  }
 }