Salome HOME
Create filter "Belongs To"
[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_Filter.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 class MODULEBASE_EXPORT ModuleBase_FilterStarter: public QWidget
47 {
48   Q_OBJECT
49 public:
50   ModuleBase_FilterStarter(const std::string& theFeature, QWidget* theParent,
51     ModuleBase_IWorkshop* theWorkshop);
52
53   ~ModuleBase_FilterStarter() {}
54
55 private slots:
56   void onFiltersLaunch();
57
58 private:
59   std::string myFeatureName;
60   ModuleBase_IWorkshop* myWorkshop;
61
62   QLabel* myFilterLbl;
63   QLabel* myModifyLbl;
64 };
65
66
67 class ModuleBase_WidgetSelectionFilter;
68
69 class ModuleBase_FilterItem : public QWidget
70 {
71   Q_OBJECT
72 public:
73   ModuleBase_FilterItem(const std::string& theFilter, ModuleBase_WidgetSelectionFilter* theParent);
74
75   std::string filter() const { return myFilterID; }
76
77   /// Returns list of widget controls
78   /// \return a control list
79   QList<QWidget*> getControls() const;
80
81   QList<ModuleBase_ModelWidget*> widgets() const {
82     return myWidgets;
83   }
84
85 signals:
86   void deleteItem(ModuleBase_FilterItem* theItem);
87   void reversedItem(ModuleBase_FilterItem* theItem);
88
89 private slots:
90   void onReverse(bool theCheck);
91   void onDelete();
92
93 private:
94   void addItemRow(QWidget* theParent);
95
96   std::string myFilterID;
97   FiltersFeaturePtr mySelection;
98   QToolButton* myRevBtn;
99   QList<ModuleBase_ModelWidget*> myWidgets;
100 };
101
102 class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget
103 {
104   Q_OBJECT
105 public:
106   ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
107     const Config_WidgetAPI* theData);
108
109   ~ModuleBase_WidgetSelectionFilter();
110
111   /// Returns list of widget controls
112   /// \return a control list
113   virtual QList<QWidget*> getControls() const;
114
115   /// It is called when user press Ok or OkPlus buttons in the parent property panel
116   /// By default this slot does nothing
117   virtual void onFeatureAccepted();
118
119   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
120
121   QWidget* filtersWidget() const { return myFiltersWgt; }
122
123 protected:
124   /// Saves the internal parameters to the given feature (not ussed for this widget)
125   /// \return True in success
126   virtual bool storeValueCustom();
127
128   /// Restore value from attribute data to the widget's control (not ussed for this widget)
129   virtual bool restoreValueCustom();
130
131 private slots:
132   void onAddFilter(int);
133   void onDeleteItem(ModuleBase_FilterItem* theItem);
134   void onReverseItem(ModuleBase_FilterItem* theItem);
135   void onSelect();
136   void onShowOnly(bool theErase);
137
138 private:
139   void updateSelectBtn();
140   void updateNumberSelected();
141   void clearCurrentSelection(bool toUpdate = false);
142   void updatePreview(const TopoDS_Shape& theShape);
143   void redisplayFeature();
144
145 private:
146   ModuleBase_IWorkshop* myWorkshop;
147
148   QWidget* myFiltersWgt;
149   QVBoxLayout* myFiltersLayout;
150
151   QComboBox* myFiltersCombo;
152   QPushButton* mySelectBtn;
153   QLabel* myNbLbl;
154   QCheckBox* myShowBtn;
155
156   int mySelectionType;
157   std::list<std::string> myFilters;
158   std::list<std::string> myUseFilters;
159
160   QList<ModuleBase_ViewerPrsPtr> myValues;
161   Handle(AIS_Shape) myPreview;
162
163   AIS_ListOfInteractive myListIO;
164
165   FeaturePtr mySelectorFeature;
166   std::string mySelectorAttribute;
167 };
168
169
170 #endif