Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
[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   /// Constructor
62   /// \param theParent the parent object
63   /// \param theWorkshop instance of workshop interface
64   /// \param theData the widget configuation. The attribute of the model widget is obtained from
65   /// \param theParentId is Id of a parent of the current attribute
66   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
67                             const Config_WidgetAPI* theData, const std::string& theParentId);
68
69   virtual ~ModuleBase_WidgetShapeSelector();
70
71   virtual bool restoreValue();
72
73   /// Defines if it is supposed that the widget should interact with the viewer.
74   virtual bool isViewerSelector() { return true; }
75
76   /// Returns list of widget controls
77   /// \return a control list
78   virtual QList<QWidget*> getControls() const;
79
80   /// Fills the attribute with the value of the selected owner
81   /// \param theOwner a selected owner
82   virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
83
84   /// The methiod called when widget is deactivated
85   virtual void deactivate();
86
87  public slots:
88
89   /// Activate or deactivate selection
90   void activateSelection(bool toActivate);
91
92  private slots:
93    /// Slot which is called on selection event
94   void onSelectionChanged();
95
96  protected:
97   /// Saves the internal parameters to the given feature
98   /// \return True in success
99   virtual bool storeValueCustom() const;
100
101   /// The methiod called when widget is activated
102   virtual void activateCustom();
103
104   /// Creates a backup of the current values of the attribute
105   /// It should be realized in the specific widget because of different
106   /// parameters of the current attribute
107   virtual void storeAttributeValue();
108
109   /// Creates a backup of the current values of the attribute
110   /// It should be realized in the specific widget because of different
111   /// parameters of the current attribute
112   /// \param theValid a boolean flag, if restore happens for valid parameters
113   virtual void restoreAttributeValue(const bool theValid);
114
115   /// Computes and updates name of selected object in the widget
116   void updateSelectionName();
117
118   /// Raise panel which contains this widget
119   void raisePanel() const;
120
121   /// Returns true if selected shape corresponds to requested shape types
122   /// \param theShape a shape
123   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
124
125   /// Clear attribute
126   void clearAttribute();
127
128   /// Store the values to the model attribute of the widget. It casts this attribute to
129   /// the specific type and set the given values
130   /// \param theSelectedObject an object
131   /// \param theShape a selected shape, which is used in the selection attribute
132   /// \return true if it is succeed
133   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
134
135   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
136   /// \return a shape
137   virtual GeomShapePtr getShape() const;
138
139   /// Return the attribute values wrapped in a list of viewer presentations
140   /// \return a list of viewer presentations, which contains an attribute result and
141   /// a shape. If the attribute do not uses the shape, it is empty
142   QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
143
144   //----------- Class members -------------
145   protected:
146   /// Label of the widget
147   QLabel* myLabel;
148
149   /// Input control of the widget
150   QLineEdit* myTextLine;
151
152   /// Reference to workshop
153   ModuleBase_IWorkshop* myWorkshop;
154
155   /// List of accepting shapes types
156   QStringList myShapeTypes;
157
158   /// backup parameters of the model attribute. The class processes three types of attribute:
159   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
160   /// values are reserved in the backup
161   /// An attribute object
162   ObjectPtr myObject;
163   /// An attribute shape
164   GeomShapePtr myShape;
165   /// A reference of the attribute
166   AttributePtr myRefAttribute;
167   /// A boolean value whether refAttr uses reference of object
168   bool myIsObject;
169 };
170
171 #endif