1 // File: ModuleBase_WidgetShapeSelector.h
2 // Created: 2 June 2014
3 // Author: Vitaly Smetannikov
5 #ifndef ModuleBase_WidgetShapeSelector_H
6 #define ModuleBase_WidgetShapeSelector_H
8 #include "ModuleBase.h"
9 #include "ModuleBase_ModelWidget.h"
10 #include "ModuleBase_ViewerFilters.h"
12 #include <ModelAPI_Object.h>
13 #include <GeomAPI_Shape.h>
15 #include <TopAbs_ShapeEnum.hxx>
17 #include <QStringList>
19 class Config_WidgetAPI;
24 class ModuleBase_IWorkshop;
26 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
30 static TopAbs_ShapeEnum shapeType(const QString& theType);
32 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
33 const Config_WidgetAPI* theData, const std::string& theParentId);
35 virtual ~ModuleBase_WidgetShapeSelector();
37 /// Saves the internal parameters to the given feature
38 /// \param theObject a model feature to be changed
39 virtual bool storeValue() const;
41 virtual bool restoreValue();
43 virtual bool focusTo();
45 /// Returns the internal parent wiget control, that can be shown anywhere
46 /// \returns the widget
47 QWidget* getControl() const
52 /// Returns list of widget controls
53 /// \return a control list
54 virtual QList<QWidget*> getControls() const;
56 ObjectPtr selectedFeature() const
58 return mySelectedObject;
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);
67 /// The methiod called when widget is activated
68 virtual void activate();
70 /// The methiod called when widget is deactivated
71 virtual void deactivate();
76 /// Activate or deactivate selection
77 void activateSelection(bool toActivate);
80 void onSelectionChanged();
83 bool eventFilter(QObject* theObj, QEvent* theEvent);
85 void updateSelectionName();
86 void raisePanel() const;
88 /// Returns true if shape of given object corresponds to requested shape type
89 /// This method is called only in non sub-shapes selection mode
90 virtual bool acceptObjectShape(const ObjectPtr theObject) const;
92 /// Returns true if selected shape corresponds to requested shape types
93 /// This method is called only in sub-shapes selection mode
94 virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
96 /// Returns true if selected object corresponds to requested Object type
97 /// Thid method is used in any selection mode
98 virtual bool acceptObjectType(const ObjectPtr theObject) const;
101 // Set the given object as a value of the widget
102 void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
104 //----------- Class members -------------
106 QWidget* myContainer;
108 QLineEdit* myTextLine;
110 ModuleBase_IWorkshop* myWorkshop;
112 ObjectPtr mySelectedObject;
113 std::shared_ptr<GeomAPI_Shape> myShape;
115 QStringList myShapeTypes;
116 QStringList myObjectTypes;
118 /// If true then local selector has to be activated in context
123 Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;