]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSelector.h
Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: selection processing...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetSelector.h
4 // Created:     19 June 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef ModuleBase_WidgetSelector_H
8 #define ModuleBase_WidgetSelector_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_WidgetValidated.h"
12 #include <ModuleBase_ViewerPrs.h>
13 #include "ModuleBase_Definitions.h"
14
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Attribute.h>
17 #include <GeomAPI_Shape.h>
18
19 class Config_WidgetAPI;
20 class QWidget;
21 class ModuleBase_IWorkshop;
22
23 /**
24 * \ingroup GUI
25 * Implementation of widget for selection.
26 * This abstract interface is designed to be used for shape/multi shape selector widgets.
27 */
28 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
29 {
30 Q_OBJECT
31  public:
32
33   /// Constructor
34   /// \param theParent the parent object
35   /// \param theWorkshop instance of workshop interface
36   /// \param theData the widget configuation. The attribute of the model widget is obtained from
37   ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
38                             const Config_WidgetAPI* theData);
39
40   virtual ~ModuleBase_WidgetSelector();
41
42   /// Defines if it is supposed that the widget should interact with the viewer.
43   virtual bool isViewerSelector() { return true; }
44
45   /// Activate or deactivate selection and selection filters
46   /// \return true if the selection filter of the widget is activated in viewer context
47   virtual bool activateSelectionAndFilters(bool toActivate);
48
49   /// Checks the widget validity. By default, it returns true.
50   /// \param thePrs a selected presentation in the view
51   /// \return a boolean value
52   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
53
54   /// Fills the attribute with the value of the selected owner
55   /// \param thePrs a selected owner
56   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
57
58   /// The methiod called when widget is deactivated
59   virtual void deactivate();
60
61 // NDS: protected is temporary
62 protected slots:
63   /// Slot which is called on selection event
64   // NDS: virtual is temporary
65   virtual void onSelectionChanged();
66
67  protected:
68   /// Update focus after the attribute value change
69   // NDS: has body is temporary
70    virtual void updateFocus() {};
71
72   /// Return the attribute values wrapped in a list of viewer presentations
73   /// \return a list of viewer presentations, which contains an attribute result and
74   /// a shape. If the attribute do not uses the shape, it is empty
75   // NDS: has body is temporary
76   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
77
78   /// Retunrs a list of possible shape types
79   /// \return a list of shapes
80   virtual QIntList getShapeTypes() const = 0;
81
82   /// Computes and updates name of selected object in the widget
83   // NDS: has body is temporary
84   virtual void updateSelectionName() {};
85
86   /// Store the values to the model attribute of the widget. It casts this attribute to
87   /// the specific type and set the given values
88   /// \param theSelectedObject an object
89   /// \param theShape a selected shape, which is used in the selection attribute
90   /// \return true if it is succeed
91   virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
92
93   /// The methiod called when widget is activated
94   virtual void activateCustom();
95
96   /// Returns true if selected shape corresponds to requested shape types.
97   /// If the widget type of shapes contains the faces item, the result is converted
98   /// to construction result and the method returns true if there is at least one face
99   /// in the construction.
100   /// \param theShape a shape
101   /// \param theResult a selected result
102   bool acceptSubShape(const GeomShapePtr& theShape, const ResultPtr& theResult) const;
103
104   /// Return an object and geom shape by the viewer presentation
105   /// \param thePrs a selection
106   /// \param theObject an output object
107   /// \param theShape a shape of the selection
108   virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
109                                 ObjectPtr& theObject,
110                                 GeomShapePtr& theShape);
111
112   //----------- Class members -------------
113   /// Returns a name in the next form: attribute_feature_name/attribute_id
114   /// \param theAttribute a model attribute
115   /// \return string value
116   static std::string generateName(const AttributePtr& theAttribite,
117                                   ModuleBase_IWorkshop* theWorkshop);
118 };
119
120 #endif