Salome HOME
Activation objects redesign.
[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   /// Fills given container with selection modes if the widget has it
58   /// \param theModes [out] a container of modes
59   /// \param isAdditional if true, the modes are combinated with the module ones
60   virtual void selectionModes(QIntList& theModes, bool& isAdditional);
61
62   /// Defines if it is supposed that the widget should interact with the viewer.
63   virtual bool isViewerSelector() { return true; }
64
65   /// Activate or deactivate selection and selection filters
66   virtual void activateSelectionAndFilters(bool toActivate);
67
68   /// Checks the widget validity. By default, it returns true.
69   /// \param thePrs a selected presentation in the view
70   /// \return a boolean value
71   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
72
73   /// Fills the attribute with the value of the selected owner
74   /// \param thePrs a selected owner
75   virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
76
77   /// The methiod called when widget is deactivated
78   virtual void deactivate();
79
80   /// Return the attribute values wrapped in a list of viewer presentations
81   /// \return a list of viewer presentations, which contains an attribute result and
82   /// a shape. If the attribute do not uses the shape, it is empty
83   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
84
85 protected:
86   /// Returns true if envent is processed. The default implementation is empty, returns false.
87   virtual bool processSelection();
88
89   /// Emits model changed info, updates the current control by selection change
90   /// \param theDone a state whether the selection is set
91   virtual void updateOnSelectionChanged(const bool theDone);
92
93   /// Update focus after the attribute value change
94   // NDS: has body is temporary
95    virtual void updateFocus() {};
96
97   /// Retunrs a list of possible shape types
98   /// \return a list of shapes
99   QIntList getShapeTypes() const;
100
101   /// Retunrs a list of possible shape types
102   /// \return a list of shapes
103   virtual QIntList shapeTypes() const = 0;
104
105   /// Computes and updates name of selected object in the widget
106   // NDS: has body is temporary
107   virtual void updateSelectionName() {};
108
109   /// The methiod called when widget is activated
110   virtual void activateCustom();
111
112   /// Returns true if selected shape corresponds to requested shape types.
113   /// If the widget type of shapes contains the faces item, the result is converted
114   /// to construction result and the method returns true if there is at least one face
115   /// in the construction.
116   /// \param theShape a shape
117   /// \param theResult a selected result
118   bool acceptSubShape(const GeomShapePtr& theShape,
119                       const std::shared_ptr<ModelAPI_Result>& theResult) const;
120
121   /// Return an object and geom shape by the viewer presentation
122   /// \param thePrs a selection
123   /// \param theObject an output object
124   /// \param theShape a shape of the selection
125   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
126                                 ObjectPtr& theObject,
127                                 GeomShapePtr& theShape);
128
129   //----------- Class members -------------
130   /// Returns a name in the next form: attribute_feature_name/attribute_id
131   /// \param theAttribute a model attribute
132   /// \param theWorkshop a workshop class instance
133   /// \return string value
134   static std::string generateName(const AttributePtr& theAttribute,
135                                   ModuleBase_IWorkshop* theWorkshop);
136 };
137
138 #endif