Salome HOME
Issue #368 move constraint problem
[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 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
37 * It can be defined in XML file as following:
38 * \code
39 * <multi_selector id="group_list" 
40 *    tooltip="Select a set of objects" 
41 *    type_choice="Vertices Edges Faces Solids" /> 
42 * \endcode
43 * It uses folloing parameters:
44 * - id - is a name of corresponded attribute
45 * - tooltip - a tooltip for the widget
46 * - type_choice - list of expected shape types.
47 */
48 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
49 {
50   Q_OBJECT
51  public:
52   /// Constructor
53   /// \param theParent the parent object
54   /// \param theWorkshop instance of workshop interface
55   /// \param theData the widget configuation. The attribute of the model widget is obtained from
56   /// \param theParentId is Id of a parent of the current attribute
57   ModuleBase_WidgetMultiSelector(QWidget* theParent,
58                                  ModuleBase_IWorkshop* theWorkshop,
59                                  const Config_WidgetAPI* theData,
60                                  const std::string& theParentId);
61   virtual ~ModuleBase_WidgetMultiSelector();
62
63   /// Saves the internal parameters to the given feature
64   virtual bool storeValue() const;
65
66   virtual bool restoreValue();
67
68   /// Returns the internal parent wiget control, that can be shown anywhere
69   /// \returns the widget
70   QWidget* getControl() const;
71
72   /// Returns list of widget controls
73   /// \return a control list
74   virtual QList<QWidget*> getControls() const;
75
76   virtual bool eventFilter(QObject* , QEvent* );
77
78  public slots:
79   /// Activate or deactivate selection
80   void activateSelection(bool toActivate);
81
82   /// Slot is called on selection type changed
83   void onSelectionTypeChanged();
84
85   /// Slot is called on selection changed
86   void onSelectionChanged();
87
88 protected slots:
89   /// Slot for copy command in a list pop-up menu
90   void onCopyItem();
91
92   /// Slot is called on selection of list of selected items
93   void onListSelection();
94
95  protected:
96    /// Provide filtering of selected shapes
97    /// \param theShapesToFilter source list of shapes
98    /// \param theResult result list of shapes
99   void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
100                     NCollection_List<TopoDS_Shape>& theResult);
101
102   /// Set current shape type for selection
103   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
104
105   /// Start shape selection
106   void activateShapeSelection();
107
108  private:
109    /// Update selection list
110    void updateSelectionList(AttributeSelectionListPtr);
111
112    /// List control
113   QListWidget* myListControl;
114
115   /// Combobox of types
116   QComboBox* myTypeCombo;
117
118   /// Container
119   QWidget* myMainWidget;
120
121   //TODO: Move into the base of selectors
122   ModuleBase_IWorkshop* myWorkshop;
123
124   /// If true then local selector has to be activated in context
125   bool myIsActive;
126
127   /// \typedef GeomSelection provides correspondance between Result object and its shape
128   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
129
130   /// Variable of GeomSelection type
131   QList<GeomSelection> mySelection;
132
133   /// An action for pop-up menu in a list control
134   QAction* myCopyAction;
135 };
136
137 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */