Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: extrusion by preselection
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetValidated.h
4 // Created:     12 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef MODULEBASE_WIDGETVALIDATED_H_
9 #define MODULEBASE_WIDGETVALIDATED_H_
10
11 #include <ModuleBase.h>
12 #include <ModuleBase_ModelWidget.h>
13
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_AISObject.h>
16 #include <ModelAPI_Object.h>
17
18 #include <SelectMgr_ListOfFilter.hxx>
19
20 #include <QList>
21
22 class QWidget;
23 class ModuleBase_IWorkshop;
24 class ModuleBase_ISelection;
25 class ModelAPI_Validator;
26 class Config_WidgetAPI;
27 class Handle_SelectMgr_EntityOwner;
28
29 /**
30 * \ingroup GUI
31 * Implementation of widget with validators and filters processing.
32 */
33 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
34 {
35   Q_OBJECT
36  public:
37   /// Constructor
38   /// \param theParent the parent object
39   /// \param theWorkshop a reference to workshop
40   /// \param theData the widget configuation. The attribute of the model widget is obtained from
41   ModuleBase_WidgetValidated(QWidget* theParent,
42                              ModuleBase_IWorkshop* theWorkshop,
43                              const Config_WidgetAPI* theData);
44   virtual ~ModuleBase_WidgetValidated();
45
46   /// Checks all widget validator if the owner is valid
47   /// \param theValue a selected presentation in the view
48   /// \return a boolean value
49   bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
50
51   //! Returns data object by AIS
52   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
53
54   //! Clear all validated cash in the widget
55   void clearValidatedCash();
56
57 protected:
58   /// Checks whether all active viewer filters validate the presentation
59   /// \param thePrs a selected presentation in the view
60   /// \return a boolean value
61   bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
62
63   /// Creates a backup of the current values of the attribute
64   /// It should be realized in the specific widget because of different
65   /// parameters of the current attribute
66   virtual void storeAttributeValue();
67
68   /// Creates a backup of the current values of the attribute
69   /// It should be realized in the specific widget because of different
70   /// parameters of the current attribute
71   /// \param theValid a boolean flag, if restore happens for valid parameters
72   virtual void restoreAttributeValue(const bool theValid);
73
74   /// Checks the widget validity. By default, it returns true.
75   /// \param thePrs a selected presentation in the view
76   /// \return a boolean value
77   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
78
79   /// Fills the attribute with the value of the selected owner
80   /// \param thePrs a selected owner
81   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
82
83   /// Returns a list of selected presentations in the viewer and object browser
84   /// The presentations from the object browser are filtered by the AIS context filters
85   /// \return a list of presentations
86   QList<ModuleBase_ViewerPrs> getFilteredSelected();
87
88   /// It obtains selection filters from the workshop and activates them in the active viewer
89   /// \param toActivate a flag about activation or deactivation the filters
90   /// \return true if the selection filter of the widget is activated in viewer context
91   bool activateFilters(const bool toActivate);
92
93   /// Block the model flush of update and intialization of attribute
94   /// \param theToBlock flag whether the model is blocked or unblocked
95   /// \param isActive out value if model is blocked, in value if model is unblocked
96   /// to be used to restore flush state when unblocked
97   /// \param isAttributeSetInitializedBlocked out value if model is blocked
98   /// in value if model is unblocked to be used to restore previous state when unblocked
99   virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
100                               bool& isAttributeSetInitializedBlocked);
101
102 private:
103   /// Checks the current attibute in all attribute validators
104   // \return true if all validators return that the attribute is valid
105   bool isValidAttribute() const;
106
107   /// Returns true if the workshop validator filter has been already activated
108   /// \return boolean value
109   bool isFilterActivated() const;
110
111   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
112   /// \param theValue a viewer presentation
113   /// \param theValid a valid state
114   bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
115
116   /// Store the validity state of the presentation in an internal map
117   /// \param theValue a viewer presentation
118   /// \param theValid a valid state
119   void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
120
121   /// Applies AIS context filters to the parameter list. The not approved presentations are
122   /// removed from the parameters.
123   /// \param theValues a list of presentations.
124   void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
125
126   /// Remove subshapes of compsolids if whole compsolid is present.
127   /// \param theValues a list of presentations.
128   void filterCompSolids(QList<ModuleBase_ViewerPrs>& theValues);
129
130 protected:
131   /// Reference to workshop
132   ModuleBase_IWorkshop* myWorkshop;
133   /// The widget is in validation mode: store is performed, restore is not
134   bool myIsInValidate;
135
136 private:
137   ObjectPtr myPresentedObject; /// back up of the filtered object
138   QList<ModuleBase_ViewerPrs> myValidPrs; /// cash of valid selection presentations
139   QList<ModuleBase_ViewerPrs> myInvalidPrs; /// cash of invalid selection presentations
140 };
141
142 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */