Salome HOME
Merge remote-tracking branch 'origin/BR_REENTRANCE_OPERATION' into origin_Dev_1.5.0
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index 8d9f07d31afe6579a720e41bc74e139c100b686f..ebfe32e00530ccc34534908a0970a667f7910d6b 100644 (file)
@@ -133,21 +133,45 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
                                          const bool theToValidate)
 {
+  bool isDone = false;
   if (theValues.empty())
-    return false;
+    return isDone;
 
   ModuleBase_ViewerPrs aValue = theValues.takeFirst();
-
-  Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
-  bool isDone = false;
   TopoDS_Shape aShape = aValue.shape();
-  double aX, aY;
-  if (getPoint2d(aView, aShape, aX, aY)) {
-    isDone = setPoint(aX, aY);
+  if (!aShape.IsNull()) {
+    Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
+    double aX, aY;
+    if (getPoint2d(aView, aShape, aX, aY)) {
+      isDone = setPoint(aX, aY);
+    }
+  }
+  else if (canBeActivatedByMove()) {
+    if (feature()->getKind() == SketchPlugin_Line::ID()) {
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aValue.object());
+      // Initialise new line with first point equal to end of previous
+      if (aFeature.get()) {
+        std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+        std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                                       aData->attribute(SketchPlugin_Line::END_ID()));
+        if (aPoint) {
+          setPoint(aPoint->x(), aPoint->y());
+          PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aPoint->x(),
+                                        aPoint->y());
+          isDone = true;
+        }
+      }
+    }
   }
   return isDone;
 }
 
+void PartSet_WidgetPoint2D::selectContent()
+{
+  myXSpin->selectAll();
+}
+
 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
 {
   if (fabs(theX) >= MaxCoordinate)
@@ -250,6 +274,16 @@ void PartSet_WidgetPoint2D::activateCustom()
   myWorkshop->activateSubShapesSelection(aModes);
 }
 
+bool PartSet_WidgetPoint2D::canBeActivatedByMove()
+{
+  bool aCanBeActivated = false;
+  if (feature()->getKind() == SketchPlugin_Line::ID() &&
+      attributeID() == SketchPlugin_Line::START_ID())
+    aCanBeActivated = true;
+
+  return aCanBeActivated;
+}
+
 void PartSet_WidgetPoint2D::deactivate()
 {
   ModuleBase_ModelWidget::deactivate();