Salome HOME
Merge remote-tracking branch 'remotes/origin/Filters_Development_2'
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectionFilter.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_WidgetSelectionFilter_H
21 #define ModuleBase_WidgetSelectionFilter_H
22
23 #include "ModuleBase.h"
24 #include "ModuleBase_ModelWidget.h"
25 #include "ModuleBase_ViewerPrs.h"
26
27 #include <ModelAPI_FiltersFeature.h>
28
29 #include <SelectMgr_IndexedMapOfOwner.hxx>
30 #include <AIS_Shape.hxx>
31 #include <AIS_ListOfInteractive.hxx>
32
33 #include <QWidget>
34 #include <QList>
35
36 class QLabel;
37 class QComboBox;
38 class QGroupBox;
39 class QToolButton;
40 class QVBoxLayout;
41 class QPushButton;
42 class QCheckBox;
43
44 class ModuleBase_IWorkshop;
45
46 /**
47 * \ingroup GUI
48 * An object which lets to start a Filters operation as
49 * a sub-operation of the current one.
50 */
51 class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget
52 {
53   Q_OBJECT
54 public:
55   /// Constructor
56   /// \param theFeature a name of feature for filtering
57   /// \param theParent a parent widget which will get control after filtering
58   /// \param theWorkshop a pointer on a current workshop
59   ModuleBase_FilterStarter(const std::string& theFeature, QWidget* theParent,
60     ModuleBase_IWorkshop* theWorkshop);
61
62   /// Destructor
63   ~ModuleBase_FilterStarter() {}
64
65 private slots:
66   /// A slot to launch filtering operation
67   void onFiltersLaunch();
68
69 private:
70   /// Name of filtering feature
71   std::string myFeatureName;
72
73   /// A workshop
74   ModuleBase_IWorkshop* myWorkshop;
75 };
76
77
78 class ModuleBase_WidgetSelectionFilter;
79 /**
80 * \ingroup GUI
81 * A widget which reperesents a one filter item in filters list
82 * Also it includes filter GUI if it exists
83 */
84 class ModuleBase_FilterItem : public QWidget
85 {
86   Q_OBJECT
87 public:
88
89   /// Constructor
90   /// \param theFilter the filter ID
91   /// \param theParent a parent widget of ModuleBase_WidgetSelectionFilter class
92   ModuleBase_FilterItem(const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent);
93
94   /// Returns filter Id
95   std::string filter() const { return myFilterID; }
96
97   /// Returns list of widget controls
98   /// \return a control list
99   QList<QWidget*> getControls() const;
100
101   /// Returns list of widgets which reperesent the current filter GUI
102   QList<ModuleBase_ModelWidget*> widgets() const {
103     return myWidgets;
104   }
105
106 signals:
107   /// The seignal is sent on deletion of the item
108   void deleteItem(ModuleBase_FilterItem* theItem);
109
110   /// The seignal is sent on reversing of the item
111   void reversedItem(ModuleBase_FilterItem* theItem);
112
113 private slots:
114   /// A slot to process reverse button click
115   /// \param theCheck a current state of the button
116   void onReverse(bool theCheck);
117
118   /// A slot to process delete button click
119   void onDelete();
120
121 private:
122   /// A function which adds standard widgets of the item
123   void addItemRow(QWidget* theParent);
124
125   /// Current filter Id
126   std::string myFilterID;
127
128   /// Filters feature
129   FiltersFeaturePtr mySelection;
130
131   /// Reverce button
132   QToolButton* myRevBtn;
133
134   /// A list of sub-widgets
135   QList<ModuleBase_ModelWidget*> myWidgets;
136 };
137
138 /**
139 * \ingroup GUI
140 * A widget for selection by filters
141 */
142 class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
143 {
144   Q_OBJECT
145 public:
146
147   /// Constructor
148   /// \param theParent the parent object
149   /// \param theData the widget configuration. The attribute of the model widget is obtained from
150   /// a low-level API for reading xml definitions of widgets
151   ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
152     const Config_WidgetAPI* theData);
153
154   /// Destructor
155   ~ModuleBase_WidgetSelectionFilter();
156
157   /// Returns list of widget controls
158   /// \return a control list
159   virtual QList<QWidget*> getControls() const;
160
161   /// It is called when user press Ok or OkPlus buttons in the parent property panel
162   /// By default this slot does nothing
163   virtual void onFeatureAccepted();
164
165   /// Returns current workshop
166   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
167
168   /// Returns a container widget for filter items
169   QWidget* filtersWidget() const { return myFiltersWgt; }
170
171   /// Returns error string
172   virtual QString getError(const bool theValueStateChecked = true) const;
173
174 protected:
175   /// Saves the internal parameters to the given feature (not ussed for this widget)
176   /// \return True in success
177   virtual bool storeValueCustom();
178
179   /// Restore value from attribute data to the widget's control (not ussed for this widget)
180   virtual bool restoreValueCustom();
181
182 private slots:
183   /// Add a filter by Id in combo box
184   void onAddFilter(int);
185
186   /// Add a filter by name
187   void onAddFilter(const std::string& theFilter);
188
189   /// Process deletion of a filter item
190   void onDeleteItem(ModuleBase_FilterItem* theItem);
191
192   /// Process reversion of a filter item
193   void onReverseItem(ModuleBase_FilterItem* theItem);
194
195   /// Process selection
196   void onSelect();
197
198   /// Show only selected objects
199   void onShowOnly(bool theErase);
200
201   /// Process update of a filter item
202   void onObjectUpdated();
203
204 private:
205   /// Update state of button State
206   void updateSelectBtn();
207
208   /// Update number of selected objects
209   void updateNumberSelected();
210
211   /// Clear selection
212   void clearCurrentSelection(bool toUpdate = false);
213
214   /// Update preview
215   /// \param theShape a preview shape
216   void updatePreview(const TopoDS_Shape& theShape);
217
218   /// Call to redisplay the fiter feature
219   void redisplayFeature();
220
221 private:
222   ModuleBase_IWorkshop* myWorkshop;
223
224   QWidget* myFiltersWgt;
225   QVBoxLayout* myFiltersLayout;
226
227   QComboBox* myFiltersCombo;
228   QPushButton* mySelectBtn;
229   QLabel* myNbLbl;
230   QCheckBox* myShowBtn;
231
232   /// Type of selection mode
233   int mySelectionType;
234
235   /// List of non-used filters
236   std::list<std::string> myFilters;
237
238   /// List of used filters
239   std::list<std::string> myUseFilters;
240
241   /// Result of filtering
242   QList<ModuleBase_ViewerPrsPtr> myValues;
243
244   /// A preview shape
245   Handle(AIS_Shape) myPreview;
246
247   /// List of displayed objects before "Show only"
248   AIS_ListOfInteractive myListIO;
249
250   /// A Feature which will get result of filtering
251   FeaturePtr mySelectorFeature;
252
253   /// Attribute name which will get result of filtering
254   std::string mySelectorAttribute;
255 };
256
257
258 #endif