Salome HOME
Issue #653 - Double and triple click edges -- Fix Debian dynamic_pointer_cast problem...
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.cpp
index e8d24eb51421f612c0b514c7d61b8263a460a667..ee59d8aeef8744ec7f610029c6f6488f914c03f8 100644 (file)
@@ -1,21 +1,19 @@
 // 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>
 #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)
 {
+  myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop);
+
   myFirstPntName = theData->getProperty("first_point");
 
   // Reconnect to local slot
@@ -41,15 +42,6 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
 {
 }
 
-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)
 {
@@ -59,23 +51,31 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
   if (!aPoint)
     return;
 
-  double aRadius = thePnt->distance(aPoint->pnt());
+  double aValue = computeValue(aPoint->pnt(), thePnt);
   AttributeDoublePtr aReal = aData->real(attributeID());
-  if (aReal && (aReal->value() != aRadius)) {
-    aReal->setValue(aRadius);
+  if (aReal && (aReal->value() != aValue)) {
+    aReal->setValue(aValue);
     
-    ModuleBase_Tools::setSpinValue(mySpinBox, aRadius);
+    ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
     storeValue();
   }
 }
 
+double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
+                                                   const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt)
+{
+  return theCurrentPnt->distance(theFirstPnt);
+}
+
 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*)));
+
+  myLockApplyMgr->activate();
 }
 
 void PartSet_WidgetPoint2dDistance::deactivate()
@@ -85,7 +85,8 @@ void PartSet_WidgetPoint2dDistance::deactivate()
              this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
   disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
              this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
-  myWorkshop->operationMgr()->setLockValidating(false);
+
+  myLockApplyMgr->deactivate();
 }
 
 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
@@ -94,6 +95,9 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
   if (theEvent->button() != Qt::LeftButton)
     return;
 
+  if (mySpinBox->hasVariable())
+    return;
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
@@ -106,8 +110,11 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
 
 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
-  myWorkshop->operationMgr()->setLockValidating(true);
-  myWorkshop->operationMgr()->setApplyEnabled(false);
+  if (isEditingMode())
+    return;
+
+  if (mySpinBox->hasVariable())
+    return;
 
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
@@ -120,7 +127,7 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
 
 void PartSet_WidgetPoint2dDistance::onValuesChanged()
 {
-  myWorkshop->operationMgr()->setLockValidating(false);
+  myLockApplyMgr->valuesChanged();
   emit valuesChanged();
 }