Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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_ModelWidget.h"
12 #include "ModuleBase_ViewerFilters.h"
13
14 #include <ModelAPI_Object.h>
15 #include <GeomAPI_Shape.h>
16
17 #include <TopAbs_ShapeEnum.hxx>
18
19 #include <QStringList>
20
21 class Config_WidgetAPI;
22 class QWidget;
23 class QLabel;
24 class QLineEdit;
25 class QToolButton;
26 class ModuleBase_IWorkshop;
27
28 /**
29 * \ingroup GUI
30 * Implementation of widget for shapes selection.
31 * This type of widget can be defined in XML file with 'shape_selector' keyword.
32 * For example:
33 * \code
34 *   <shape_selector id="main_object" 
35 *    label="Main object" 
36 *    icon=":icons/cut_shape.png" 
37 *    tooltip="Select an object solid"
38 *    shape_types="solid shell"
39 *    concealment="true"
40 *  />
41 * \endcode
42 * It can use following parameters:
43 * - id - name of object attribute
44 * - label - content of widget's label
45 * - icon - icon which can be used instead label
46 * - tooltip - the witget's tooltip text
47 * - shape_types - list of shape types for selection. 
48 *       Possible values: face, vertex, wire, edge, shell, solid
49 * - object_types - types of selectable objects. 
50 *       For today it supports only one type "construction" 
51 *        which corresponds to ModelAPI_ResultConstruction object type
52 * - concealment - hide or not hide selected object after operation
53 */
54 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
55 {
56 Q_OBJECT
57  public:
58
59    /// Converts string value (name of shape type) to shape enum value
60    /// \param theType - string with shape type name
61    /// \return TopAbs_ShapeEnum value
62   static TopAbs_ShapeEnum shapeType(const QString& theType);
63
64   /// Constructor
65   /// \param theParent the parent object
66   /// \param theWorkshop instance of workshop interface
67   /// \param theData the widget configuation. The attribute of the model widget is obtained from
68   /// \param theParentId is Id of a parent of the current attribute
69   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
70                             const Config_WidgetAPI* theData, const std::string& theParentId);
71
72   virtual ~ModuleBase_WidgetShapeSelector();
73
74   /// Saves the internal parameters to the given feature
75   virtual bool storeValue() const;
76
77   virtual bool restoreValue();
78
79   /// Defines if it is supposed that the widget should interact with the viewer.
80   virtual bool isViewerSelector() { return true; }
81
82   /// Returns the internal parent wiget control, that can be shown anywhere
83   /// \returns the widget
84   QWidget* getControl() const
85   {
86     return myContainer;
87   }
88
89   /// Returns list of widget controls
90   /// \return a control list
91   virtual QList<QWidget*> getControls() const;
92
93   /// Returns currently selected data object
94   ObjectPtr selectedFeature() const
95   {
96     return mySelectedObject;
97   }
98
99   /// Set the given wrapped value to the current widget
100   /// This value should be processed in the widget according to the needs
101   /// \param theValue the wrapped widget value
102   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
103
104
105   /// The methiod called when widget is activated
106   virtual void activate();
107
108   /// The methiod called when widget is deactivated
109   virtual void deactivate();
110
111
112  public slots:
113
114   /// Activate or deactivate selection
115   void activateSelection(bool toActivate);
116
117  private slots:
118    /// Slot which is called on selection event
119   void onSelectionChanged();
120
121  protected:
122    /// Computes and updates name of selected object in the widget
123   void updateSelectionName();
124
125   /// Raise panel which contains this widget
126   void raisePanel() const;
127
128   /// Returns true if selected shape corresponds to requested shape types
129   /// \param theShape a shape
130   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
131
132   /// Returns true if selected object corresponds to requested Object type
133   /// Thid method is used in any selection mode
134   /// \param theObject an object 
135   virtual bool acceptObjectType(const ObjectPtr theObject) const;
136
137
138   // Set the given object as a value of the widget
139   /// \param theObj an object 
140   /// \param theShape a shape
141   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
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   //----------- Class members -------------
152  protected:
153
154    /// Container of the widget's control
155   QWidget* myContainer;
156
157   /// Label of the widget
158   QLabel* myLabel;
159
160   /// Input control of the widget
161   QLineEdit* myTextLine;
162
163   /// Reference to workshop
164   ModuleBase_IWorkshop* myWorkshop;
165
166   /// Pointer to selected object
167   ObjectPtr mySelectedObject;
168
169   /// Pointer to selected shape
170   GeomShapePtr myShape;
171
172   /// List of accepting shapes types
173   QStringList myShapeTypes;
174
175   /// List of accepting object types
176   QStringList myObjectTypes;
177
178   /// Active/inactive flag
179   bool myIsActive;
180
181   /// Filter by objects types
182   Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
183 };
184
185 #endif