Salome HOME
Issue #265 Conflicting constraints after aborting of constraint creation
[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 * Implementation of widget for shapes selection.
30 * This type of widget can be defined in XML file with 'shape_selector' keyword.
31 * For example:
32 * \code
33 *   <shape_selector id="main_object" 
34 *    label="Main object" 
35 *    icon=":icons/cut_shape.png" 
36 *    tooltip="Select an object solid"
37 *    shape_types="solid shell"
38 *    concealment="true"
39 *  />
40 * \endcode
41 * It can use following parameters:
42 * - id - name of object attribute
43 * - label - content of widget's label
44 * - icon - icon which can be used instead label
45 * - tooltip - the witget's tooltip text
46 * - shape_types - list of shape types for selection. 
47 *       Possible values: face, vertex, wire, edge, shell, solid
48 * - object_types - types of selectable objects. 
49 *       For today it supports only one type "construction" 
50 *        which corresponds to ModelAPI_ResultConstruction object type
51 * - concealment - hide or not hide selected object after operation
52 */
53 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
54 {
55 Q_OBJECT
56  public:
57
58    /// Converts string value (name of shape type) to shape enum value
59    /// \param theType - string with shape type name
60    /// \return TopAbs_ShapeEnum value
61   static TopAbs_ShapeEnum shapeType(const QString& theType);
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   /// Saves the internal parameters to the given feature
74   virtual bool storeValue() const;
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 the internal parent wiget control, that can be shown anywhere
82   /// \returns the widget
83   QWidget* getControl() const
84   {
85     return myContainer;
86   }
87
88   /// Returns list of widget controls
89   /// \return a control list
90   virtual QList<QWidget*> getControls() const;
91
92   /// Returns currently selected data object
93   ObjectPtr selectedFeature() const
94   {
95     return mySelectedObject;
96   }
97
98   /// Set the given wrapped value to the current widget
99   /// This value should be processed in the widget according to the needs
100   /// \param theValue the wrapped widget value
101   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
102
103
104   /// The methiod called when widget is activated
105   virtual void activate();
106
107   /// The methiod called when widget is deactivated
108   virtual void deactivate();
109
110
111  public slots:
112
113   /// Activate or deactivate selection
114   void activateSelection(bool toActivate);
115
116  private slots:
117    /// Slot which is called on selection event
118   void onSelectionChanged();
119
120  protected:
121    /// Computes and updates name of selected object in the widget
122   void updateSelectionName();
123
124   /// Raise panel which contains this widget
125   void raisePanel() const;
126
127   /// Returns true if selected shape corresponds to requested shape types
128   /// \param theShape a shape
129   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
130
131   /// Returns true if selected object corresponds to requested Object type
132   /// Thid method is used in any selection mode
133   /// \param theObject an object 
134   virtual bool acceptObjectType(const ObjectPtr theObject) const;
135
136
137   // Set the given object as a value of the widget
138   /// \param theObj an object 
139   /// \param theShape a shape
140   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
141
142   /// Check the selected with validators if installed
143   /// \param theObj the object for checking
144   /// \param theShape the shape for checking
145   virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
146
147   /// Clear attribute
148   void clearAttribute();
149
150   //----------- Class members -------------
151  protected:
152
153    /// Container of the widget's control
154   QWidget* myContainer;
155
156   /// Label of the widget
157   QLabel* myLabel;
158
159   /// Input control of the widget
160   QLineEdit* myTextLine;
161
162   /// Reference to workshop
163   ModuleBase_IWorkshop* myWorkshop;
164
165   /// Pointer to selected object
166   ObjectPtr mySelectedObject;
167
168   /// Pointer to selected shape
169   GeomShapePtr myShape;
170
171   /// List of accepting shapes types
172   QStringList myShapeTypes;
173
174   /// List of accepting object types
175   QStringList myObjectTypes;
176
177   /// Active/inactive flag
178   bool myIsActive;
179
180   /// Filter by objects types
181   Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
182 };
183
184 #endif