Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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_ModelWidget.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_ModelWidget
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   /// Saves the internal parameters to the given feature
65   virtual bool storeValue() const;
66
67   virtual bool restoreValue();
68
69   /// Returns the internal parent wiget control, that can be shown anywhere
70   /// \returns the widget
71   QWidget* getControl() const;
72
73   /// Returns list of widget controls
74   /// \return a control list
75   virtual QList<QWidget*> getControls() const;
76
77   virtual bool eventFilter(QObject* , QEvent* );
78
79  public slots:
80   /// Activate or deactivate selection
81   void activateSelection(bool toActivate);
82
83   /// Slot is called on selection type changed
84   void onSelectionTypeChanged();
85
86   /// Slot is called on selection changed
87   void onSelectionChanged();
88
89 protected slots:
90   /// Slot for copy command in a list pop-up menu
91   void onCopyItem();
92
93   /// Slot is called on selection of list of selected items
94   void onListSelection();
95
96  protected:
97    /// Provide filtering of selected shapes
98    /// \param theShapesToFilter source list of shapes
99    /// \param theResult result list of shapes
100   void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
101                     NCollection_List<TopoDS_Shape>& theResult);
102
103   /// Set current shape type for selection
104   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
105
106   /// Start shape selection
107   void activateShapeSelection();
108
109  private:
110    /// Update selection list
111    void updateSelectionList(AttributeSelectionListPtr);
112
113    /// List control
114   QListWidget* myListControl;
115
116   /// Combobox of types
117   QComboBox* myTypeCombo;
118
119   /// Container
120   QWidget* myMainWidget;
121
122   //TODO: Move into the base of selectors
123   ModuleBase_IWorkshop* myWorkshop;
124
125   /// If true then local selector has to be activated in context
126   bool myIsActive;
127
128   /// Provides correspondance between Result object and its shape
129   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
130
131   /// Variable of GeomSelection type
132   QList<GeomSelection> mySelection;
133
134   /// An action for pop-up menu in a list control
135   QAction* myCopyAction;
136 };
137
138 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */