Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: extrusion cut.
[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_WidgetSelector.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
31 /**
32 * \ingroup GUI
33 * Implementation of widget for shapes selection.
34 * This type of widget can be defined in XML file with 'shape_selector' keyword.
35 * For example:
36 * \code
37 *   <shape_selector id="main_object" 
38 *    label="Main object" 
39 *    icon=":icons/cut_shape.png" 
40 *    tooltip="Select an object solid"
41 *    shape_types="solid shell"
42 *    concealment="true"
43 *  />
44 * \endcode
45 * It can use following parameters:
46 * - id - name of object attribute
47 * - label - content of widget's label
48 * - icon - icon which can be used instead label
49 * - tooltip - the witget's tooltip text
50 * - shape_types - list of shape types for selection. 
51 *       Possible values: face, vertex, wire, edge, shell, solid
52 * - object_types - types of selectable objects. 
53 *       For today it supports only one type "construction" 
54 *        which corresponds to ModelAPI_ResultConstruction object type
55 * - concealment - hide or not hide selected object after operation
56 */
57 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
58 {
59 Q_OBJECT
60  public:
61
62   /// Constructor
63   /// \param theParent the parent object
64   /// \param theWorkshop instance of workshop interface
65   /// \param theData the widget configuation. The attribute of the model widget is obtained from
66   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
67                                  const Config_WidgetAPI* theData);
68
69   virtual ~ModuleBase_WidgetShapeSelector();
70
71   /// Returns list of widget controls
72   /// \return a control list
73   virtual QList<QWidget*> getControls() const;
74
75  protected:
76   /// Saves the internal parameters to the given feature
77   /// \return True in success
78   virtual bool storeValueCustom() const;
79
80   virtual bool restoreValueCustom();
81
82   /// Creates a backup of the current values of the attribute
83   /// It should be realized in the specific widget because of different
84   /// parameters of the current attribute
85   virtual void storeAttributeValue();
86
87   /// Creates a backup of the current values of the attribute
88   /// It should be realized in the specific widget because of different
89   /// parameters of the current attribute
90   /// \param theValid a boolean flag, if restore happens for valid parameters
91   virtual void restoreAttributeValue(const bool theValid);
92
93   /// Computes and updates name of selected object in the widget
94   virtual void updateSelectionName();
95
96   // Update focus after the attribute value change
97   virtual void updateFocus();
98
99   /// Retunrs a list of possible shape types
100   /// \return a list of shapes
101   virtual QIntList getShapeTypes() const;
102
103   /// Store the values to the model attribute of the widget. It casts this attribute to
104   /// the specific type and set the given values
105   /// \param theObject an object
106   /// \param theShape a selected shape, which is used in the selection attribute
107   /// \return true if it is succeed
108   virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape);
109
110   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
111   /// \return a shape
112   virtual GeomShapePtr getShape() const;
113
114   /// Return the attribute values wrapped in a list of viewer presentations
115   /// \return a list of viewer presentations, which contains an attribute result and
116   /// a shape. If the attribute do not uses the shape, it is empty
117   virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
118
119   //----------- Class members -------------
120   protected:
121   /// Label of the widget
122   QLabel* myLabel;
123
124   /// Input control of the widget
125   QLineEdit* myTextLine;
126
127   /// List of accepting shapes types
128   QStringList myShapeTypes;
129
130   /// backup parameters of the model attribute. The class processes three types of attribute:
131   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
132   /// values are reserved in the backup
133   /// An attribute object
134   ObjectPtr myObject;
135   /// An attribute shape
136   GeomShapePtr myShape;
137   /// A reference of the attribute
138   AttributePtr myRefAttribute;
139   /// A boolean value whether refAttr uses reference of object
140   bool myIsObject;
141 };
142
143 #endif