1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef MODULEBASE_WIDGETVALIDATED_H_
22 #define MODULEBASE_WIDGETVALIDATED_H_
24 #include <ModuleBase.h>
25 #include <ModuleBase_ModelWidget.h>
27 #include <GeomAPI_Shape.h>
28 #include <GeomAPI_AISObject.h>
29 #include <ModelAPI_Object.h>
30 #include <ModelAPI_Attribute.h>
32 #include <SelectMgr_ListOfFilter.hxx>
33 #include <NCollection_DataMap.hxx>
34 #include <TopoDS_Shape.hxx>
40 class ModuleBase_IWorkshop;
41 class ModuleBase_ISelection;
42 class ModuleBase_WidgetSelectorStore;
43 class ModelAPI_Validator;
44 class Config_WidgetAPI;
46 //#define LIST_OF_VALID_PRS
50 * Implementation of widget with validators and filters processing.
52 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
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();
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);
73 //! Returns data object by AIS
74 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
76 /// The method called when widget is deactivated
77 virtual void deactivate();
79 //! Clear all validated cash in the widget
80 void clearValidatedCash();
82 /// Returns true if the workshop validator filter has been already activated
83 /// \return boolean value
84 bool isFilterActivated() const;
86 /// Appends into container of workshop selection filters
87 /// \param [out] theModuleSelectionFilters module additional modes, -1 means all default modes
88 /// \param [out] selection filters
89 virtual void selectionFilters(QIntList& theModuleSelectionFilters,
90 SelectMgr_ListOfFilter& theSelectionFilters);
92 /// Block the model flush of update and intialization of attribute
93 /// \param theAttribute an attribute of blocking
94 /// \param theFeature a feature
95 /// \param theToBlock flag whether the model is blocked or unblocked
96 /// \param isFlushesActived 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 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
101 static void blockFeatureAttribute(const AttributePtr& theAttribute,
102 const FeaturePtr& theFeature,
103 const bool& theToBlock,
104 bool& isFlushesActived,
105 bool& isAttributeSetInitializedBlocked,
106 bool& isAttributeSendUpdatedBlocked);
108 /// Checks the current attibute in all attribute validators
109 /// \param theAttribute an attribute to be validated
110 /// \return true if all validators return that the attribute is valid
111 static bool isValidAttribute(const AttributePtr& theAttribute);
114 /// Checks whether all active viewer filters validate the presentation
115 /// \param thePrs a selected presentation in the view
116 /// \return a boolean value
117 virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
119 /// Checks all attribute validators returns valid. It tries on the given selection
120 /// to current attribute by setting the value inside and calling validators. After this,
121 /// the previous attribute value is restored.The valid/invalid value is cashed.
122 /// \param theValue a selected presentation in the view
123 /// \param theAttribute the attribute
124 /// \return a boolean value
125 bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
126 const AttributePtr& theAttribute);
128 /// Retunrs attribute, which should be validated. In default implementation,
129 /// this is an attribute of ID
130 /// \return an attribute
131 virtual AttributePtr attribute() const;
133 /// Creates a backup of the current values of the attribute
134 /// It should be realized in the specific widget because of different
135 /// parameters of the current attribute
136 /// \param theAttribute an attribute to be stored
137 virtual void storeAttributeValue(const AttributePtr& theAttribute);
139 /// Creates a backup of the current values of the attribute
140 /// It should be realized in the specific widget because of different
141 /// parameters of the current attribute
142 /// \param theAttribute an attribute to be restored
143 /// \param theValid a boolean flag, if restore happens for valid parameters
144 virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
146 /// Checks the widget validity. By default, it returns true.
147 /// \param thePrs a selected presentation in the view
148 /// \return a boolean value
149 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
151 /// Fills the attribute with the value of the selected owner
152 /// \param thePrs a selected owner
153 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
155 /// Returns a list of selected presentations in the viewer and object browser
156 /// The presentations from the object browser are filtered by the AIS context filters
157 /// \return a list of presentations
158 QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
160 /// Block the model flush of update and intialization of attribute
161 /// \param theAttribute an attribute of blocking
162 /// \param theToBlock flag whether the model is blocked or unblocked
163 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
164 /// to be used to restore flush state when unblocked
165 /// \param isAttributeSetInitializedBlocked out value if model is blocked
166 /// in value if model is unblocked to be used to restore previous state when unblocked
167 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
168 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
169 bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
170 bool& isAttributeSendUpdatedBlocked);
173 /// Gets the validity state of the presentation in an internal map.
174 /// Returns true if the valid state of value is stored
175 /// \param theValue a viewer presentation
176 /// \param theValid a valid state
177 bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
179 /// Store the validity state of the presentation in an internal map
180 /// \param theValue a viewer presentation
181 /// \param theValid a valid state
182 void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
185 /// Applies AIS context filters to the parameter list. The not approved presentations are
186 /// removed from the parameters.
187 /// \param theValues a list of presentations.
188 void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
190 /// Remove subshapes of compsolids if whole compsolid is present.
191 /// \param theValues a list of presentations.
192 void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
195 /// Reference to workshop
196 ModuleBase_IWorkshop* myWorkshop;
197 /// The widget is in validation mode: store is performed, restore is not
201 ObjectPtr myPresentedObject; /// back up of the filtered object
202 #ifdef LIST_OF_VALID_PRS
203 /// cash of valid selection presentations
204 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
206 /// cash of invalid selection presentations
207 QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
209 // assume that one presentation selection presentation corresponds only one shape
210 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
211 NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
214 /// store to backup parameters of the model
215 ModuleBase_WidgetSelectorStore* myAttributeStore;
218 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */