Salome HOME
Using variables in WidgetDoubleValue
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2dDistance.cpp
index 9fdbc3f2773d6962fb5f509a73b7421f7efbbc8a..e8d24eb51421f612c0b514c7d61b8263a460a667 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        PartSet_WidgetPoint2dDistance.h
 // Created:     23 June 2014
 // Author:      Vitaly Smetannikov
@@ -5,11 +7,14 @@
 #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>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_OperationMgr.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
@@ -26,31 +31,24 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
     : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
 {
   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()
 {
 }
 
-//bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
-//{
-//  bool isDone = false;
-//
-//  if (theValue) {
-//    ModuleBase_WidgetValueFeature* aFeatureValue =
-//        dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
-//    if (aFeatureValue) {
-//      std::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
-//      ObjectPtr aObject = aFeatureValue->object();
-//      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
-//      if (aFeature && aPnt) {
-//        setPoint(aFeature, aPnt);
-//        isDone = true;
-//      }
-//    }
-//  }
-//  return isDone;
-//}
+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)
@@ -65,11 +63,13 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
   AttributeDoublePtr aReal = aData->real(attributeID());
   if (aReal && (aReal->value() != aRadius)) {
     aReal->setValue(aRadius);
-    mySpinBox->setValue(aRadius);
+    
+    ModuleBase_Tools::setSpinValue(mySpinBox, aRadius);
+    storeValue();
   }
 }
 
-void PartSet_WidgetPoint2dDistance::activate()
+void PartSet_WidgetPoint2dDistance::activateCustom()
 {
   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 
@@ -85,10 +85,15 @@ 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);
 }
 
 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;
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
@@ -101,6 +106,9 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
 
 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  myWorkshop->operationMgr()->setLockValidating(true);
+  myWorkshop->operationMgr()->setApplyEnabled(false);
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
@@ -110,4 +118,9 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
   setPoint(feature(), aPnt);
 }
 
+void PartSet_WidgetPoint2dDistance::onValuesChanged()
+{
+  myWorkshop->operationMgr()->setLockValidating(false);
+  emit valuesChanged();
+}