]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetMultiSelector.h
Salome HOME
Merge remote-tracking branch 'origin/EDF_2019'
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
21 #define MODULEBASE_WIDGETMULTISELECTOR_H_
22
23 #include <ModuleBase.h>
24 #include <ModuleBase_WidgetSelector.h>
25
26 #include <GeomAPI_Shape.h>
27 #include <ModelAPI_Result.h>
28
29 #include <NCollection_List.hxx>
30 #include <TopoDS_Shape.hxx>
31
32 #include <QList>
33 #include <QString>
34 #include <QStringList>
35 #include <QPair>
36 #include <QMap>
37
38 class QWidget;
39 class QCheckBox;
40 //class QComboBox;
41 class ModuleBase_ListView;
42 class ModuleBase_IWorkshop;
43 class ModuleBase_ChoiceCtrl;
44 class ModuleBase_FilterStarter;
45
46 /**
47 * \ingroup GUI
48 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
49 * It can be defined in XML file as following:
50 * \code
51 * <multi_selector id="group_list" 
52 *    tooltip="Select a set of objects" 
53 *    shape_types="Vertices Edges Faces Solids" />
54 * \endcode
55 * It uses following parameters:
56 * - id - is a name of corresponded attribute
57 * - tooltip - a tooltip for the widget
58 * - shape_types - list of expected shape types.
59 */
60 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
61 {
62   Q_OBJECT
63  public:
64   /// Constructor
65   /// \param theParent the parent object
66   /// \param theWorkshop instance of workshop interface
67   /// \param theData the widget configuration. The attribute of the model widget is obtained from
68   ModuleBase_WidgetMultiSelector(QWidget* theParent,
69                                  ModuleBase_IWorkshop* theWorkshop,
70                                  const Config_WidgetAPI* theData);
71   virtual ~ModuleBase_WidgetMultiSelector();
72
73   /// Returns list of widget controls
74   /// \return a control list
75   virtual QList<QWidget*> getControls() const;
76
77   /// The methiod called when widget is deactivated
78   virtual void deactivate();
79
80   /// Update Undo/Redo actions state
81   virtual void updateAfterDeactivation();
82
83   /// Update Undo/Redo actions state
84   virtual void updateAfterActivation();
85
86   /// Set the given wrapped value to the current widget
87   /// This value should be processed in the widget according to the needs
88   /// \param theValues the wrapped selection values
89   /// \param theToValidate a validation of the values flag
90   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
91                             const bool theToValidate);
92
93   /// Returns values which should be highlighted when the whidget is active
94   /// \param theValues a list of presentations
95   virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
96
97   /// Returns true if the action can be processed. By default it is empty and returns false.
98   /// \param theActionType an action type
99   /// \param isActionEnabled if true, the enable state of the action
100   virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled);
101
102   /// Returns true if the event is processed. The default implementation is empty, returns false.
103   virtual bool processAction(ModuleBase_ActionType theActionType,
104                              const ActionParamPtr& theParam = ActionParamPtr());
105
106   /// Checks the widget validity. By default, it returns true.
107   /// \param thePrs a selected presentation in the view
108   /// \return a boolean value
109   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
110
111   /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list.
112   /// \param theActionType type of action. It can be ActionUndo or ActionRedo.
113   virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const;
114
115   /// The slot is called when user press Ok or OkPlus buttons in the parent property panel
116   virtual void onFeatureAccepted();
117
118   /// Returns True if data of its feature was modified during operation
119   virtual bool isModified() const;
120
121 public slots:
122   /// Slot is called on selection type changed
123   void onSelectionTypeChanged();
124
125 protected:
126   /// Returns true if envent is processed.
127   /// Redefined to process XML state about clear selection in neutral point
128   virtual bool processSelection();
129
130 protected slots:
131   /// Slot for delete command in a list pop-up menu
132   void onDeleteItem();
133
134   /// Slot is called on selection of list of selected items
135   void onListSelection();
136
137   void onListActivated();
138
139   void onSameTopology(bool theOn);
140
141   void onShowOnly(bool);
142
143 protected:
144   /// Returns true if the event is processed. The default implementation is empty, returns false.
145   virtual bool processDelete();
146
147   /// The methiod called when widget is activated
148   virtual void activateCustom();
149
150   /// Saves the internal parameters to the given feature
151   /// \return True in success
152   virtual bool storeValueCustom();
153
154   /// restire type of selection by feature attribute
155   virtual bool restoreValueCustom();
156
157   /// Creates an element of the attribute current selection if history is empty
158   virtual void appendFirstSelectionInHistory();
159
160   /// Create an element in the history that stores the current selection,
161   /// position in the history is incremented
162   void appendSelectionInHistory();
163
164   /// Clear list of stored selected items, reset current position into '-1'
165   void clearSelectedHistory();
166
167   /// Set the focus on the last item in  the list
168   virtual void updateFocus();
169
170   /// Computes and updates name of selected object in the widget
171   virtual void updateSelectionName();
172
173   /// Emits model changed info, updates the current control by selection change
174   /// \param theDone a state whether the selection is set
175   virtual void updateOnSelectionChanged(const bool theDone);
176
177   /// Retunrs a list of possible shape types
178   /// \return a list of shapes
179   virtual QIntList shapeTypes() const;
180
181   /// Set current shape type for selection
182   void setCurrentShapeType(const int theShapeType);
183
184   /// Return the attribute values wrapped in a list of viewer presentations
185   /// \return a list of viewer presentations, which contains an attribute result and
186   /// a shape. If the attribute do not uses the shape, it is empty
187   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
188
189   /// Fills the list control by the attribute values
190   void updateSelectionList();
191
192   /// Converts the XML defined type choice to the validator type
193   /// For example, the "Edges" is converted to "edge"
194   std::string validatorType(const QString& theType) const;
195
196   /// Clear selection in the viewer. The content of the widget is cleared also
197   void clearSelection();
198
199 protected:
200   /// Returns attribute indices selected in the widget selection list
201   /// \param theIndices a list of indices
202   void getSelectedAttributeIndices(std::set<int>& theIndices);
203
204   /// Gets the feature attribute and fill a list of viewer presentation for the attribute
205   /// indices. If the the container of indices is empty, it returns all objects.
206   /// \param theAttributeIds indices in attribute list to be returned
207   /// \param theValues the result presentations, filled with object and shape of an attribute item
208   void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
209                             QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) const;
210
211   /// Iterates throgh the model attribute list and remove elements which do not present in the list
212   /// \param theValues the wrapped selection values
213   /// \return true if at least one object is removed
214   virtual bool removeUnusedAttributeObjects(
215     QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
216
217   /// Converts viewer presentation selection list to objects and shapes map
218   /// \param theValues the wrapped selection values
219   /// \return selection list
220   std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
221                                           (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
222
223   /// Returns true if the object and shape present in the container
224   /// \param theObject a model object, a set of shapes is searched by it
225   /// \param theShape a shape to be in the set of the object shapes
226   /// \param theGeomSelection a map built on selection
227   /// \param theWorkshop a current workshop
228   /// \return boolean result
229   static bool findInSelection(const ObjectPtr& theObject,
230                             GeomShapePtr theShape,
231                             const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
232                             ModuleBase_IWorkshop* theWorkshop);
233
234 protected:
235   ModuleBase_ListView* myListView; ///< List control
236
237   bool myIsUseChoice; ///< A flag to store use_choice parameter state
238
239   QStringList myShapeTypes; ///< List of Shape types defined in XML
240
241   /// Control for types
242   ModuleBase_ChoiceCtrl* myTypeCtrl;
243
244   /// A flag to clear selection by click in empty place in the viewer
245   bool myIsNeutralPointClear;
246
247   /// A flag to block set selection perform if the method is in process
248   bool myIsSetSelectionBlocked;
249
250   /// A container of selected objects
251   QList<QList<std::shared_ptr<ModuleBase_ViewerPrs> > > mySelectedHistoryValues;
252
253   /// Position in a container of selected values
254   int myCurrentHistoryIndex;
255
256   bool myIsFirst;
257   std::string myDefMode;
258
259   QCheckBox* myGeomCheck;
260   ModuleBase_FilterStarter* myFiltersWgt;
261
262   QObjectPtrList myVisibleObjects;
263   QStringList myAllowedObjects;
264   QStringList myTmpAllowed;
265 };
266
267 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */