Salome HOME
Shape plane filter should process shapes of objects selected in object browser.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetSelector.h
4 // Created:     19 June 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef ModuleBase_WidgetSelector_H
8 #define ModuleBase_WidgetSelector_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_WidgetValidated.h"
12 #include <ModuleBase_ViewerPrs.h>
13 #include "ModuleBase_Definitions.h"
14
15 #include <ModelAPI_Object.h>
16 #include <GeomAPI_Shape.h>
17
18 class Config_WidgetAPI;
19 class QWidget;
20 class ModuleBase_IWorkshop;
21
22 /**
23 * \ingroup GUI
24 * Implementation of widget for selection.
25 * This abstract interface is designed to be used for shape/multi shape selector widgets.
26 */
27 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
28 {
29 Q_OBJECT
30  public:
31
32   /// Constructor
33   /// \param theParent the parent object
34   /// \param theWorkshop instance of workshop interface
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_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
38                             const Config_WidgetAPI* theData, const std::string& theParentId);
39
40   virtual ~ModuleBase_WidgetSelector();
41
42   /// Defines if it is supposed that the widget should interact with the viewer.
43   virtual bool isViewerSelector() { return true; }
44
45   /// Checks the widget validity. By default, it returns true.
46   /// \param theValue a selected presentation in the view
47   /// \return a boolean value
48   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
49
50   /// Fills the attribute with the value of the selected owner
51   /// \param theOwner a selected owner
52   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
53
54   /// The methiod called when widget is deactivated
55   virtual void deactivate();
56
57   //TODO: nds stabilization hotfix
58   virtual void disconnectSignals();
59
60 protected:
61   /// Activate or deactivate selection
62   void activateSelection(bool toActivate);
63
64  private slots:
65    /// Slot which is called on selection event
66   void onSelectionChanged();
67
68  protected:
69   /// Set an empty value to attribute
70   virtual void clearAttribute() = 0;
71
72   // Update focus after the attribute value change
73   virtual void updateFocus() = 0;
74
75   /// Return the attribute values wrapped in a list of viewer presentations
76   /// \return a list of viewer presentations, which contains an attribute result and
77   /// a shape. If the attribute do not uses the shape, it is empty
78   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const = 0;
79
80   /// Retunrs a list of possible shape types
81   /// \return a list of shapes
82   virtual QIntList getShapeTypes() const = 0;
83
84   /// Computes and updates name of selected object in the widget
85   virtual void updateSelectionName() = 0;
86
87   /// Store the values to the model attribute of the widget. It casts this attribute to
88   /// the specific type and set the given values
89   /// \param theSelectedObject an object
90   /// \param theShape a selected shape, which is used in the selection attribute
91   /// \return true if it is succeed
92   virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
93
94    /// The methiod called when widget is activated
95   virtual void activateCustom();
96
97   /// Returns true if selected shape corresponds to requested shape types.
98   /// If the widget type of shapes contains the faces item, the result is converted
99   /// to construction result and the method returns true if there is at least one face
100   /// in the construction.
101   /// \param theShape a shape
102   /// \param theResult a selected result
103   bool acceptSubShape(const GeomShapePtr& theShape, const ResultPtr& theResult) const;
104
105   /// Return an object and geom shape by the viewer presentation
106   /// \param thePrs a selection
107   /// \param theObject an output object
108   /// \param theShape a shape of the selection
109   virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
110                                 ObjectPtr& theObject,
111                                 GeomShapePtr& theShape);
112
113   //----------- Class members -------------
114 };
115
116 #endif