Salome HOME
A separation of WidgetSelector class in order to unite the logic of shape/multi shape...
[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_WidgetSelector.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_WidgetSelector
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   virtual bool restoreValue();
67
68   /// Returns list of widget controls
69   /// \return a control list
70   virtual QList<QWidget*> getControls() const;
71
72   /// Set the given wrapped value to the current widget
73   /// This value should be processed in the widget according to the needs
74   /// \param theValues the wrapped selection values
75   virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
76
77   /// Checks the widget validity. By default, it returns true.
78   /// \param theValue a selected presentation in the view
79   /// \return a boolean value
80   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
81
82  public slots:
83   /// Slot is called on selection type changed
84   void onSelectionTypeChanged();
85
86 protected slots:
87   /// Slot for copy command in a list pop-up menu
88   void onCopyItem();
89
90   /// Slot is called on selection of list of selected items
91   void onListSelection();
92
93 protected:
94   /// Saves the internal parameters to the given feature
95   /// \return True in success
96   virtual bool storeValueCustom() const;
97
98   /// Creates a backup of the current values of the attribute
99   /// It should be realized in the specific widget because of different
100   /// parameters of the current attribute
101   virtual void storeAttributeValue();
102
103   /// Clear attribute
104   virtual void clearAttribute();
105
106   // Set the focus on the last item in  the list
107   virtual void updateFocus();
108
109   /// Computes and updates name of selected object in the widget
110   virtual void updateSelectionName();
111
112   /// Retunrs a list of possible shape types
113   /// \return a list of shapes
114   virtual QIntList getShapeTypes() const;
115
116   /// Append the values to the model attribute of the widget. It casts this attribute to
117   /// the specific type and set the given values
118   /// \param theSelectedObject an object
119   /// \param theShape a selected shape, which is used in the selection attribute
120   /// \return true if it is succeed
121   void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
122
123   /// Creates a backup of the current values of the attribute
124   /// It should be realized in the specific widget because of different
125   /// parameters of the current attribute
126   /// \param theValid a boolean flag, if restore happens for valid parameters
127   virtual void restoreAttributeValue(const bool theValid);
128
129   /// Set current shape type for selection
130   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
131
132   /// Return the attribute values wrapped in a list of viewer presentations
133   /// \return a list of viewer presentations, which contains an attribute result and
134   /// a shape. If the attribute do not uses the shape, it is empty
135   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
136
137   /// Update selection list
138   void updateSelectionList(AttributeSelectionListPtr);
139
140   /// Converts the XML defined type choice to the validator type
141   /// For example, the "Edges" is converted to "edge"
142   std::string validatorType(const QString& theType) const;
143
144 protected:
145   /// List control
146   QListWidget* myListControl;
147
148   /// Combobox of types
149   QComboBox* myTypeCombo;
150
151   /// Provides correspondance between Result object and its shape
152   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
153
154   /// An action for pop-up menu in a list control
155   QAction* myCopyAction;
156
157   /// backup parameters of the model attribute. The class processes three types of attribute:
158   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
159   /// values are reserved in the backup
160   /// Variable of selection type
161   std::string mySelectionType;
162
163   /// Variable of GeomSelection
164   QList<GeomSelection> mySelection;
165
166   //bool myIsUseChoice;
167 };
168
169 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */