Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // Copyright (C) 2014-2022  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_WidgetSelector_H
21 #define ModuleBase_WidgetSelector_H
22
23 #include "ModuleBase.h"
24 #include "ModuleBase_WidgetValidated.h"
25 #include "ModuleBase_Definitions.h"
26
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Attribute.h>
29 #include <GeomAPI_Shape.h>
30
31 class Config_WidgetAPI;
32 class QWidget;
33 class ModuleBase_IWorkshop;
34 class ModuleBase_ViewerPrs;
35 class ModelAPI_Result;
36
37 /**
38 * \ingroup GUI
39 * Implementation of widget for selection.
40 * This abstract interface is designed to be used for shape/multi shape selector widgets.
41 */
42 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
43 {
44 Q_OBJECT
45  public:
46
47   /// Constructor
48   /// \param theParent the parent object
49   /// \param theWorkshop instance of workshop interface
50   /// \param theData the widget configuation. The attribute of the model widget is obtained from
51   ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
52                             const Config_WidgetAPI* theData);
53
54   virtual ~ModuleBase_WidgetSelector();
55
56   /// Fills given container with selection modes if the widget has it
57   /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
58   /// \param [out] theModes a container of modes
59   virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
60
61   /// Defines if it is supposed that the widget should interact with the viewer.
62   virtual bool isViewerSelector() { return true; }
63
64   /// Activate or deactivate selection and selection filters
65   virtual void updateSelectionModesAndFilters(bool toActivate);
66
67   /// Checks the widget validity. By default, it returns true.
68   /// \param thePrs a selected presentation in the view
69   /// \return a boolean value
70   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
71
72   /// Fills the attribute with the value of the selected owner
73   /// \param thePrs a selected owner
74   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
75
76   /// The methiod called when widget is deactivated
77   virtual void deactivate();
78
79   /// Return the attribute values wrapped in a list of viewer presentations
80   /// \return a list of viewer presentations, which contains an attribute result and
81   /// a shape. If the attribute do not uses the shape, it is empty
82   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
83
84   virtual bool isWholeResultAllowed() const;
85
86 protected:
87   /// Returns true if envent is processed. The default implementation is empty, returns false.
88   virtual bool processSelection();
89
90   /// Emits model changed info, updates the current control by selection change
91   /// \param theDone a state whether the selection is set
92   virtual void updateOnSelectionChanged(const bool theDone);
93
94   /// Update focus after the attribute value change
95   // NDS: has body is temporary
96    virtual void updateFocus() {};
97
98   /// Retunrs a list of possible shape types
99   /// \return a list of shapes
100   QIntList getShapeTypes() const;
101
102   /// Retunrs a list of possible shape types
103   /// \return a list of shapes
104   virtual QIntList shapeTypes() const = 0;
105
106   /// Computes and updates name of selected object in the widget
107   // NDS: has body is temporary
108   virtual void updateSelectionName() {};
109
110   /// The methiod called when widget is activated
111   virtual void activateCustom();
112
113   /// Returns true if selected shape corresponds to requested shape types.
114   /// If the widget type of shapes contains the faces item, the result is converted
115   /// to construction result and the method returns true if there is at least one face
116   /// in the construction.
117   /// \param theShape a shape
118   /// \param theResult a selected result
119   bool acceptSubShape(const GeomShapePtr& theShape,
120                       const std::shared_ptr<ModelAPI_Result>& theResult) const;
121
122   /// Return an object and geom shape by the viewer presentation
123   /// \param thePrs a selection
124   /// \param theObject an output object
125   /// \param theShape a shape of the selection
126   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
127                                 ObjectPtr& theObject,
128                                 GeomShapePtr& theShape);
129
130 protected:
131   bool myIsPointsFiltering;
132 };
133
134 #endif