Salome HOME
bf9cb955f6d144316d485a2ec6beb9d492195bec
[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
11 #include <ModelAPI_Object.h>
12 #include <GeomAPI_Shape.h>
13
14 #include <TopAbs_ShapeEnum.hxx>
15
16 #include <QStringList>
17 #include <QPalette>
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   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
31                             const Config_WidgetAPI* theData, const std::string& theParentId);
32
33   virtual ~ModuleBase_WidgetShapeSelector();
34
35   /// Saves the internal parameters to the given feature
36   /// \param theObject a model feature to be changed
37   virtual bool storeValue() const;
38
39   virtual bool restoreValue();
40
41   virtual bool focusTo();
42
43   /// Returns the internal parent wiget control, that can be shown anywhere
44   /// \returns the widget
45   QWidget* getControl() const
46   {
47     return myContainer;
48   }
49
50   /// Returns list of widget controls
51   /// \return a control list
52   virtual QList<QWidget*> getControls() const;
53
54   ObjectPtr selectedFeature() const
55   {
56     return mySelectedObject;
57   }
58
59   /// Set the given wrapped value to the current widget
60   /// This value should be processed in the widget according to the needs
61   /// \param theValue the wrapped widget value
62   virtual bool setValue(ModuleBase_WidgetValue* theValue);
63
64 public slots:
65
66   /// Activate or deactivate selection
67   void activateSelection(bool toActivate);
68
69 private slots:
70   void onSelectionChanged();
71
72 protected:
73   bool eventFilter(QObject* theObj, QEvent* theEvent);
74
75 private:
76   void updateSelectionName();
77   void raisePanel() const;
78   bool isAccepted(const ObjectPtr theObject) const;
79   bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
80
81   // Set the given object as a value of the widget
82   void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
83
84   static TopAbs_ShapeEnum shapeType(const QString& theType);
85
86   QWidget* myContainer;
87   QLabel* myLabel;
88   QLineEdit* myTextLine;
89   //QToolButton* myActivateBtn;
90
91   ModuleBase_IWorkshop* myWorkshop;
92
93   ObjectPtr mySelectedObject;
94   boost::shared_ptr<GeomAPI_Shape> myShape;
95
96   QStringList myShapeTypes;
97
98   /// If true then local selector has to be activated in context
99   bool myUseSubShapes;
100
101   QPalette myBasePalet;
102   QPalette myInactivePalet;
103
104   bool myIsActive;
105 };
106
107 #endif