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