Salome HOME
1. Correction for perfomance problem by Apply button state update: do not listen...
[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
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 class ModuleBase_ViewerPrs;
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   /// Set the given wrapped value to the current widget
72   /// This value should be processed in the widget according to the needs
73   /// The method is called by the current operation to process the operation preselection.
74   /// It is redefined to check the value validity and if it is, fill the attribute with by value
75   /// \param theValues the wrapped selection values
76   /// \param theToValidate a flag on validation of the values
77   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
78                             const bool theToValidate);
79
80   /// Returns list of widget controls
81   /// \return a control list
82   virtual QList<QWidget*> getControls() const;
83
84  protected:
85   /// Saves the internal parameters to the given feature
86   /// \return True in success
87   virtual bool storeValueCustom();
88
89   virtual bool restoreValueCustom();
90
91   /// Computes and updates name of selected object in the widget
92   virtual void updateSelectionName();
93
94   // Update focus after the attribute value change
95   virtual void updateFocus();
96
97   /// Retunrs a list of possible shape types
98   /// \return a list of shapes
99   virtual QIntList getShapeTypes() const;
100
101   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
102   /// \return a shape
103   virtual GeomShapePtr getShape() const;
104
105   /// Return the attribute values wrapped in a list of viewer presentations
106   /// \return a list of viewer presentations, which contains an attribute result and
107   /// a shape. If the attribute do not uses the shape, it is empty
108   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
109
110   //----------- Class members -------------
111   protected:
112   /// Label of the widget
113   QLabel* myLabel;
114
115   /// Input control of the widget
116   QLineEdit* myTextLine;
117
118   /// List of accepting shapes types
119   QStringList myShapeTypes;
120 };
121
122 #endif