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