Salome HOME
033b260b4888c3912ea80ef46cb338fd3cee7407
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetMultiSelector.h
5  *
6  *  Created on: Oct 8, 2014
7  *      Author: sbh
8  */
9
10 #ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
11 #define MODULEBASE_WIDGETMULTISELECTOR_H_
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_WidgetValidated.h>
15
16 #include <GeomAPI_Shape.h>
17 #include <ModelAPI_Result.h>
18 #include <ModelAPI_AttributeSelectionList.h>
19
20 #include <NCollection_List.hxx>
21 #include <TopoDS_Shape.hxx>
22
23 #include <QList>
24 #include <QString>
25 #include <QStringList>
26 #include <QPair>
27
28 class QWidget;
29 class QListWidget;
30 class QComboBox;
31 class ModuleBase_IWorkshop;
32 class QAction;
33
34
35 /**
36 * \ingroup GUI
37 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
38 * It can be defined in XML file as following:
39 * \code
40 * <multi_selector id="group_list" 
41 *    tooltip="Select a set of objects" 
42 *    type_choice="Vertices Edges Faces Solids" /> 
43 * \endcode
44 * It uses folloing parameters:
45 * - id - is a name of corresponded attribute
46 * - tooltip - a tooltip for the widget
47 * - type_choice - list of expected shape types.
48 */
49 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetValidated
50 {
51   Q_OBJECT
52  public:
53   /// Constructor
54   /// \param theParent the parent object
55   /// \param theWorkshop instance of workshop interface
56   /// \param theData the widget configuation. The attribute of the model widget is obtained from
57   /// \param theParentId is Id of a parent of the current attribute
58   ModuleBase_WidgetMultiSelector(QWidget* theParent,
59                                  ModuleBase_IWorkshop* theWorkshop,
60                                  const Config_WidgetAPI* theData,
61                                  const std::string& theParentId);
62   virtual ~ModuleBase_WidgetMultiSelector();
63
64   virtual bool restoreValue();
65
66   /// Returns list of widget controls
67   /// \return a control list
68   virtual QList<QWidget*> getControls() const;
69
70   virtual bool eventFilter(QObject* , QEvent* );
71
72   /// The methiod called when widget is deactivated
73   virtual void deactivate();
74
75   /// Set the given wrapped value to the current widget
76   /// This value should be processed in the widget according to the needs
77   /// \param theValues the wrapped selection values
78   /// \param thePosition an index in the list of values, the values should be get from the index
79   virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
80
81   /// Fills the attribute with the value of the selected owner
82   /// \param theOwner a selected owner
83   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
84
85  public slots:
86   /// Slot is called on selection type changed
87   void onSelectionTypeChanged();
88
89   /// Slot is called on selection changed
90   virtual void onSelectionChanged();
91
92 protected slots:
93   /// Slot for copy command in a list pop-up menu
94   void onCopyItem();
95
96   /// Slot is called on selection of list of selected items
97   void onListSelection();
98
99  protected:
100   /// The methiod called when widget is activated
101   virtual void activateCustom();
102
103   /// Saves the internal parameters to the given feature
104   /// \return True in success
105   virtual bool storeValueCustom() const;
106
107   /// Creates a backup of the current values of the attribute
108   /// It should be realized in the specific widget because of different
109   /// parameters of the current attribute
110   virtual void storeAttributeValue();
111
112   /// Creates a backup of the current values of the attribute
113   /// It should be realized in the specific widget because of different
114   /// parameters of the current attribute
115   /// \param theValid a boolean flag, if restore happens for valid parameters
116   virtual void restoreAttributeValue(const bool theValid);
117
118   /// Set current shape type for selection
119   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
120
121   /// Start shape selection
122   /// \param isActivated a state whether the shape is activated or deactivated in selection
123   void activateShapeSelection(const bool isActivated);
124
125   /// Return the attribute values wrapped in a list of viewer presentations
126   /// \return a list of viewer presentations, which contains an attribute result and
127   /// a shape. If the attribute do not uses the shape, it is empty
128   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
129
130  protected:
131    /// Update selection list
132    void updateSelectionList(AttributeSelectionListPtr);
133
134    /// List control
135   QListWidget* myListControl;
136
137   /// Combobox of types
138   QComboBox* myTypeCombo;
139
140   //TODO: Move into the base of selectors
141   ModuleBase_IWorkshop* myWorkshop;
142
143   /// Provides correspondance between Result object and its shape
144   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
145
146   /// An action for pop-up menu in a list control
147   QAction* myCopyAction;
148
149   /// backup parameters of the model attribute. The class processes three types of attribute:
150   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
151   /// values are reserved in the backup
152   /// Variable of selection type
153   std::string mySelectionType;
154
155   /// Variable of GeomSelection
156   QList<GeomSelection> mySelection;
157 };
158
159 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */