Salome HOME
Merge branch 'master' of salome:modules/shaper
[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_Definitions.h"
13
14 #include <ModelAPI_Object.h>
15 #include <ModelAPI_Attribute.h>
16 #include <GeomAPI_Shape.h>
17
18 class Config_WidgetAPI;
19 class QWidget;
20 class ModuleBase_IWorkshop;
21 class ModuleBase_ViewerPrs;
22 class ModelAPI_Result;
23
24 /**
25 * \ingroup GUI
26 * Implementation of widget for selection.
27 * This abstract interface is designed to be used for shape/multi shape selector widgets.
28 */
29 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
30 {
31 Q_OBJECT
32  public:
33
34   /// Constructor
35   /// \param theParent the parent object
36   /// \param theWorkshop instance of workshop interface
37   /// \param theData the widget configuation. The attribute of the model widget is obtained from
38   ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
39                             const Config_WidgetAPI* theData);
40
41   virtual ~ModuleBase_WidgetSelector();
42
43   /// Defines if it is supposed that the widget should interact with the viewer.
44   virtual bool isViewerSelector() { return true; }
45
46   /// Activate or deactivate selection and selection filters
47   /// \return true if the selection filter of the widget is activated in viewer context
48   virtual bool activateSelectionAndFilters(bool toActivate);
49
50   /// Checks the widget validity. By default, it returns true.
51   /// \param thePrs a selected presentation in the view
52   /// \return a boolean value
53   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
54
55   /// Fills the attribute with the value of the selected owner
56   /// \param thePrs a selected owner
57   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
58
59   /// The methiod called when widget is deactivated
60   virtual void deactivate();
61
62   /// Return the attribute values wrapped in a list of viewer presentations
63   /// \return a list of viewer presentations, which contains an attribute result and
64   /// a shape. If the attribute do not uses the shape, it is empty
65   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
66
67 protected slots:
68   /// Slot which is called on selection event
69   virtual void onSelectionChanged();
70
71 protected:
72   /// Emits model changed info, updates the current control by selection change
73   /// \param theDone a state whether the selection is set
74   virtual void updateOnSelectionChanged(const bool theDone);
75
76   /// Update focus after the attribute value change
77   // NDS: has body is temporary
78    virtual void updateFocus() {};
79
80   /// Retunrs a list of possible shape types
81   /// \return a list of shapes
82   QIntList getShapeTypes() const;
83
84   /// Retunrs a list of possible shape types
85   /// \return a list of shapes
86   virtual QIntList shapeTypes() const = 0;
87
88   /// Computes and updates name of selected object in the widget
89   // NDS: has body is temporary
90   virtual void updateSelectionName() {};
91
92   /// The methiod called when widget is activated
93   virtual void activateCustom();
94
95   /// Returns true if selected shape corresponds to requested shape types.
96   /// If the widget type of shapes contains the faces item, the result is converted
97   /// to construction result and the method returns true if there is at least one face
98   /// in the construction.
99   /// \param theShape a shape
100   /// \param theResult a selected result
101   bool acceptSubShape(const GeomShapePtr& theShape,
102                       const std::shared_ptr<ModelAPI_Result>& 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 std::shared_ptr<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   /// \param theWorkshop a workshop class instance
116   /// \return string value
117   static std::string generateName(const AttributePtr& theAttribute,
118                                   ModuleBase_IWorkshop* theWorkshop);
119 };
120
121 #endif