Salome HOME
#2309 Possibility to hide faces
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.h
index 8b2ae15ba440f206f71ba7b03f1d27d4bc2f4bff..bd01429ed0b05ccc5e2facfefe3318aac088cba0 100644 (file)
@@ -1,9 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetValidated.h
-// Created:     12 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #ifndef MODULEBASE_WIDGETVALIDATED_H_
 #define MODULEBASE_WIDGETVALIDATED_H_
 #include <ModelAPI_Attribute.h>
 
 #include <SelectMgr_ListOfFilter.hxx>
+#include <NCollection_DataMap.hxx>
+#include <TopoDS_Shape.hxx>
 
 #include <QList>
+#include <QMap>
 
 class QWidget;
 class ModuleBase_IWorkshop;
@@ -26,7 +42,8 @@ class ModuleBase_ISelection;
 class ModuleBase_WidgetSelectorStore;
 class ModelAPI_Validator;
 class Config_WidgetAPI;
-class Handle_SelectMgr_EntityOwner;
+
+//#define LIST_OF_VALID_PRS
 
 /**
 * \ingroup GUI
@@ -59,16 +76,42 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg
   //! Clear all validated cash in the widget
   void clearValidatedCash();
 
+  /// Returns true if the workshop validator filter has been already activated
+  /// \return boolean value
+  bool isFilterActivated() const;
+
+  /// Block the model flush of update and intialization of attribute
+  /// \param theAttribute an attribute of blocking
+  /// \param theFeature a feature
+  /// \param theToBlock flag whether the model is blocked or unblocked
+  /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
+  /// to be used to restore flush state when unblocked
+  /// \param isAttributeSetInitializedBlocked out value if model is blocked
+  /// in value if model is unblocked to be used to restore previous state when unblocked
+  /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
+  static void blockFeatureAttribute(const AttributePtr& theAttribute,
+                                    const FeaturePtr& theFeature,
+                                    const bool& theToBlock,
+                                    bool& isFlushesActived,
+                                    bool& isAttributeSetInitializedBlocked,
+                                    bool& isAttributeSendUpdatedBlocked);
+
+  /// Checks the current attibute in all attribute validators
+  /// \param theAttribute an attribute to be validated
+  /// \return true if all validators return that the attribute is valid
+  static bool isValidAttribute(const AttributePtr& theAttribute);
+
 protected:
   /// Checks whether all active viewer filters validate the presentation
   /// \param thePrs a selected presentation in the view
   /// \return a boolean value
-  bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+  virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
 
   /// Checks all attribute validators returns valid. It tries on the given 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
+  /// \param theAttribute the attribute
   /// \return a boolean value
   bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
                                     const AttributePtr& theAttribute);
@@ -113,25 +156,18 @@ protected:
   /// Block the model flush of update and intialization of attribute
   /// \param theAttribute an attribute of blocking
   /// \param theToBlock flag whether the model is blocked or unblocked
-  /// \param isActive out value if model is blocked, in value if model is unblocked
+  /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
   /// to be used to restore flush state when unblocked
   /// \param isAttributeSetInitializedBlocked out value if model is blocked
   /// in value if model is unblocked to be used to restore previous state when unblocked
+  /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
-                              bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
-
-private:
-  /// Checks the current attibute in all attribute validators
-  /// \param theAttribute an attribute to be validated
-  /// \return true if all validators return that the attribute is valid
-  bool isValidAttribute(const AttributePtr& theAttribute) const;
-
-  /// Returns true if the workshop validator filter has been already activated
-  /// \return boolean value
-  bool isFilterActivated() const;
+                              bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
+                              bool& isAttributeSendUpdatedBlocked);
 
 protected:
-  /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
+  /// Gets the validity state of the presentation in an internal map.
+  /// Returns true if the valid state of value is stored
   /// \param theValue a viewer presentation
   /// \param theValid a valid state
   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
@@ -159,8 +195,17 @@ protected:
 
 private:
   ObjectPtr myPresentedObject; /// back up of the filtered object
-  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations
-  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations
+#ifdef LIST_OF_VALID_PRS
+  /// cash of valid selection presentations
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
+
+  /// cash of invalid selection presentations
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
+#else
+  // assume that one presentation selection presentation corresponds only one shape
+  NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
+  NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
+#endif
 
   /// store to backup parameters of the model
   ModuleBase_WidgetSelectorStore* myAttributeStore;