1 // Copyright (C) 2014-2019 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 ModuleBase_IWorkshop;
48 * An object which lets to start a Filters operation as
49 * a sub-operation of the current one.
51 class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget
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);
63 ~ModuleBase_FilterStarter() {}
66 /// A slot to launch filtering operation
67 void onFiltersLaunch();
70 /// Name of filtering feature
71 std::string myFeatureName;
74 ModuleBase_IWorkshop* myWorkshop;
78 class ModuleBase_WidgetSelectionFilter;
81 * A widget which reperesents a one filter item in filters list
82 * Also it includes filter GUI if it exists
84 class ModuleBase_FilterItem : public QWidget
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);
95 std::string filter() const { return myFilterID; }
97 /// Returns list of widgets which reperesent the current filter GUI
98 QList<ModuleBase_ModelWidget*> widgets() const {
103 /// The seignal is sent on deletion of the item
104 void deleteItem(ModuleBase_FilterItem* theItem);
106 /// The seignal is sent on reversing of the item
107 void reversedItem(ModuleBase_FilterItem* theItem);
110 /// A slot to process reverse button click
111 /// \param theCheck a current state of the button
112 void onReverse(bool theCheck);
114 /// A slot to process delete button click
118 /// A function which adds standard widgets of the item
119 void addItemRow(QWidget* theParent);
121 /// Current filter Id
122 std::string myFilterID;
125 FiltersFeaturePtr mySelection;
128 QToolButton* myRevBtn;
130 /// A list of sub-widgets
131 QList<ModuleBase_ModelWidget*> myWidgets;
136 * A widget for selection by filters
138 class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
144 /// \param theParent the parent object
145 /// \param theData the widget configuration. The attribute of the model widget is obtained from
146 /// a low-level API for reading xml definitions of widgets
147 ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
148 const Config_WidgetAPI* theData);
151 ~ModuleBase_WidgetSelectionFilter();
153 /// Returns list of widget controls
154 /// \return a control list
155 virtual QList<QWidget*> getControls() const;
157 /// It is called when user press Ok or OkPlus buttons in the parent property panel
158 /// By default this slot does nothing
159 virtual void onFeatureAccepted();
161 /// Returns current workshop
162 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
164 /// Returns a container widget for filter items
165 QWidget* filtersWidget() const { return myFiltersWgt; }
167 /// Returns error string
168 virtual QString getError(const bool theValueStateChecked = true) const;
171 /// Saves the internal parameters to the given feature (not ussed for this widget)
172 /// \return True in success
173 virtual bool storeValueCustom();
175 /// Restore value from attribute data to the widget's control (not ussed for this widget)
176 virtual bool restoreValueCustom();
179 /// Add a filter by Id in combo box
180 void onAddFilter(int);
182 /// Process deletion of a filter item
183 void onDeleteItem(ModuleBase_FilterItem* theItem);
185 /// Process reversion of a filter item
186 void onReverseItem(ModuleBase_FilterItem* theItem);
188 /// Process selection
191 /// Show only selected objects
192 void onShowOnly(bool theErase);
194 /// Process update of a filter item
195 void onObjectUpdated();
198 /// Update state of button State
199 void updateSelectBtn();
201 /// Update number of selected objects
202 void updateNumberSelected();
205 void clearCurrentSelection(bool toUpdate = false);
208 /// \param theShape a preview shape
209 void updatePreview(const TopoDS_Shape& theShape);
211 /// Call to redisplay the fiter feature
212 void redisplayFeature();
214 /// Add a filter by name
215 ModuleBase_FilterItem* onAddFilter(const std::string& theFilter);
218 ModuleBase_IWorkshop* myWorkshop;
220 QWidget* myFiltersWgt;
221 QVBoxLayout* myFiltersLayout;
223 QComboBox* myFiltersCombo;
224 QPushButton* mySelectBtn;
226 QCheckBox* myShowBtn;
228 /// Type of selection mode
231 /// List of non-used filters
232 std::list<std::string> myFilters;
234 /// List of used filters
235 std::list<std::string> myUseFilters;
237 /// Result of filtering
238 QList<ModuleBase_ViewerPrsPtr> myValues;
241 Handle(AIS_Shape) myPreview;
243 /// List of displayed objects before "Show only"
244 AIS_ListOfInteractive myListIO;
246 /// A Feature which will get result of filtering
247 FeaturePtr mySelectorFeature;
249 /// Attribute name which will get result of filtering
250 std::string mySelectorAttribute;