SHAPER  9.12.0
ModuleBase_WidgetValidated.h
1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef MODULEBASE_WIDGETVALIDATED_H_
21 #define MODULEBASE_WIDGETVALIDATED_H_
22 
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
25 
26 #include <GeomAPI_Shape.h>
27 #include <GeomAPI_AISObject.h>
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Attribute.h>
30 #include <ModelAPI_ResultBody.h>
31 
32 #include <SelectMgr_ListOfFilter.hxx>
33 #include <NCollection_DataMap.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <AIS_NListOfEntityOwner.hxx>
36 
37 #include <QList>
38 #include <QMap>
39 
40 class QWidget;
44 class ModelAPI_Validator;
45 class Config_WidgetAPI;
46 
47 //#define LIST_OF_VALID_PRS
48 
53 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
54 {
55  Q_OBJECT
56  public:
62  ModuleBase_IWorkshop* theWorkshop,
63  const Config_WidgetAPI* theData);
64  virtual ~ModuleBase_WidgetValidated();
65 
72  virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
73 
75  ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
76 
78  virtual void deactivate();
79 
81  void clearValidatedCash();
82 
85  bool isFilterActivated() const;
86 
90  virtual void selectionFilters(QIntList& theModuleSelectionFilters,
91  SelectMgr_ListOfFilter& theSelectionFilters);
92 
102  static void blockFeatureAttribute(const AttributePtr& theAttribute,
103  const FeaturePtr& theFeature,
104  const bool& theToBlock,
105  bool& isFlushesActived,
106  bool& isAttributeSetInitializedBlocked,
107  bool& isAttributeSendUpdatedBlocked);
108 
112  static bool isValidAttribute(const AttributePtr& theAttribute);
113 
114 protected:
118  virtual bool isValidInFilters(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
119 
126  bool isValidSelectionForAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
127  const AttributePtr& theAttribute);
128 
132  virtual AttributePtr attribute() const;
133 
138  virtual void storeAttributeValue(const AttributePtr& theAttribute);
139 
145  virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
146 
150  virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
151 
154  virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
155 
159  QList<std::shared_ptr<ModuleBase_ViewerPrs>> getFilteredSelected();
160 
169  virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
170  bool& isFlushesActived, bool& isAttributeSetInitializedBlocked,
171  bool& isAttributeSendUpdatedBlocked);
172 
173 protected:
178  bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
179 
183  void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
184 
185 private:
189  void filterPresentations(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
190 
193  void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
194 
195  void collectSubBodies(const ResultBodyPtr& theBody, AIS_NListOfEntityOwner& theList);
196 
197 protected:
202 
203 private:
204  ObjectPtr myPresentedObject;
205 #ifdef LIST_OF_VALID_PRS
207  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs;
208 
210  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs;
211 #else
212  // assume that one presentation selection presentation corresponds only one shape
213  NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myValidPrs;
214  NCollection_DataMap<TopoDS_Shape, std::shared_ptr<ModuleBase_ViewerPrs> > myInvalidPrs;
215 #endif
216 
218  ModuleBase_WidgetSelectorStore* myAttributeStore;
219 };
220 
221 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */
Provides low-level API for WidgetFactory for reading xml definitions of widgets.
Definition: Config_WidgetAPI.h:46
Allows to validate the attribute value of a feature or the whole feature.
Definition: ModelAPI_Validator.h:43
A class which provides access to selection.
Definition: ModuleBase_ISelection.h:44
Class which provides access to Workshop object services.
Definition: ModuleBase_IWorkshop.h:48
An abstract custom widget class.
Definition: ModuleBase_ModelWidget.h:60
virtual bool isValidSelectionCustom(const std::shared_ptr< ModuleBase_ViewerPrs > &theValue)
Checks if the selection presentation is valid in widget.
Definition: ModuleBase_ModelWidget.h:176
virtual void deactivate()
The method called when widget is deactivated.
Definition: ModuleBase_ModelWidget.cpp:303
virtual void selectionFilters(QIntList &theModuleSelectionFilters, SelectMgr_ListOfFilter &theSelectionFilters)
Appends into container of workshop selection filters.
Definition: ModuleBase_ModelWidget.cpp:124
Provides for an attribute backup of values.
Definition: ModuleBase_WidgetSelectorStore.h:37
Implementation of widget with validators and filters processing.
Definition: ModuleBase_WidgetValidated.h:54
ModuleBase_IWorkshop * myWorkshop
Reference to workshop.
Definition: ModuleBase_WidgetValidated.h:199
virtual bool setSelectionCustom(const std::shared_ptr< ModuleBase_ViewerPrs > &thePrs)=0
Fills the attribute with the value of the selected owner.
bool myIsInValidate
The widget is in validation mode: store is performed, restore is not.
Definition: ModuleBase_WidgetValidated.h:201