Salome HOME
#1119 Confirmation box for deleting parts
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.cpp
index 3dfefe34962ae3378ab53ef8ed4d66ecc06c70ed..562604dc05578878b5ef62c137adebad2296788b 100644 (file)
@@ -1,12 +1,11 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
-// File:        PartSet_WidgetPoint2dDistance.h
+// File:        PartSet_WidgetPoint2dDistance.cpp
 // Created:     23 June 2014
 // Author:      Vitaly Smetannikov
 
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_Tools.h"
-#include "PartSet_LockApplyMgr.h"
 
 #include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_IWorkshop.h>
@@ -29,29 +28,13 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
                                                              const std::string& theParentId)
  : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop)
 {
-  myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop);
-
   myFirstPntName = theData->getProperty("first_point");
-
-  // Reconnect to local slot
-  disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
-  connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged()));
 }
 
 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
 {
 }
 
-// It is not clear a necesity of this method also it contradicts to scenario defined in parent class
-//void PartSet_WidgetPoint2dDistance::reset()
-//{
-//  bool isOk;
-//  double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
-//
-//  ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
-//  storeValueCustom();
-//}
-
 void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
 {
@@ -84,19 +67,16 @@ void PartSet_WidgetPoint2dDistance::activateCustom()
           this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
           this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
-
-  myLockApplyMgr->activate();
 }
 
 void PartSet_WidgetPoint2dDistance::deactivate()
 {
+  ModuleBase_ModelWidget::deactivate();
   ModuleBase_IViewer* aViewer = myWorkshop->viewer();
   disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 
              this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
   disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
              this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
-
-  myLockApplyMgr->deactivate();
 }
 
 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -115,7 +95,10 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
   setPoint(feature(), aPnt);
-  emit focusOutWidget(this);
+
+  // if the validator of the control returns false, focus should not be switched
+  if (getError().isEmpty())
+    emit focusOutWidget(this);
 }
 
 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -132,12 +115,18 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
   PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
+  bool isBlocked = blockValueState(true);
   setPoint(feature(), aPnt);
+  blockValueState(isBlocked);
+  setValueState(ModifiedInViewer);
 }
 
-void PartSet_WidgetPoint2dDistance::onValuesChanged()
+bool PartSet_WidgetPoint2dDistance::processEnter()
 {
-  myLockApplyMgr->valuesChanged();
-  emit valuesChanged();
+  bool isModified = getValueState() == ModifiedInPP;
+  if (isModified) {
+    emit valuesChanged();
+    mySpinBox->selectAll();
+  }
+  return isModified;
 }
-