Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[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 <ModelAPI_Object.h>
16
17 #include <SelectMgr_ListOfFilter.hxx>
18
19 class QWidget;
20 class ModuleBase_IWorkshop;
21 class ModuleBase_ISelection;
22 class Config_WidgetAPI;
23 class Handle_SelectMgr_EntityOwner;
24
25 /**
26 * \ingroup GUI
27 * Implementation of widget with validators and filters processing.
28 */
29 class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidget
30 {
31   Q_OBJECT
32  public:
33   /// Constructor
34   /// \param theParent the parent object
35   /// \param theData the widget configuation. The attribute of the model widget is obtained from
36   /// \param theParentId is Id of a parent of the current attribute
37   ModuleBase_WidgetValidated(QWidget* theParent,
38                              const Config_WidgetAPI* theData,
39                              const std::string& theParentId);
40   virtual ~ModuleBase_WidgetValidated();
41
42   /// Checks all widget validator if the owner is valid
43   /// \param theOwner a selected owner in the view
44   /// \return a boolean value
45   bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
46
47   /// Set the given wrapped value to the current widget
48   /// This value should be processed in the widget according to the needs
49   /// The method is called by the current operation to process the operation preselection.
50   /// It is redefined to check the value validity and if it is, fill the attribute with by value
51   /// \param theValue the wrapped widget value
52   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
53
54 protected:
55   /// Creates a backup of the current values of the attribute
56   /// It should be realized in the specific widget because of different
57   /// parameters of the current attribute
58   virtual void storeAttributeValue() = 0;
59
60   /// Creates a backup of the current values of the attribute
61   /// It should be realized in the specific widget because of different
62   /// parameters of the current attribute
63   /// \param theValid a boolean flag, if restore happens for valid parameters
64   virtual void restoreAttributeValue(const bool theValid) = 0;
65
66   /// Fills the attribute with the value of the selected owner
67   /// \param theOwner a selected owner
68   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0;
69
70   virtual void removePresentations() {};
71
72   /// Checks the current attibute in all attribute validators
73   // \return true if all validators return that the attribute is valid
74   bool isValidAttribute() const;
75
76   /// It obtains selection filters from the workshop and activates them in the active viewer
77   /// \param theWorkshop an active workshop
78   /// \param toActivate a flag about activation or deactivation the filters
79   virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
80
81   /// Returns a list of selected presentations. Firstly it is obtained from the viewer,
82   /// if there are not selected objects in the viewer, it get the selection from the object browser.
83   /// If the browser has selected objects, the viewer prs objects are created with only object
84   /// field of the presentation initialized. The widget should accept the selection in the object
85   /// browser at the same way as in the viewer.
86   /// \param theSelection a selection, where the selected objects and presentations are found
87   /// \return a list of presentations
88   QList<ModuleBase_ViewerPrs> getSelectedEntitiesOrObjects(ModuleBase_ISelection* theSelection) const;
89
90 };
91
92 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */