1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MODULEBASE_WIDGETVALIDATED_H_
21 #define MODULEBASE_WIDGETVALIDATED_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_AISObject.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Attribute.h>
31 #include <SelectMgr_ListOfFilter.hxx>
32 #include <NCollection_DataMap.hxx>
33 #include <TopoDS_Shape.hxx>
39 class ModuleBase_IWorkshop;
40 class ModuleBase_ISelection;
41 class ModuleBase_WidgetSelectorStore;
42 class ModelAPI_Validator;
43 class Config_WidgetAPI;
45 //#define LIST_OF_VALID_PRS
49 * Implementation of widget with validators and filters processing.
51 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
56 /// \param theParent the parent object
57 /// \param theWorkshop a reference to workshop
58 /// \param theData the widget configuation. The attribute of the model widget is obtained from
59 ModuleBase_WidgetValidated(QWidget* theParent,
60 ModuleBase_IWorkshop* theWorkshop,
61 const Config_WidgetAPI* theData);
62 virtual ~ModuleBase_WidgetValidated();
64 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
65 /// next, the attribute's validating. It trying on the give selection to current attribute by
66 /// setting the value inside and calling validators. After this, the previous attribute value is
67 /// restored.The valid/invalid value is cashed.
68 /// \param theValue a selected presentation in the view
69 /// \return a boolean value
70 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
72 //! Returns data object by AIS
73 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
75 /// The method called when widget is deactivated
76 virtual void deactivate();
78 //! Clear all validated cash in the widget
79 void clearValidatedCash();
81 /// Returns true if the workshop validator filter has been already activated
82 /// \return boolean value
83 bool isFilterActivated() const;
85 /// Appends into container of workshop selection filters
86 /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
87 /// \param [out] selection filters
88 virtual void selectionFilters(QIntList& theModuleSelectionFilters,
89 SelectMgr_ListOfFilter& theSelectionFilters);
91 /// Block the model flush of update and intialization of attribute
92 /// \param theAttribute an attribute of blocking
93 /// \param theFeature a feature
94 /// \param theToBlock flag whether the model is blocked or unblocked
95 /// \param isFlushesActived 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 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
100 static void blockFeatureAttribute(const AttributePtr& theAttribute,
101 const FeaturePtr& theFeature,
102 const bool& theToBlock,
103 bool& isFlushesActived,
104 bool& isAttributeSetInitializedBlocked,
105 bool& isAttributeSendUpdatedBlocked);
107 /// Checks the current attibute in all attribute validators
108 /// \param theAttribute an attribute to be validated
109 /// \return true if all validators return that the attribute is valid
110 static bool isValidAttribute(const AttributePtr& theAttribute);
113 /// Checks whether all active viewer filters validate the presentation
114 /// \param thePrs a selected presentation in the view
115 /// \return a boolean value
116 virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
118 /// Checks all attribute validators returns valid. It tries on the given selection
119 /// to current attribute by setting the value inside and calling validators. After this,
120 /// the previous attribute value is restored.The valid/invalid value is cashed.
121 /// \param theValue a selected presentation in the view
122 /// \param theAttribute the attribute
123 /// \return a boolean value
124 bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
125 const AttributePtr& theAttribute);
127 /// Retunrs attribute, which should be validated. In default implementation,
128 /// this is an attribute of ID
129 /// \return an attribute
130 virtual AttributePtr attribute() const;
132 /// Creates a backup of the current values of the attribute
133 /// It should be realized in the specific widget because of different
134 /// parameters of the current attribute
135 /// \param theAttribute an attribute to be stored
136 virtual void storeAttributeValue(const AttributePtr& theAttribute);
138 /// Creates a backup of the current values of the attribute
139 /// It should be realized in the specific widget because of different
140 /// parameters of the current attribute
141 /// \param theAttribute an attribute to be restored
142 /// \param theValid a boolean flag, if restore happens for valid parameters
143 virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
145 /// Checks the widget validity. By default, it returns true.
146 /// \param thePrs a selected presentation in the view
147 /// \return a boolean value
148 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
150 /// Fills the attribute with the value of the selected owner
151 /// \param thePrs a selected owner
152 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
154 /// Returns a list of selected presentations in the viewer and object browser
155 /// The presentations from the object browser are filtered by the AIS context filters
156 /// \return a list of presentations
157 QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
159 /// Block the model flush of update and intialization of attribute
160 /// \param theAttribute an attribute of blocking
161 /// \param theToBlock flag whether the model is blocked or unblocked
162 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
163 /// to be used to restore flush state when unblocked
164 /// \param isAttributeSetInitializedBlocked out value if model is blocked
165 /// in value if model is unblocked to be used to restore previous state when unblocked
166 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
167 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
168 bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
169 bool& isAttributeSendUpdatedBlocked);
172 /// Gets the validity state of the presentation in an internal map.
173 /// Returns true if the valid state of value is stored
174 /// \param theValue a viewer presentation
175 /// \param theValid a valid state
176 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
178 /// Store the validity state of the presentation in an internal map
179 /// \param theValue a viewer presentation
180 /// \param theValid a valid state
181 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
184 /// Applies AIS context filters to the parameter list. The not approved presentations are
185 /// removed from the parameters.
186 /// \param theValues a list of presentations.
187 void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
189 /// Remove subshapes of compsolids if whole compsolid is present.
190 /// \param theValues a list of presentations.
191 void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
194 /// Reference to workshop
195 ModuleBase_IWorkshop* myWorkshop;
196 /// The widget is in validation mode: store is performed, restore is not
200 ObjectPtr myPresentedObject; /// back up of the filtered object
201 #ifdef LIST_OF_VALID_PRS
202 /// cash of valid selection presentations
203 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
205 /// cash of invalid selection presentations
206 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
208 // assume that one presentation selection presentation corresponds only one shape
209 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
210 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
213 /// store to backup parameters of the model
214 ModuleBase_WidgetSelectorStore* myAttributeStore;
217 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */