Salome HOME
ad3d3b857931ff08b2f62fdc6c82137295c7473f
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
1 // File:        ModuleBase_WidgetShapeSelector.h
2 // Created:     2 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #ifndef ModuleBase_WidgetShapeSelector_H
6 #define ModuleBase_WidgetShapeSelector_H
7
8 #include "ModuleBase.h"
9 #include "ModuleBase_ModelWidget.h"
10 #include "ModuleBase_ViewerFilters.h"
11
12 #include <ModelAPI_Object.h>
13 #include <GeomAPI_Shape.h>
14
15 #include <TopAbs_ShapeEnum.hxx>
16
17 #include <QStringList>
18
19 class Config_WidgetAPI;
20 class QWidget;
21 class QLabel;
22 class QLineEdit;
23 class QToolButton;
24 class ModuleBase_IWorkshop;
25
26 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
27 {
28 Q_OBJECT
29  public:
30   static TopAbs_ShapeEnum shapeType(const QString& theType);
31
32   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
33                             const Config_WidgetAPI* theData, const std::string& theParentId);
34
35   virtual ~ModuleBase_WidgetShapeSelector();
36
37   /// Saves the internal parameters to the given feature
38   /// \param theObject a model feature to be changed
39   virtual bool storeValue() const;
40
41   virtual bool restoreValue();
42
43   virtual bool focusTo();
44
45   /// Returns the internal parent wiget control, that can be shown anywhere
46   /// \returns the widget
47   QWidget* getControl() const
48   {
49     return myContainer;
50   }
51
52   /// Returns list of widget controls
53   /// \return a control list
54   virtual QList<QWidget*> getControls() const;
55
56   ObjectPtr selectedFeature() const
57   {
58     return mySelectedObject;
59   }
60
61   /// Set the given wrapped value to the current widget
62   /// This value should be processed in the widget according to the needs
63   /// \param theValue the wrapped widget value
64   virtual bool setValue(ModuleBase_WidgetValue* theValue);
65
66  public slots:
67
68   /// Activate or deactivate selection
69   void activateSelection(bool toActivate);
70
71  private slots:
72   void onSelectionChanged();
73
74  protected:
75   bool eventFilter(QObject* theObj, QEvent* theEvent);
76
77   void updateSelectionName();
78   void raisePanel() const;
79
80   /// Returns true if shape of given object corresponds to requested shape type
81   /// This method is called only in non sub-shapes selection mode
82   virtual bool acceptObjectShape(const ObjectPtr theObject) const;
83
84   /// Returns true if selected shape corresponds to requested shape types
85   /// This method is called only in sub-shapes selection mode
86   virtual bool acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const;
87
88   /// Returns true if selected object corresponds to requested Object type
89   /// Thid method is used in any selection mode
90   virtual bool acceptObjectType(const ObjectPtr theObject) const;
91
92
93   // Set the given object as a value of the widget
94   void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
95
96   //----------- Class members -------------
97  private:
98   QWidget* myContainer;
99   QLabel* myLabel;
100   QLineEdit* myTextLine;
101
102   ModuleBase_IWorkshop* myWorkshop;
103
104   ObjectPtr mySelectedObject;
105   boost::shared_ptr<GeomAPI_Shape> myShape;
106
107   QStringList myShapeTypes;
108   QStringList myObjectTypes;
109
110   /// If true then local selector has to be activated in context
111   bool myUseSubShapes;
112
113   bool myIsActive;
114
115   Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
116 };
117
118 #endif