Salome HOME
Union of validator and filter functionalities.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetShapeSelector.h
4 // Created:     2 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef ModuleBase_WidgetShapeSelector_H
8 #define ModuleBase_WidgetShapeSelector_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_WidgetValidated.h"
12 #include "ModuleBase_ViewerFilters.h"
13 #include <ModuleBase_ViewerPrs.h>
14
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Attribute.h>
17 #include <GeomAPI_Shape.h>
18
19 #include <TopAbs_ShapeEnum.hxx>
20
21 #include <QStringList>
22
23 class Config_WidgetAPI;
24 class QWidget;
25 class QLabel;
26 class QLineEdit;
27 class QToolButton;
28 class ModuleBase_IWorkshop;
29
30 /**
31 * \ingroup GUI
32 * Implementation of widget for shapes selection.
33 * This type of widget can be defined in XML file with 'shape_selector' keyword.
34 * For example:
35 * \code
36 *   <shape_selector id="main_object" 
37 *    label="Main object" 
38 *    icon=":icons/cut_shape.png" 
39 *    tooltip="Select an object solid"
40 *    shape_types="solid shell"
41 *    concealment="true"
42 *  />
43 * \endcode
44 * It can use following parameters:
45 * - id - name of object attribute
46 * - label - content of widget's label
47 * - icon - icon which can be used instead label
48 * - tooltip - the witget's tooltip text
49 * - shape_types - list of shape types for selection. 
50 *       Possible values: face, vertex, wire, edge, shell, solid
51 * - object_types - types of selectable objects. 
52 *       For today it supports only one type "construction" 
53 *        which corresponds to ModelAPI_ResultConstruction object type
54 * - concealment - hide or not hide selected object after operation
55 */
56 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
57 {
58 Q_OBJECT
59  public:
60
61    /// Converts string value (name of shape type) to shape enum value
62    /// \param theType - string with shape type name
63    /// \return TopAbs_ShapeEnum value
64   static TopAbs_ShapeEnum shapeType(const QString& theType);
65
66   /// Constructor
67   /// \param theParent the parent object
68   /// \param theWorkshop instance of workshop interface
69   /// \param theData the widget configuation. The attribute of the model widget is obtained from
70   /// \param theParentId is Id of a parent of the current attribute
71   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
72                             const Config_WidgetAPI* theData, const std::string& theParentId);
73
74   virtual ~ModuleBase_WidgetShapeSelector();
75
76   virtual bool restoreValue();
77
78   /// Defines if it is supposed that the widget should interact with the viewer.
79   virtual bool isViewerSelector() { return true; }
80
81   /// Returns list of widget controls
82   /// \return a control list
83   virtual QList<QWidget*> getControls() const;
84
85   /// Set the given wrapped value to the current widget
86   /// This value should be processed in the widget according to the needs
87   /// \param theValue the wrapped widget value
88   virtual bool setSelectionPrs(ModuleBase_ViewerPrs theValue);
89
90   /// Fills the attribute with the value of the selected owner
91   /// \param theOwner a selected owner
92   virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
93
94   /// The methiod called when widget is deactivated
95   virtual void deactivate();
96
97   // Get the object from the attribute
98   /// \param theObj an object 
99   static ObjectPtr getObject(const AttributePtr& theAttribute);
100
101  public slots:
102
103   /// Activate or deactivate selection
104   void activateSelection(bool toActivate);
105
106  private slots:
107    /// Slot which is called on selection event
108   void onSelectionChanged();
109
110  protected:
111   /// Saves the internal parameters to the given feature
112   /// \return True in success
113   virtual bool storeValueCustom() const;
114
115   /// The methiod called when widget is activated
116   virtual void activateCustom();
117
118   /// Creates a backup of the current values of the attribute
119   /// It should be realized in the specific widget because of different
120   /// parameters of the current attribute
121   /// \param isBackup a boolean flag, if true, store values from the attribute
122   /// to backup, otherwise set the backed up values to the attribute
123   virtual void backupAttributeValue(const bool isBackup);
124
125   /// Computes and updates name of selected object in the widget
126   void updateSelectionName();
127
128   /// Raise panel which contains this widget
129   void raisePanel() const;
130
131   /// Returns true if selected shape corresponds to requested shape types
132   /// \param theShape a shape
133   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
134
135   // Set the given object as a value of the widget
136   /// \param theObj an object 
137   /// \param theShape a shape
138   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
139
140   // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
141   /// \return a shape
142   GeomShapePtr getShape() const;
143
144   /// Check the selected with validators if installed
145   /// \param theObj the object for checking
146   /// \param theShape the shape for checking
147   //virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
148
149   /// Clear attribute
150   void clearAttribute();
151
152   /// Store the values to the model attribute of the widget. It casts this attribute to
153   /// the specific type and set the given values
154   /// \param theSelectedObject an object
155   /// \param theShape a selected shape, which is used in the selection attribute
156   virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
157
158   //----------- Class members -------------
159   protected:
160   /// Label of the widget
161   QLabel* myLabel;
162
163   /// Input control of the widget
164   QLineEdit* myTextLine;
165
166   /// Reference to workshop
167   ModuleBase_IWorkshop* myWorkshop;
168
169   /// List of accepting shapes types
170   QStringList myShapeTypes;
171
172   /// Active/inactive flag
173   bool myIsActive;
174
175   /// backup parameters of the model attribute. The class processes three types of attribute:
176   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
177   /// values are reserved in the backup
178   /// An attribute object
179   ObjectPtr myObject;
180   /// An attribute shape
181   GeomShapePtr myShape;
182   /// A reference of the attribute
183   AttributePtr myRefAttribute;
184   /// A boolean value whether refAttr uses reference of object
185   bool myIsObject;
186 };
187
188 #endif