]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetValidated.h
Salome HOME
Activation objects redesign.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef MODULEBASE_WIDGETVALIDATED_H_
22 #define MODULEBASE_WIDGETVALIDATED_H_
23
24 #include <ModuleBase.h>
25 #include <ModuleBase_ModelWidget.h>
26
27 #include <GeomAPI_Shape.h>
28 #include <GeomAPI_AISObject.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_Attribute.h>
31
32 #include <SelectMgr_ListOfFilter.hxx>
33 #include <NCollection_DataMap.hxx>
34 #include <TopoDS_Shape.hxx>
35
36 #include <QList>
37 #include <QMap>
38
39 class QWidget;
40 class ModuleBase_IWorkshop;
41 class ModuleBase_ISelection;
42 class ModuleBase_WidgetSelectorStore;
43 class ModelAPI_Validator;
44 class Config_WidgetAPI;
45
46 //#define LIST_OF_VALID_PRS
47
48 /**
49 * \ingroup GUI
50 * Implementation of widget with validators and filters processing.
51 */
52 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
53 {
54   Q_OBJECT
55  public:
56   /// Constructor
57   /// \param theParent the parent object
58   /// \param theWorkshop a reference to workshop
59   /// \param theData the widget configuation. The attribute of the model widget is obtained from
60   ModuleBase_WidgetValidated(QWidget* theParent,
61                              ModuleBase_IWorkshop* theWorkshop,
62                              const Config_WidgetAPI* theData);
63   virtual ~ModuleBase_WidgetValidated();
64
65   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
66   /// next, the attribute's validating. It trying on the give selection to current attribute by
67   /// setting the value inside and calling validators. After this, the previous attribute value is
68   /// restored.The valid/invalid value is cashed.
69   /// \param theValue a selected presentation in the view
70   /// \return a boolean value
71   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
72
73   //! Returns data object by AIS
74   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
75
76   /// The method called when widget is deactivated
77   virtual void deactivate();
78
79   //! Clear all validated cash in the widget
80   void clearValidatedCash();
81
82   /// Returns true if the workshop validator filter has been already activated
83   /// \return boolean value
84   bool isFilterActivated() const;
85
86   /// Appends into container of workshop selection filters
87   /// \param [out] selection filters
88   virtual void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
89
90   /// Block the model flush of update and intialization of attribute
91   /// \param theAttribute an attribute of blocking
92   /// \param theFeature a feature
93   /// \param theToBlock flag whether the model is blocked or unblocked
94   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
95   /// to be used to restore flush state when unblocked
96   /// \param isAttributeSetInitializedBlocked out value if model is blocked
97   /// in value if model is unblocked to be used to restore previous state when unblocked
98   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
99   static void blockFeatureAttribute(const AttributePtr& theAttribute,
100                                     const FeaturePtr& theFeature,
101                                     const bool& theToBlock,
102                                     bool& isFlushesActived,
103                                     bool& isAttributeSetInitializedBlocked,
104                                     bool& isAttributeSendUpdatedBlocked);
105
106   /// Checks the current attibute in all attribute validators
107   /// \param theAttribute an attribute to be validated
108   /// \return true if all validators return that the attribute is valid
109   static bool isValidAttribute(const AttributePtr& theAttribute);
110
111 protected:
112   /// Checks whether all active viewer filters validate the presentation
113   /// \param thePrs a selected presentation in the view
114   /// \return a boolean value
115   virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
116
117   /// Checks all attribute validators returns valid. It tries on the given selection
118   /// to current attribute by setting the value inside and calling validators. After this,
119   /// the previous attribute value is restored.The valid/invalid value is cashed.
120   /// \param theValue a selected presentation in the view
121   /// \param theAttribute the attribute
122   /// \return a boolean value
123   bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
124                                     const AttributePtr& theAttribute);
125
126   /// Retunrs attribute, which should be validated. In default implementation,
127   /// this is an attribute of ID
128   /// \return an attribute
129   virtual AttributePtr attribute() const;
130
131   /// Creates a backup of the current values of the attribute
132   /// It should be realized in the specific widget because of different
133   /// parameters of the current attribute
134   /// \param theAttribute an attribute to be stored
135   virtual void storeAttributeValue(const AttributePtr& theAttribute);
136
137   /// Creates a backup of the current values of the attribute
138   /// It should be realized in the specific widget because of different
139   /// parameters of the current attribute
140   /// \param theAttribute an attribute to be restored
141   /// \param theValid a boolean flag, if restore happens for valid parameters
142   virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
143
144   /// Checks the widget validity. By default, it returns true.
145   /// \param thePrs a selected presentation in the view
146   /// \return a boolean value
147   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
148
149   /// Fills the attribute with the value of the selected owner
150   /// \param thePrs a selected owner
151   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
152
153   /// Returns a list of selected presentations in the viewer and object browser
154   /// The presentations from the object browser are filtered by the AIS context filters
155   /// \return a list of presentations
156   QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
157
158   /// Block the model flush of update and intialization of attribute
159   /// \param theAttribute an attribute of blocking
160   /// \param theToBlock flag whether the model is blocked or unblocked
161   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
162   /// to be used to restore flush state when unblocked
163   /// \param isAttributeSetInitializedBlocked out value if model is blocked
164   /// in value if model is unblocked to be used to restore previous state when unblocked
165   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
166   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
167                               bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
168                               bool& isAttributeSendUpdatedBlocked);
169
170 protected:
171   /// Gets the validity state of the presentation in an internal map.
172   /// Returns true if the valid state of value is stored
173   /// \param theValue a viewer presentation
174   /// \param theValid a valid state
175   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
176
177   /// Store the validity state of the presentation in an internal map
178   /// \param theValue a viewer presentation
179   /// \param theValid a valid state
180   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
181
182 private:
183   /// Applies AIS context filters to the parameter list. The not approved presentations are
184   /// removed from the parameters.
185   /// \param theValues a list of presentations.
186   void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
187
188   /// Remove subshapes of compsolids if whole compsolid is present.
189   /// \param theValues a list of presentations.
190   void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
191
192 protected:
193   /// Reference to workshop
194   ModuleBase_IWorkshop* myWorkshop;
195   /// The widget is in validation mode: store is performed, restore is not
196   bool myIsInValidate;
197
198 private:
199   ObjectPtr myPresentedObject; /// back up of the filtered object
200 #ifdef LIST_OF_VALID_PRS
201   /// cash of valid selection presentations
202   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
203
204   /// cash of invalid selection presentations
205   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
206 #else
207   // assume that one presentation selection presentation corresponds only one shape
208   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
209   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
210 #endif
211
212   /// store to backup parameters of the model
213   ModuleBase_WidgetSelectorStore* myAttributeStore;
214 };
215
216 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */