1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetValidated.h
4 // Created: 12 Mar 2015
5 // Author: Natalia ERMOLAEVA
8 #ifndef MODULEBASE_WIDGETVALIDATED_H_
9 #define MODULEBASE_WIDGETVALIDATED_H_
11 #include <ModuleBase.h>
12 #include <ModuleBase_ModelWidget.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_AISObject.h>
16 #include <ModelAPI_Object.h>
18 #include <SelectMgr_ListOfFilter.hxx>
23 class ModuleBase_IWorkshop;
24 class ModuleBase_ISelection;
25 class ModelAPI_Validator;
26 class Config_WidgetAPI;
27 class Handle_SelectMgr_EntityOwner;
31 * Implementation of widget with validators and filters processing.
33 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
38 /// \param theParent the parent object
39 /// \param theData the widget configuation. The attribute of the model widget is obtained from
40 /// \param theParentId is Id of a parent of the current attribute
41 ModuleBase_WidgetValidated(QWidget* theParent,
42 ModuleBase_IWorkshop* theWorkshop,
43 const Config_WidgetAPI* theData,
44 const std::string& theParentId);
45 virtual ~ModuleBase_WidgetValidated();
47 /// Checks whether all active viewer filters validate the presentation
48 /// \param theWorkshop an active workshop
49 /// \param theValue a selected presentation in the view
50 /// \return a boolean value
51 bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
53 /// Checks all widget validator if the owner is valid
54 /// \param theValue a selected presentation in the view
55 /// \return a boolean value
56 bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
58 /// Set the given wrapped value to the current widget
59 /// This value should be processed in the widget according to the needs
60 /// The method is called by the current operation to process the operation preselection.
61 /// It is redefined to check the value validity and if it is, fill the attribute with by value
62 /// \param theValues the wrapped selection values
63 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
64 const bool theToValidate);
66 //! Returns data object by AIS
67 ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
70 /// Creates a backup of the current values of the attribute
71 /// It should be realized in the specific widget because of different
72 /// parameters of the current attribute
73 virtual void storeAttributeValue();
75 /// Creates a backup of the current values of the attribute
76 /// It should be realized in the specific widget because of different
77 /// parameters of the current attribute
78 /// \param theValid a boolean flag, if restore happens for valid parameters
79 virtual void restoreAttributeValue(const bool theValid);
81 /// Checks the widget validity. By default, it returns true.
82 /// \param theValue a selected presentation in the view
83 /// \return a boolean value
84 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
86 /// Fills the attribute with the value of the selected owner
87 /// \param theOwner a selected owner
88 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
90 /// Checks the current attibute in all attribute validators
91 // \return true if all validators return that the attribute is valid
92 bool isValidAttribute() const;
94 /// Returns true if the workshop validator filter has been already activated
95 /// \return boolean value
96 bool isFilterActivated() const;
98 /// It obtains selection filters from the workshop and activates them in the active viewer
99 /// \param theWorkshop an active workshop
100 /// \param toActivate a flag about activation or deactivation the filters
101 void activateFilters(const bool toActivate);
103 /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
104 /// \param theValue a viewer presentation
105 /// \param theValid a valid state
106 bool getValidState(const ModuleBase_ViewerPrs& theValue, bool& theValid);
108 /// Store the validity state of the presentation in an internal map
109 /// \param theValue a viewer presentation
110 /// \param theValid a valid state
111 void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
113 // Removes all presentations from internal maps.
114 void clearValidState();
116 /// Returns a list of selected presentations in the viewer and object browser
117 /// The presentations from the object browser are filtered by the AIS context filters
118 /// \return a list of presentations
119 QList<ModuleBase_ViewerPrs> getFilteredSelected();
121 /// Applies AIS context filters to the parameter list. The not approved presentations are
122 /// removed from the parameters.
123 /// \param theValues a list of presentations.
124 void filterPresentations(QList<ModuleBase_ViewerPrs>& theValues);
127 ModuleBase_IWorkshop* myWorkshop; /// Reference to workshop
128 bool myIsInValidate; // the widget is in validation mode: store is performed, restore is not
131 ObjectPtr myPresentedObject; /// back up of the filtered object
132 QList<ModuleBase_ViewerPrs> myValidPrs;
133 QList<ModuleBase_ViewerPrs> myInvalidPrs;
136 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */