]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetValidated.h
Salome HOME
Issue #1941 Split auxiliary line.
[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 #include <ModelAPI_Attribute.h>
18
19 #include <SelectMgr_ListOfFilter.hxx>
20 #include <NCollection_DataMap.hxx>
21 #include <TopoDS_Shape.hxx>
22
23 #include <QList>
24 #include <QMap>
25
26 class QWidget;
27 class ModuleBase_IWorkshop;
28 class ModuleBase_ISelection;
29 class ModuleBase_WidgetSelectorStore;
30 class ModelAPI_Validator;
31 class Config_WidgetAPI;
32
33 //#define LIST_OF_VALID_PRS
34
35 /**
36 * \ingroup GUI
37 * Implementation of widget with validators and filters processing.
38 */
39 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
40 {
41   Q_OBJECT
42  public:
43   /// Constructor
44   /// \param theParent the parent object
45   /// \param theWorkshop a reference to workshop
46   /// \param theData the widget configuation. The attribute of the model widget is obtained from
47   ModuleBase_WidgetValidated(QWidget* theParent,
48                              ModuleBase_IWorkshop* theWorkshop,
49                              const Config_WidgetAPI* theData);
50   virtual ~ModuleBase_WidgetValidated();
51
52   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
53   /// next, the attribute's validating. It trying on the give selection to current attribute by
54   /// setting the value inside and calling validators. After this, the previous attribute value is
55   /// restored.The valid/invalid value is cashed.
56   /// \param theValue a selected presentation in the view
57   /// \return a boolean value
58   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
59
60   //! Returns data object by AIS
61   ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
62
63   //! Clear all validated cash in the widget
64   void clearValidatedCash();
65
66   /// Returns true if the workshop validator filter has been already activated
67   /// \return boolean value
68   bool isFilterActivated() const;
69
70 protected:
71   /// Checks whether all active viewer filters validate the presentation
72   /// \param thePrs a selected presentation in the view
73   /// \return a boolean value
74   virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
75
76   /// Checks all attribute validators returns valid. It tries on the given selection
77   /// to current attribute by setting the value inside and calling validators. After this,
78   /// the previous attribute value is restored.The valid/invalid value is cashed.
79   /// \param theValue a selected presentation in the view
80   /// \param theAttribute the attribute
81   /// \return a boolean value
82   bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
83                                     const AttributePtr& theAttribute);
84
85   /// Retunrs attribute, which should be validated. In default implementation,
86   /// this is an attribute of ID
87   /// \return an attribute
88   virtual AttributePtr attribute() const;
89
90   /// Creates a backup of the current values of the attribute
91   /// It should be realized in the specific widget because of different
92   /// parameters of the current attribute
93   /// \param theAttribute an attribute to be stored
94   virtual void storeAttributeValue(const AttributePtr& theAttribute);
95
96   /// Creates a backup of the current values of the attribute
97   /// It should be realized in the specific widget because of different
98   /// parameters of the current attribute
99   /// \param theAttribute an attribute to be restored
100   /// \param theValid a boolean flag, if restore happens for valid parameters
101   virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
102
103   /// Checks the widget validity. By default, it returns true.
104   /// \param thePrs a selected presentation in the view
105   /// \return a boolean value
106   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
107
108   /// Fills the attribute with the value of the selected owner
109   /// \param thePrs a selected owner
110   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
111
112   /// Returns a list of selected presentations in the viewer and object browser
113   /// The presentations from the object browser are filtered by the AIS context filters
114   /// \return a list of presentations
115   QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
116
117   /// It obtains selection filters from the workshop and activates them in the active viewer
118   /// \param toActivate a flag about activation or deactivation the filters
119   /// \return true if the selection filter of the widget is activated in viewer context
120   bool activateFilters(const bool toActivate);
121
122   /// Block the model flush of update and intialization of attribute
123   /// \param theAttribute an attribute of blocking
124   /// \param theToBlock flag whether the model is blocked or unblocked
125   /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
126   /// to be used to restore flush state when unblocked
127   /// \param isAttributeSetInitializedBlocked out value if model is blocked
128   /// in value if model is unblocked to be used to restore previous state when unblocked
129   /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
130   virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
131                               bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
132                               bool& isAttributeSendUpdatedBlocked);
133
134 private:
135   /// Checks the current attibute in all attribute validators
136   /// \param theAttribute an attribute to be validated
137   /// \return true if all validators return that the attribute is valid
138   bool isValidAttribute(const AttributePtr& theAttribute) const;
139
140 protected:
141   /// Gets the validity state of the presentation in an internal map.
142   /// Returns true if the valid state of value is stored
143   /// \param theValue a viewer presentation
144   /// \param theValid a valid state
145   bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
146
147   /// Store the validity state of the presentation in an internal map
148   /// \param theValue a viewer presentation
149   /// \param theValid a valid state
150   void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
151
152 private:
153   /// Applies AIS context filters to the parameter list. The not approved presentations are
154   /// removed from the parameters.
155   /// \param theValues a list of presentations.
156   void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
157
158   /// Remove subshapes of compsolids if whole compsolid is present.
159   /// \param theValues a list of presentations.
160   void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
161
162 protected:
163   /// Reference to workshop
164   ModuleBase_IWorkshop* myWorkshop;
165   /// The widget is in validation mode: store is performed, restore is not
166   bool myIsInValidate;
167
168 private:
169   ObjectPtr myPresentedObject; /// back up of the filtered object
170 #ifdef LIST_OF_VALID_PRS
171   /// cash of valid selection presentations
172   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
173
174   /// cash of invalid selection presentations
175   QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
176 #else
177   // assume that one presentation selection presentation corresponds only one shape
178   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
179   NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
180 #endif
181
182   /// store to backup parameters of the model
183   ModuleBase_WidgetSelectorStore* myAttributeStore;
184 };
185
186 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */