Salome HOME
Provide sub-shapes selection in sketcher
[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   virtual bool storeValue() const;
39
40   virtual bool restoreValue();
41
42   /// Returns the internal parent wiget control, that can be shown anywhere
43   /// \returns the widget
44   QWidget* getControl() const
45   {
46     return myContainer;
47   }
48
49   /// Returns list of widget controls
50   /// \return a control list
51   virtual QList<QWidget*> getControls() const;
52
53   ObjectPtr selectedFeature() const
54   {
55     return mySelectedObject;
56   }
57
58   /// Set the given wrapped value to the current widget
59   /// This value should be processed in the widget according to the needs
60   /// \param theValue the wrapped widget value
61   virtual bool setValue(ModuleBase_WidgetValue* theValue);
62
63
64   /// The methiod called when widget is activated
65   virtual void activate();
66
67   /// The methiod called when widget is deactivated
68   virtual void deactivate();
69
70
71  public slots:
72
73   /// Activate or deactivate selection
74   void activateSelection(bool toActivate);
75
76  private slots:
77   void onSelectionChanged();
78
79  protected:
80   void updateSelectionName();
81   void raisePanel() const;
82
83   /// Returns true if shape of given object corresponds to requested shape type
84   /// This method is called only in non sub-shapes selection mode
85   virtual bool acceptObjectShape(const ObjectPtr theObject) const;
86
87   /// Returns true if selected shape corresponds to requested shape types
88   /// This method is called only in sub-shapes selection mode
89   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
90
91   /// Returns true if selected object corresponds to requested Object type
92   /// Thid method is used in any selection mode
93   virtual bool acceptObjectType(const ObjectPtr theObject) const;
94
95
96   // Set the given object as a value of the widget
97   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
98
99   //----------- Class members -------------
100  protected:
101   QWidget* myContainer;
102   QLabel* myLabel;
103   QLineEdit* myTextLine;
104
105   ModuleBase_IWorkshop* myWorkshop;
106
107   ObjectPtr mySelectedObject;
108   std::shared_ptr<GeomAPI_Shape> myShape;
109
110   QStringList myShapeTypes;
111   QStringList myObjectTypes;
112
113   /// If true then local selector has to be activated in context
114   bool myUseSubShapes;
115
116   bool myIsActive;
117
118   Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
119 };
120
121 #endif