Salome HOME
Architecture changes
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.cpp
index f4c5bc6d16cd7980d27be2f4a0d32ee5523358f9..829380cef043548846458c274782a0df8eecb46f 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
-// File:        PartSet_WidgetPoint2dDistance.h
+// File:        PartSet_WidgetPoint2dDistance.cpp
 // Created:     23 June 2014
 // Author:      Vitaly Smetannikov
 
@@ -8,14 +8,11 @@
 #include "PartSet_Tools.h"
 
 #include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewWindow.h>
+#include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 
-#include <XGUI_ViewerProxy.h>
-#include <XGUI_Workshop.h>
-#include <XGUI_PropertyPanel.h>
-#include <XGUI_OperationMgr.h>
-
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
 #include <GeomDataAPI_Point2D.h>
 #include <QMouseEvent>
 
 PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
-                                                                   const Config_WidgetAPI* theData,
-                                                                   const std::string& theParentId)
-    : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
+                                                             ModuleBase_IWorkshop* theWorkshop,
+                                                             const Config_WidgetAPI* theData,
+                                                             const std::string& theParentId)
+ : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop)
 {
   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)
 {
@@ -78,8 +62,8 @@ double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptr<GeomAPI
 
 void PartSet_WidgetPoint2dDistance::activateCustom()
 {
-  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
-  connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+  connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
           this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
           this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
@@ -87,12 +71,12 @@ void PartSet_WidgetPoint2dDistance::activateCustom()
 
 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*)));
-  myWorkshop->operationMgr()->setLockValidating(false);
 }
 
 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -122,21 +106,26 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
   if (mySpinBox->hasVariable())
     return;
 
-  myWorkshop->operationMgr()->setLockValidating(true);
-  myWorkshop->operationMgr()->setApplyEnabled(false);
-
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
   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()
 {
-  myWorkshop->operationMgr()->setLockValidating(false);
-  emit valuesChanged();
+  //bool isModified = mySpinBox->isModified();
+  bool isModified = getValueState() == ModifiedInPP;
+  if (isModified) {
+    emit valuesChanged();
+    //mySpinBox->clearModified();
+    mySpinBox->selectAll();
+  }
+  return isModified;
 }
-