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