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