Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // Copyright (C) 2014-2019  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 protected:
85   /// Returns true if envent is processed. The default implementation is empty, returns false.
86   virtual bool processSelection();
87
88   /// Emits model changed info, updates the current control by selection change
89   /// \param theDone a state whether the selection is set
90   virtual void updateOnSelectionChanged(const bool theDone);
91
92   /// Update focus after the attribute value change
93   // NDS: has body is temporary
94    virtual void updateFocus() {};
95
96   /// Retunrs a list of possible shape types
97   /// \return a list of shapes
98   QIntList getShapeTypes() const;
99
100   /// Retunrs a list of possible shape types
101   /// \return a list of shapes
102   virtual QIntList shapeTypes() const = 0;
103
104   /// Computes and updates name of selected object in the widget
105   // NDS: has body is temporary
106   virtual void updateSelectionName() {};
107
108   /// The methiod called when widget is activated
109   virtual void activateCustom();
110
111   /// Returns true if selected shape corresponds to requested shape types.
112   /// If the widget type of shapes contains the faces item, the result is converted
113   /// to construction result and the method returns true if there is at least one face
114   /// in the construction.
115   /// \param theShape a shape
116   /// \param theResult a selected result
117   bool acceptSubShape(const GeomShapePtr& theShape,
118                       const std::shared_ptr<ModelAPI_Result>& theResult) const;
119
120   /// Return an object and geom shape by the viewer presentation
121   /// \param thePrs a selection
122   /// \param theObject an output object
123   /// \param theShape a shape of the selection
124   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
125                                 ObjectPtr& theObject,
126                                 GeomShapePtr& theShape);
127
128 protected:
129   bool myIsPointsFiltering;
130 };
131
132 #endif