Salome HOME
ModuleBase_ViewerPrs is wrapped into shared_ptr: remove include of this class from...
[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 protected slots:
63   /// Slot which is called on selection event
64   virtual void onSelectionChanged();
65
66 protected:
67   /// Emits model changed info, updates the current control by selection change
68   /// \param theDone a state whether the selection is set
69   virtual void updateOnSelectionChanged(const bool theDone);
70
71   /// Update focus after the attribute value change
72   // NDS: has body is temporary
73    virtual void updateFocus() {};
74
75   /// Return the attribute values wrapped in a list of viewer presentations
76   /// \return a list of viewer presentations, which contains an attribute result and
77   /// a shape. If the attribute do not uses the shape, it is empty
78   // NDS: has body is temporary
79   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
80
81   /// Retunrs a list of possible shape types
82   /// \return a list of shapes
83   virtual QIntList getShapeTypes() const = 0;
84
85   /// Computes and updates name of selected object in the widget
86   // NDS: has body is temporary
87   virtual void updateSelectionName() {};
88
89   /// The methiod called when widget is activated
90   virtual void activateCustom();
91
92   /// Returns true if selected shape corresponds to requested shape types.
93   /// If the widget type of shapes contains the faces item, the result is converted
94   /// to construction result and the method returns true if there is at least one face
95   /// in the construction.
96   /// \param theShape a shape
97   /// \param theResult a selected result
98   bool acceptSubShape(const GeomShapePtr& theShape,
99                       const std::shared_ptr<ModelAPI_Result>& theResult) const;
100
101   /// Return an object and geom shape by the viewer presentation
102   /// \param thePrs a selection
103   /// \param theObject an output object
104   /// \param theShape a shape of the selection
105   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
106                                 ObjectPtr& theObject,
107                                 GeomShapePtr& theShape);
108
109   //----------- Class members -------------
110   /// Returns a name in the next form: attribute_feature_name/attribute_id
111   /// \param theAttribute a model attribute
112   /// \return string value
113   static std::string generateName(const AttributePtr& theAttribite,
114                                   ModuleBase_IWorkshop* theWorkshop);
115 };
116
117 #endif