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