Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: do not select...
authornds <nds@opencascade.com>
Fri, 8 Apr 2016 08:20:22 +0000 (11:20 +0300)
committernds <nds@opencascade.com>
Fri, 8 Apr 2016 08:21:43 +0000 (11:21 +0300)
12 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_FilterValidated.cpp
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetValidator.cpp [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetValidator.h [new file with mode: 0755]
src/PartSet/PartSet_WidgetPoint2DFlyout.cpp
src/PartSet/PartSet_WidgetPoint2DFlyout.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/PartSet/PartSet_WidgetPoint2dDistance.cpp
src/PartSet/PartSet_WidgetPoint2dDistance.h

index c7b2e215c0294fbcfcb9796a324a104be1a8c3cc..d2d93c9b5e92819151d85c8ea18d3db6c71a6bf3 100644 (file)
@@ -58,6 +58,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetSwitch.h
   ModuleBase_WidgetToolbox.h
   ModuleBase_WidgetValidated.h
+  ModuleBase_WidgetValidator.h
   ModuleBase_IconFactory.h
   ModuleBase_WidgetErrorLabel.h
 )
@@ -114,6 +115,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetSwitch.cpp
   ModuleBase_WidgetToolbox.cpp
   ModuleBase_WidgetValidated.cpp
+  ModuleBase_WidgetValidator.cpp
   ModuleBase_IconFactory.cpp
   ModuleBase_WidgetErrorLabel.cpp
   ModuleBase_SelectionValidator.cpp
index a41f154631c91eb1fd185b56baa6c4fe58294553..3d57d9f186922d496466ac9532e5d620d5672748 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_WidgetValidated.h>
+#include <ModuleBase_WidgetValidator.h>
 #include <ModuleBase_ViewerPrs.h>
 
 IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter);
@@ -30,8 +31,12 @@ Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityO
                                                                            (aCurrentWidget);
     ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs());
     myWorkshop->selection()->fillPresentation(aPrs, theOwner);
-
-    aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs);
+    if (aWidgetValidated)
+      aValid = !aWidgetValidated || aWidgetValidated->isValidSelection(aPrs);
+    else if (aCurrentWidget->widgetValidator()) {
+      ModuleBase_WidgetValidator* aWidgetValidator = aCurrentWidget->widgetValidator();
+      aValid = aWidgetValidator->isValidSelection(aPrs);
+    }
   }
 
 #ifdef DEBUG_FILTERS
index 1985400a453644d51c3836b917ee216dd87f687a..dc56812fc3bc3da50f36fa2dd1fc2cb4f1fa4eb3 100644 (file)
@@ -7,6 +7,7 @@
 #include "ModuleBase_ModelWidget.h"
 #include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_Tools.h"
+#include "ModuleBase_WidgetValidator.h"
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
@@ -30,7 +31,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
     : QWidget(theParent),
       myIsEditing(false),
       myState(Stored),
-      myIsValueStateBlocked(false)
+      myIsValueStateBlocked(false),
+      myWidgetValidator(0)
 {
   myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
 
@@ -168,6 +170,10 @@ void ModuleBase_ModelWidget::activate()
     if (anAttribute.get() != NULL && !anAttribute->isInitialized())
       initializeValueByActivate();
   }
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(true);
+
   activateCustom();
 }
 
@@ -177,6 +183,9 @@ void ModuleBase_ModelWidget::deactivate()
   if (myState == ModifiedInPP || myState == ModifiedInViewer)
     storeValue();
   myState = Stored;
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(false);
 }
 
 void ModuleBase_ModelWidget::initializeValueByActivate()
index 6712bc0299d715372cd3edb805c5bece054dc25c..11d983a33df0ce42cb33e323a70ee9799d63d02e 100644 (file)
@@ -18,6 +18,7 @@
 class Config_WidgetAPI;
 class ModuleBase_IWorkshop;
 class ModuleBase_ViewerPrs;
+class ModuleBase_WidgetValidator;
 class QKeyEvent;
 
 /**\class ModuleBase_ModelWidget
@@ -114,6 +115,14 @@ Q_OBJECT
   /// \param theValues a list of presentations
   virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) {};
 
+  /// Checks if the selection presentation is valid in widget 
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue) { return true; }
+
+  /// Returns widget validator, by default it is NULL. To be created in a child if necessary
+  ModuleBase_WidgetValidator* widgetValidator() { return myWidgetValidator; }
+
   /// Restore value from attribute data to the widget's control. Emits signals before and after store
   /// \return True in success
   bool restoreValue();
@@ -280,6 +289,7 @@ protected slots:
   void onWidgetValuesModified();
 
  protected:
+   ModuleBase_WidgetValidator* myWidgetValidator; /// own validator, by default it is zero
 
   /// The attribute name of the model feature
   std::string myAttributeID;
diff --git a/src/ModuleBase/ModuleBase_WidgetValidator.cpp b/src/ModuleBase/ModuleBase_WidgetValidator.cpp
new file mode 100755 (executable)
index 0000000..330b4c4
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <ModuleBase_WidgetValidator.h>
+
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_IWorkshop.h>
+
+ModuleBase_WidgetValidator::ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
+                                                       ModuleBase_IWorkshop* theWorkshop)
+: myModelWidget(theModelWidget), myWorkshop(theWorkshop)
+{
+}
+
+ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
+{
+}
+
+//********************************************************************
+bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
+{
+  return myModelWidget->isValidSelectionCustom(theValue);
+}
+
+bool ModuleBase_WidgetValidator::isFilterActivated() const
+{
+  bool isActivated = false;
+
+  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+  return aViewer->hasSelectionFilter(aSelFilter);
+}
+
+bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
+{
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+  bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter);
+
+  if (toActivate)
+    aViewer->addSelectionFilter(aSelFilter);
+  else {
+    aViewer->removeSelectionFilter(aSelFilter);
+    //clearValidatedCash();
+  }
+
+  return aHasSelectionFilter;
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetValidator.h b/src/ModuleBase/ModuleBase_WidgetValidator.h
new file mode 100755 (executable)
index 0000000..942e9bc
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetValidator.h
+// Created:     12 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+
+#ifndef ModuleBase_WidgetValidator_H_
+#define ModuleBase_WidgetValidator_H_
+
+#include <ModuleBase.h>
+
+#include <memory>
+
+class ModuleBase_ModelWidget;
+class ModuleBase_IWorkshop;
+class ModuleBase_ViewerPrs;
+
+/**
+* \ingroup GUI
+* Implementation of widget with validators and filters processing.
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetValidator
+{
+ public:
+  /// Constructor
+  /// \param theModelWidget the model widget to be validated
+  /// \param theWorkshop the current workshop
+  ModuleBase_WidgetValidator(ModuleBase_ModelWidget* theModelWidget,
+                             ModuleBase_IWorkshop* theWorkshop);
+  virtual ~ModuleBase_WidgetValidator();
+
+  /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
+  /// next, the attribute's validating. It trying on the give selection to current attribute by
+  /// setting the value inside and calling validators. After this, the previous attribute value is
+  /// restored.The valid/invalid value is cashed.
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
+  /// It obtains selection filters from the workshop and activates them in the active viewer
+  /// \param toActivate a flag about activation or deactivation the filters
+  /// \return true if the selection filter of the widget is activated in viewer context
+  bool activateFilters(const bool toActivate);
+
+private:
+  /// Returns true if the workshop validator filter has been already activated
+  /// \return boolean value
+  bool isFilterActivated() const;
+
+protected:
+  /// Reference to workshop
+  ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
+  ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
+};
+
+#endif /* ModuleBase_WidgetValidator_H_ */
index bb4d54b0eebf929ddb35102264d87103e8f3b228..f02e6a2b75d4b04da084641cd824152a3fdf8da7 100755 (executable)
@@ -6,6 +6,8 @@
 
 #include "PartSet_WidgetPoint2DFlyout.h"
 
+#include "ModuleBase_WidgetValidator.h"
+
 #include <XGUI_Workshop.h>
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
@@ -21,6 +23,13 @@ PartSet_WidgetPoint2DFlyout::PartSet_WidgetPoint2DFlyout(QWidget* theParent,
                                                          const Config_WidgetAPI* theData)
  : PartSet_WidgetPoint2D(theParent, theWorkshop, theData)
 {
+  myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+}
+
+bool PartSet_WidgetPoint2DFlyout::isValidSelectionCustom(
+                                      const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
+{
+  return false;
 }
 
 bool PartSet_WidgetPoint2DFlyout::useSelectedShapes() const
index f6247b33f79fda40e6b056e33477d7fa27a6f48b..f6eeb7af374b4c6798784705df78a9385d52874c 100755 (executable)
@@ -30,6 +30,11 @@ public:
   /// Destructor
   virtual ~PartSet_WidgetPoint2DFlyout() {};
 
+  /// Checks if the selection presentation is valid in widget 
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
   /// Activates the editor control only in case if the mouse over the OCC window, otherwise
   /// set focus to the usual double value control
   /// \return the state whether the widget can accept the focus
index 07270eacc49863bb744569ce9eca6dce10195faa..a2c0245033bddbf26d787e7d2d61bba0607907e8 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModuleBase_IViewWindow.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_WidgetValidator.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -116,6 +117,22 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
   ModuleBase_Tools::zeroMargins(aLayout);
   aLayout->addWidget(myGroupBox);
   setLayout(aLayout);
+
+  myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+}
+
+bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
+{
+  bool aValid = true;
+  /*if (getValidState(theValue, aValid)) {
+    return aValid;
+  }
+  aValid = isValidSelectionCustom(theValue);
+  if (aValid)
+    aValid = isValidSelectionForAttribute(theValue, attribute());
+
+  storeValidState(theValue, aValid);
+  */return aValid;
 }
 
 bool PartSet_WidgetPoint2D::resetCustom()
index c685c5ca0cdc11536dec87ec9f88b2f0f73229c7..449b890f3686df3db718150784a9c8b01c9ad1d2 100755 (executable)
@@ -47,6 +47,11 @@ Q_OBJECT
   /// Destructor
   virtual ~PartSet_WidgetPoint2D();
 
+  /// Checks if the selection presentation is valid in widget 
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
   /// Set the given wrapped value to the current widget
   /// This value should be processed in the widget according to the needs
   /// \param theValues the wrapped widget values
index ed8165c23ab76da3c83746361a856b120b2a9348..f3991587b375a6180473b803b6d5efe74d197e1b 100644 (file)
@@ -16,6 +16,7 @@
 #include <ModuleBase_IViewWindow.h>
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetValidator.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
@@ -33,12 +34,19 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
   myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0)
 {
   myFirstPntName = theData->getProperty("first_point");
+  myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
 }
 
 PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
 {
 }
 
+bool PartSet_WidgetPoint2dDistance::isValidSelectionCustom(
+                                      const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
+{
+  return false;
+}
+
 bool PartSet_WidgetPoint2dDistance::resetCustom()
 {
   bool aDone = false;
index c81a3dc8291b004e79386b13cd96a8c4735e0a0d..55825c4b648b2a8baf5b0e0dc9d99eaed6b73feb 100644 (file)
@@ -47,6 +47,11 @@ Q_OBJECT
 
   virtual ~PartSet_WidgetPoint2dDistance();
 
+  /// Checks if the selection presentation is valid in widget 
+  /// \param theValue a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
   /// The methiod called when widget is deactivated
   virtual void deactivate();