Salome HOME
ac6f0ef926b51ee4c2c59ab693c28c49fee956f3
[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 class ModelAPI_Validator;
30 class GeomValidators_ShapeType;
31
32 /**
33 * \ingroup GUI
34 * Implementation of widget for shapes selection.
35 * This type of widget can be defined in XML file with 'shape_selector' keyword.
36 * For example:
37 * \code
38 *   <shape_selector id="main_object" 
39 *    label="Main object" 
40 *    icon=":icons/cut_shape.png" 
41 *    tooltip="Select an object solid"
42 *    shape_types="solid shell"
43 *    concealment="true"
44 *  />
45 * \endcode
46 * It can use following parameters:
47 * - id - name of object attribute
48 * - label - content of widget's label
49 * - icon - icon which can be used instead label
50 * - tooltip - the witget's tooltip text
51 * - shape_types - list of shape types for selection. 
52 *       Possible values: face, vertex, wire, edge, shell, solid
53 * - object_types - types of selectable objects. 
54 *       For today it supports only one type "construction" 
55 *        which corresponds to ModelAPI_ResultConstruction object type
56 * - concealment - hide or not hide selected object after operation
57 */
58 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
59 {
60 Q_OBJECT
61  public:
62
63   /// Constructor
64   /// \param theParent the parent object
65   /// \param theWorkshop instance of workshop interface
66   /// \param theData the widget configuation. The attribute of the model widget is obtained from
67   /// \param theParentId is Id of a parent of the current attribute
68   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
69                             const Config_WidgetAPI* theData, const std::string& theParentId);
70
71   virtual ~ModuleBase_WidgetShapeSelector();
72
73   virtual bool restoreValue();
74
75   /// Defines if it is supposed that the widget should interact with the viewer.
76   virtual bool isViewerSelector() { return true; }
77
78   /// Returns list of widget controls
79   /// \return a control list
80   virtual QList<QWidget*> getControls() const;
81
82   /// Fills the attribute with the value of the selected owner
83   /// \param theOwner a selected owner
84   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
85
86   /// The methiod called when widget is deactivated
87   virtual void deactivate();
88
89 protected:
90   /// Activate or deactivate selection
91   void activateSelection(bool toActivate);
92
93  private slots:
94    /// Slot which is called on selection event
95   void onSelectionChanged();
96
97  protected:
98   /// Saves the internal parameters to the given feature
99   /// \return True in success
100   virtual bool storeValueCustom() const;
101
102   /// The methiod called when widget is activated
103   virtual void activateCustom();
104
105   /// Creates a backup of the current values of the attribute
106   /// It should be realized in the specific widget because of different
107   /// parameters of the current attribute
108   virtual void storeAttributeValue();
109
110   /// Creates a backup of the current values of the attribute
111   /// It should be realized in the specific widget because of different
112   /// parameters of the current attribute
113   /// \param theValid a boolean flag, if restore happens for valid parameters
114   virtual void restoreAttributeValue(const bool theValid);
115
116   /// Puts additional validators to the given list. A separate validator is created for each of the
117   /// "type_choice" value
118   /// \param theValidators a list of validators
119   /// \param theArguments a list of validators arguments
120   virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
121                                 std::list<std::list<std::string> >& theArguments) const;
122
123   /// Computes and updates name of selected object in the widget
124   void updateSelectionName();
125
126   /// Raise panel which contains this widget
127   void raisePanel() const;
128
129   /// Returns true if selected shape corresponds to requested shape types
130   /// \param theShape a shape
131   bool acceptSubShape(const TopoDS_Shape& theShape) const;
132
133   /// Clear attribute
134   void clearAttribute();
135
136   /// Store the values to the model attribute of the widget. It casts this attribute to
137   /// the specific type and set the given values
138   /// \param theSelectedObject an object
139   /// \param theShape a selected shape, which is used in the selection attribute
140   /// \return true if it is succeed
141   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
142
143   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
144   /// \return a shape
145   virtual GeomShapePtr getShape() const;
146
147   /// Return the attribute values wrapped in a list of viewer presentations
148   /// \return a list of viewer presentations, which contains an attribute result and
149   /// a shape. If the attribute do not uses the shape, it is empty
150   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
151
152   //----------- Class members -------------
153   protected:
154   /// Label of the widget
155   QLabel* myLabel;
156
157   /// Input control of the widget
158   QLineEdit* myTextLine;
159
160   /// Reference to workshop
161   ModuleBase_IWorkshop* myWorkshop;
162
163   /// List of accepting shapes types
164   QStringList myShapeTypes;
165
166   /// backup parameters of the model attribute. The class processes three types of attribute:
167   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
168   /// values are reserved in the backup
169   /// An attribute object
170   ObjectPtr myObject;
171   /// An attribute shape
172   GeomShapePtr myShape;
173   /// A reference of the attribute
174   AttributePtr myRefAttribute;
175   /// A boolean value whether refAttr uses reference of object
176   bool myIsObject;
177
178   /// An instance of the "shape_type" validator. It is returns on validating in customValidator()
179   GeomValidators_ShapeType* myShapeValidator;
180 };
181
182 #endif