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