Salome HOME
Fix for the issue #593: do not remove naming attribute, but use TNaming_Builder for...
[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 #include <QMap>
28
29 class QWidget;
30 class QListWidget;
31 class QComboBox;
32 class ModuleBase_IWorkshop;
33 class GeomValidators_ShapeType;
34 class QAction;
35
36
37 /**
38 * \ingroup GUI
39 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
40 * It can be defined in XML file as following:
41 * \code
42 * <multi_selector id="group_list" 
43 *    tooltip="Select a set of objects" 
44 *    type_choice="Vertices Edges Faces Solids" /> 
45 * \endcode
46 * It uses folloing parameters:
47 * - id - is a name of corresponded attribute
48 * - tooltip - a tooltip for the widget
49 * - type_choice - list of expected shape types.
50 */
51 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetValidated
52 {
53   Q_OBJECT
54  public:
55   /// Constructor
56   /// \param theParent the parent object
57   /// \param theWorkshop instance of workshop interface
58   /// \param theData the widget configuation. The attribute of the model widget is obtained from
59   /// \param theParentId is Id of a parent of the current attribute
60   ModuleBase_WidgetMultiSelector(QWidget* theParent,
61                                  ModuleBase_IWorkshop* theWorkshop,
62                                  const Config_WidgetAPI* theData,
63                                  const std::string& theParentId);
64   virtual ~ModuleBase_WidgetMultiSelector();
65
66   //TODO: nds stabilization hotfix
67   virtual void disconnectSignals();
68
69   virtual bool restoreValue();
70
71   /// Returns list of widget controls
72   /// \return a control list
73   virtual QList<QWidget*> getControls() const;
74
75   virtual bool eventFilter(QObject* , QEvent* );
76
77   /// The methiod called when widget is deactivated
78   virtual void deactivate();
79
80   /// Set the given wrapped value to the current widget
81   /// This value should be processed in the widget according to the needs
82   /// \param theValues the wrapped selection values
83   /// \param thePosition an index in the list of values, the values should be get from the index
84   virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
85
86   /// Fills the attribute with the value of the selected owner
87   /// \param theOwner a selected owner
88   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
89
90  public slots:
91   /// Slot is called on selection type changed
92   void onSelectionTypeChanged();
93
94   /// Slot is called on selection changed
95   virtual void onSelectionChanged();
96
97 protected slots:
98   /// Slot for copy command in a list pop-up menu
99   void onCopyItem();
100
101   /// Slot is called on selection of list of selected items
102   void onListSelection();
103
104  protected:
105   /// The methiod called when widget is activated
106   virtual void activateCustom();
107
108   /// Saves the internal parameters to the given feature
109   /// \return True in success
110   virtual bool storeValueCustom() const;
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   virtual void storeAttributeValue();
116
117   /// Creates a backup of the current values of the attribute
118   /// It should be realized in the specific widget because of different
119   /// parameters of the current attribute
120   /// \param theValid a boolean flag, if restore happens for valid parameters
121   virtual void restoreAttributeValue(const bool theValid);
122
123   /// Puts additional validators to the given list. A separate validator is created for each of the
124   /// "type_choice" value
125   /// \param theValidators a list of validators
126   /// \param theArguments a list of validators arguments
127   virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
128                                 std::list<std::list<std::string> >& theArguments) const;
129
130   /// Returns true if selected shape corresponds to requested shape types
131   /// \param theShape a shape
132   bool acceptSubShape(const TopoDS_Shape& theShape) const;
133
134   /// Set current shape type for selection
135   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
136
137   /// Start shape selection
138   /// \param isActivated a state whether the shape is activated or deactivated in selection
139   void activateShapeSelection(const bool isActivated);
140
141   /// Return the attribute values wrapped in a list of viewer presentations
142   /// \return a list of viewer presentations, which contains an attribute result and
143   /// a shape. If the attribute do not uses the shape, it is empty
144   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
145
146  protected:
147   /// Update selection list
148   void updateSelectionList(AttributeSelectionListPtr);
149
150   /// Converts the XML defined type choice to the validator type
151   /// For example, the "Edges" is converted to "edge"
152   std::string validatorType(const QString& theType) const;
153
154    /// List control
155   QListWidget* myListControl;
156
157   /// Combobox of types
158   QComboBox* myTypeCombo;
159
160   //TODO: Move into the base of selectors
161   ModuleBase_IWorkshop* myWorkshop;
162
163   /// Provides correspondance between Result object and its shape
164   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
165
166   /// An action for pop-up menu in a list control
167   QAction* myCopyAction;
168
169   /// backup parameters of the model attribute. The class processes three types of attribute:
170   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
171   /// values are reserved in the backup
172   /// Variable of selection type
173   std::string mySelectionType;
174
175   /// Variable of GeomSelection
176   QList<GeomSelection> mySelection;
177
178   /// An instance of the "type_choice" validator. It is returns on validating in customValidator()
179   GeomValidators_ShapeType* myShapeValidator;
180
181   //bool myIsUseChoice;
182 };
183
184 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */