]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #252: Make Ok button non accessible while cursor of mouse within 3d viewer...
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 15 Dec 2014 16:08:29 +0000 (19:08 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 15 Dec 2014 16:08:29 +0000 (19:08 +0300)
src/ModuleBase/ModuleBase_IPropertyPanel.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/PartSet/PartSet_WidgetPoint2dDistance.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_Workshop.cpp

index a5bc8defa7e54b5656841d778c6d967e39a2c27c..fdac20d135efb252e1fbd54b82a3ac17938d5fc5 100644 (file)
@@ -33,6 +33,18 @@ public:
   void setEditingMode(bool isEditing) { myIsEditing = isEditing; }
   bool isEditingMode() const { return myIsEditing; }
 
+  /// Set Enable/Disable state of Ok button
+  virtual void setOkEnabled(bool theEnabled) = 0;
+
+  /// Returns state of Ok button
+  virtual bool isOkEnabled() const = 0;
+
+  /// Set Enable/Disable state of Ok button
+  virtual void setCancelEnabled(bool theEnabled) = 0;
+
+  /// Returns state of Ok button
+  virtual bool isCancelEnabled() const = 0;
+
 signals:
   /// The signal about key release on the control, that corresponds to the attribute
   /// \param theEvent key release event
index d3f73af250ef9d7a9f9fd420a80df89e1e0876ef..5f0fc5750f5fc54b8b1ac1e824c6442858337040 100644 (file)
@@ -12,6 +12,8 @@
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_SelectionMgr.h>
 #include <XGUI_Selection.h>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_OperationMgr.h>
 
 #include <ModuleBase_DoubleSpinBox.h>
 #include <ModuleBase_Tools.h>
@@ -68,7 +70,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     myXSpin->setToolTip("X");
     aGroupLay->addWidget(myXSpin, 0, 1);
 
-    connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
+    connect(myXSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged()));
   }
   {
     QLabel* aLabel = new QLabel(myGroupBox);
@@ -82,7 +84,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
     myYSpin->setToolTip("X");
     aGroupLay->addWidget(myYSpin, 1, 1);
 
-    connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
+    connect(myYSpin, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged()));
   }
 }
 
@@ -107,8 +109,13 @@ void PartSet_WidgetPoint2D::setPoint(double theX, double theY)
 {
 
   bool isBlocked = this->blockSignals(true);
+  myXSpin->blockSignals(true);
   myXSpin->setValue(theX);
+  myXSpin->blockSignals(false);
+
+  myYSpin->blockSignals(true);
   myYSpin->setValue(theY);
+  myYSpin->blockSignals(false);
   this->blockSignals(isBlocked);
 
   emit valuesChanged();
@@ -148,8 +155,13 @@ bool PartSet_WidgetPoint2D::restoreValue()
   double _Y = aPoint->y();
 #endif
   bool isBlocked = this->blockSignals(true);
+  myXSpin->blockSignals(true);
   myXSpin->setValue(aPoint->x());
+  myXSpin->blockSignals(false);
+
+  myYSpin->blockSignals(true);
   myYSpin->setValue(aPoint->y());
+  myYSpin->blockSignals(false);
   this->blockSignals(isBlocked);
   return true;
 }
@@ -167,25 +179,6 @@ QList<QWidget*> PartSet_WidgetPoint2D::getControls() const
   return aControls;
 }
 
-//bool PartSet_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
-//{
-//  if (myOptionParam.length() == 0)
-//    return false;
-//  std::shared_ptr<ModelAPI_Data> aData = theObject->data();
-//  std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-//      aData->attribute(myOptionParam));
-//  if (aPoint) {
-//    bool isBlocked = this->blockSignals(true);
-//    myXSpin->setValue(aPoint->x());
-//    myYSpin->setValue(aPoint->y());
-//    this->blockSignals(isBlocked);
-//
-//    emit valuesChanged();
-//    emit storedPoint2D(theObject, myOptionParam);
-//    return true;
-//  }
-//  return false;
-//}
 
 void PartSet_WidgetPoint2D::activate()
 {
@@ -259,6 +252,9 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
 
 void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  myWorkshop->operationMgr()->setLockValidating(true);
+  myWorkshop->propertyPanel()->setOkEnabled(false);
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, anY;
@@ -276,3 +272,8 @@ double PartSet_WidgetPoint2D::y() const
   return myYSpin->value();
 }
 
+void PartSet_WidgetPoint2D::onValuesChanged()
+{
+  myWorkshop->operationMgr()->setLockValidating(false);
+  emit valuesChanged();
+}
index 809ad91f9fa544a5f7627538792d3925a00776e2..69e6461ea75b3038667c4743ee9d75c0f2f00dd6 100644 (file)
@@ -98,6 +98,9 @@ protected slots:
   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
   void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
 
+private slots:
+  void onValuesChanged();
+
  private:
    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, 
                    double& theX, double& theY) const;
index 2e722d02891ee77815a9855f8c914ad4207178e3..9e4826780ff1988e8ccd28e28200dc37e0bc63e7 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_Workshop.h>
+#include <XGUI_PropertyPanel.h>
+#include <XGUI_OperationMgr.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
@@ -28,32 +30,16 @@ 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::setPoint(FeaturePtr theFeature,
                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
 {
@@ -67,7 +53,10 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
   AttributeDoublePtr aReal = aData->real(attributeID());
   if (aReal && (aReal->value() != aRadius)) {
     aReal->setValue(aRadius);
+    mySpinBox->blockSignals(true);
     mySpinBox->setValue(aRadius);
+    mySpinBox->blockSignals(false);
+    emit valuesChanged();
   }
 }
 
@@ -103,6 +92,9 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn
 
 void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  myWorkshop->operationMgr()->setLockValidating(true);
+  myWorkshop->propertyPanel()->setOkEnabled(false);
+
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
 
   double aX, aY;
@@ -112,4 +104,9 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd,
   setPoint(feature(), aPnt);
 }
 
+void PartSet_WidgetPoint2dDistance::onValuesChanged()
+{
+  myWorkshop->operationMgr()->setLockValidating(false);
+  emit valuesChanged();
+}
 
index a03a784947b9769a5599da126c29fe9a139964c3..ca95b75fd3ee11f0bd851fa1319dbc76d4a9985d 100644 (file)
@@ -56,6 +56,9 @@ protected:
   /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
   void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
 
+private slots:
+  void onValuesChanged();
+
  private:
   XGUI_Workshop* myWorkshop;
   std::string myFirstPntName;
index a46365d9fbfb99da64e2374edc2733381748971e..a8f68277b5aa2266d32b6cb4f4d6c4b33730a9d8 100644 (file)
@@ -13,7 +13,7 @@
 #include <QKeyEvent>
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
-    : QObject(theParent)
+    : QObject(theParent), myIsValidationLock(false)
 {
 }
 
@@ -139,7 +139,7 @@ void XGUI_OperationMgr::onValidateOperation()
   if (!hasOperation())
     return;
   ModuleBase_Operation* anOperation = currentOperation();
-  if(anOperation) {
+  if(anOperation && (!myIsValidationLock)) {
     bool isValid = anOperation->isValid();
     emit operationValidated(isValid);
   }
index c805532859282cbd56dfeea40bbefe786c259222..1cf7dcefcbbd5fcbb6a5cc6588f24f313d39a979 100644 (file)
@@ -82,6 +82,13 @@ Q_OBJECT
   /// Returns true if the operation can be aborted
   bool canAbortOperation();
 
+  /// Blocking/unblocking enabling of Ok button in property panel.
+  /// It is used when operation can not be validated even all attributes are valid
+  void setLockValidating(bool toLock) { myIsValidationLock = toLock; }
+
+  /// Returns state of validation locking
+  bool isValidationLocked() const { return myIsValidationLock; }
+
  public slots:
   /// Slot that commits the current operation.
   void onCommitOperation();
@@ -146,6 +153,9 @@ signals:
   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
   Operations myOperations;  ///< a stack of started operations. The active operation is on top,
                             // others are suspended and started by the active is finished
+
+  /// Lock/Unlock access to Ok button in property panel
+  bool myIsValidationLock;
 };
 
 #endif
index 8a3cf8bf19fe89e4bb24f6b509dcd29cf1d53f9d..c3d200d41ae5f130f517a4802598062eafcd772e 100644 (file)
@@ -221,3 +221,29 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
   else if (!isEditingMode())
     emit noMoreWidgets();
 }
+
+void XGUI_PropertyPanel::setOkEnabled(bool theEnabled)
+{
+  QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
+  anOkBtn->setEnabled(theEnabled);
+}
+
+bool XGUI_PropertyPanel::isOkEnabled() const
+{
+  QPushButton* anOkBtn = findChild<QPushButton*>(PROP_PANEL_OK);
+  return anOkBtn->isEnabled();
+}
+
+void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
+{
+  QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
+  anCancelBtn->setEnabled(theEnabled);
+}
+
+bool XGUI_PropertyPanel::isCancelEnabled() const
+{
+  QPushButton* anCancelBtn = findChild<QPushButton*>(PROP_PANEL_CANCEL);
+  return anCancelBtn->isEnabled();
+}
+
+
index 70afb7e7f547c37c399bb81494aa2687e15596af..071779431999597d0f990657037c22dc8690f43f 100644 (file)
@@ -59,6 +59,18 @@ Q_OBJECT
 
   void setStretchEnabled(bool isEnabled);
 
+  /// Set Enable/Disable state of Ok button
+  virtual void setOkEnabled(bool theEnabled);
+
+  /// Returns state of Ok button
+  virtual bool isOkEnabled() const;
+
+  /// Set Enable/Disable state of Ok button
+  virtual void setCancelEnabled(bool theEnabled);
+
+  /// Returns state of Ok button
+  virtual bool isCancelEnabled() const;
+
  public slots:
   void updateContentWidget(FeaturePtr theFeature);
   // Enables / disables "ok" ("accept") button
index 79491af8274f91b4b1088898f3aecbdb7e77e1fc..0157532e7c003674280e4cac904f9934842ca83a 100644 (file)
@@ -1229,15 +1229,12 @@ void XGUI_Workshop::onWidgetValuesChanged()
   FeaturePtr aFeature = anOperation->feature();
 
   ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
-  //if (aCustom)
-  //  aCustom->storeValue(aFeature);
 
   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
   QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
   for (; anIt != aLast; anIt++) {
     ModuleBase_ModelWidget* aCustom = *anIt;
-    if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
-      //aCustom->storeValue(aFeature);
+    if (aCustom && (aCustom == aSenderWidget)) {
       aCustom->storeValue();
     }
   }