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