1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_WidgetSelectionFilter_H
21 #define ModuleBase_WidgetSelectionFilter_H
23 #include "ModuleBase.h"
24 #include "ModuleBase_ModelWidget.h"
25 #include "ModuleBase_ViewerPrs.h"
27 #include <ModelAPI_FiltersFeature.h>
29 #include <SelectMgr_IndexedMapOfOwner.hxx>
30 #include <AIS_Shape.hxx>
31 #include <AIS_ListOfInteractive.hxx>
44 class ModelAPI_Filter;
46 class ModuleBase_IWorkshop;
50 * An object which lets to start a Filters operation as
51 * a sub-operation of the current one.
53 class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget
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);
65 ~ModuleBase_FilterStarter() {}
68 /// A slot to launch filtering operation
69 void onFiltersLaunch();
72 /// Name of filtering feature
73 std::string myFeatureName;
76 ModuleBase_IWorkshop* myWorkshop;
80 class ModuleBase_WidgetSelectionFilter;
83 * A widget which reperesents a one filter item in filters list
84 * Also it includes filter GUI if it exists
86 class ModuleBase_FilterItem : public QWidget
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);
97 std::string filter() const { return myFilterID; }
99 /// Returns list of widgets which reperesent the current filter GUI
100 QList<ModuleBase_ModelWidget*> widgets() const {
105 /// The seignal is sent on deletion of the item
106 void deleteItem(ModuleBase_FilterItem* theItem);
108 /// The seignal is sent on reversing of the item
109 void reversedItem(ModuleBase_FilterItem* theItem);
112 /// A slot to process reverse button click
113 /// \param theCheck a current state of the button
114 void onReverse(bool theCheck);
116 /// A slot to process delete button click
120 /// A function which adds standard widgets of the item
121 void addItemRow(QWidget* theParent);
123 /// Current filter Id
124 std::string myFilterID;
127 FiltersFeaturePtr mySelection;
130 QToolButton* myRevBtn;
132 /// A list of sub-widgets
133 QList<ModuleBase_ModelWidget*> myWidgets;
138 * A widget for selection by filters
140 class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
144 static FeaturePtr SelectorFeature;
145 static std::string AttributeId;
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);
156 ~ModuleBase_WidgetSelectionFilter();
158 /// Returns list of widget controls
159 /// \return a control list
160 virtual QList<QWidget*> getControls() const;
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();
166 /// Returns current workshop
167 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
169 /// Returns a container widget for filter items
170 QWidget* filtersWidget() const { return myFiltersWgt; }
172 /// Returns error string
173 virtual QString getError(const bool theValueStateChecked = true) const;
176 /// Saves the internal parameters to the given feature (not ussed for this widget)
177 /// \return True in success
178 virtual bool storeValueCustom();
180 /// Restore value from attribute data to the widget's control (not ussed for this widget)
181 virtual bool restoreValueCustom();
184 /// Add a filter by Id in combo box
185 void onAddFilter(int);
187 /// Process deletion of a filter item
188 void onDeleteItem(ModuleBase_FilterItem* theItem);
190 /// Process reversion of a filter item
191 void onReverseItem(ModuleBase_FilterItem* theItem);
193 /// Process selection
196 /// Show only selected objects
197 void onShowOnly(bool theErase);
199 /// Process update of a filter item
200 void onObjectUpdated();
203 /// Update state of button State
204 void updateSelectBtn();
206 /// Update number of selected objects
207 void updateNumberSelected();
210 void clearCurrentSelection(bool toUpdate = false);
213 /// \param theShape a preview shape
214 void updatePreview(const TopoDS_Shape& theShape);
216 /// Call to redisplay the fiter feature
217 void redisplayFeature();
219 /// Add a filter by name
220 ModuleBase_FilterItem* onAddFilter(const std::string& theFilter);
222 /// Return currently created filter items
223 QList<ModuleBase_FilterItem*> itemsList() const;
225 /// Translate a string
226 QString translate(const std::string& theString) const;
228 /// Store translated names of filters and their instances
229 void storeFilters(const std::list<std::shared_ptr<ModelAPI_Filter> >& theFilters);
232 ModuleBase_IWorkshop* myWorkshop;
234 QWidget* myFiltersWgt;
235 QVBoxLayout* myFiltersLayout;
237 QComboBox* myFiltersCombo;
238 QPushButton* mySelectBtn;
240 QCheckBox* myShowBtn;
242 /// Type of selection mode
245 /// Result of filtering
246 QList<ModuleBase_ViewerPrsPtr> myValues;
249 Handle(AIS_Shape) myPreview;
251 /// List of displayed objects before "Show only"
252 AIS_ListOfInteractive myListIO;
254 /// A Feature which will get result of filtering
255 FeaturePtr mySelectorFeature;
257 /// Attribute name which will get result of filtering
258 std::string mySelectorAttribute;
260 /// Translated name and the corresponding filter
261 std::map<std::string, std::shared_ptr<ModelAPI_Filter> > myFilters;