Salome HOME
Key_Escape processing in File selector widget. Otherwise, crash happens if file dialo...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_WidgetShapeSelector_H
22 #define ModuleBase_WidgetShapeSelector_H
23
24 #include "ModuleBase.h"
25 #include "ModuleBase_WidgetSelector.h"
26 #include "ModuleBase_ViewerFilters.h"
27
28 #include <ModelAPI_Object.h>
29 #include <ModelAPI_Attribute.h>
30 #include <GeomAPI_Shape.h>
31
32 #include <TopAbs_ShapeEnum.hxx>
33
34 #include <QStringList>
35
36 class Config_WidgetAPI;
37 class QWidget;
38 class QLabel;
39 class QLineEdit;
40 class QToolButton;
41 class ModuleBase_IWorkshop;
42 class ModuleBase_ViewerPrs;
43 class ModelAPI_Validator;
44
45 /**
46 * \ingroup GUI
47 * Implementation of widget for shapes selection.
48 * This type of widget can be defined in XML file with 'shape_selector' keyword.
49 * For example:
50 * \code
51 *   <shape_selector id="main_object" 
52 *    label="Main object" 
53 *    icon=":icons/cut_shape.png" 
54 *    tooltip="Select an object solid"
55 *    shape_types="solid shell"
56 *    concealment="true"
57 *  />
58 * \endcode
59 * It can use following parameters:
60 * - id - name of object attribute
61 * - label - content of widget's label
62 * - icon - icon which can be used instead label
63 * - tooltip - the witget's tooltip text
64 * - shape_types - list of shape types for selection. 
65 *       Possible values: face, vertex, wire, edge, shell, solid
66 * - object_types - types of selectable objects. 
67 *       For today it supports only one type "construction" 
68 *        which corresponds to ModelAPI_ResultConstruction object type
69 * - concealment - hide or not hide selected object after operation
70 */
71 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
72 {
73 Q_OBJECT
74  public:
75
76   /// Constructor
77   /// \param theParent the parent object
78   /// \param theWorkshop instance of workshop interface
79   /// \param theData the widget configuation. The attribute of the model widget is obtained from
80   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
81                                  const Config_WidgetAPI* theData);
82
83   virtual ~ModuleBase_WidgetShapeSelector();
84
85   /// Set the given wrapped value to the current widget
86   /// This value should be processed in the widget according to the needs
87   /// The method is called by the current operation to process the operation preselection.
88   /// It is redefined to check the value validity and if it is, fill the attribute with by value
89   /// \param theValues the wrapped selection values
90   /// \param theToValidate a flag on validation of the values
91   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
92                             const bool theToValidate);
93
94   /// Returns list of widget controls
95   /// \return a control list
96   virtual QList<QWidget*> getControls() const;
97
98  protected:
99   /// Saves the internal parameters to the given feature
100   /// \return True in success
101   virtual bool storeValueCustom();
102
103   virtual bool restoreValueCustom();
104
105   /// Computes and updates name of selected object in the widget
106   virtual void updateSelectionName();
107
108   // Update focus after the attribute value change
109   virtual void updateFocus();
110
111   /// Retunrs a list of possible shape types
112   /// \return a list of shapes
113   virtual QIntList shapeTypes() const;
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<std::shared_ptr<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
136 #endif