Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Add frame (Export icon)
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.cpp
index 54887f018cc199c568914bd356ced275ec60ae39..07cf1877b7303c76a175fdc316933b3122bc3d61 100644 (file)
@@ -7,8 +7,9 @@
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_Tools.h"
 
-#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_IViewWindow.h>
+#include <ModuleBase_Tools.h>
 
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_Workshop.h>
@@ -40,6 +41,16 @@ 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)
 {
@@ -49,17 +60,22 @@ 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);
-    mySpinBox->blockSignals(true);
-    mySpinBox->setValue(aRadius);
-    mySpinBox->blockSignals(false);
+  if (aReal && (aReal->value() != aValue)) {
+    aReal->setValue(aValue);
+    
+    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();
@@ -81,6 +97,13 @@ void PartSet_WidgetPoint2dDistance::deactivate()
 
 void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  // the contex menu release by the right button should not be processed by this widget
+  if (theEvent->button() != Qt::LeftButton)
+    return;
+
+  if (mySpinBox->hasVariable())
+    return;
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
@@ -93,6 +116,9 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
 
 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  if (mySpinBox->hasVariable())
+    return;
+
   myWorkshop->operationMgr()->setLockValidating(true);
   myWorkshop->operationMgr()->setApplyEnabled(false);