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