Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_WidgetShapeSelector_H
21 #define ModuleBase_WidgetShapeSelector_H
22
23 #include "ModuleBase.h"
24 #include "ModuleBase_WidgetSelector.h"
25 #include "ModuleBase_ViewerFilters.h"
26
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Attribute.h>
29 #include <GeomAPI_Shape.h>
30
31 #include <TopAbs_ShapeEnum.hxx>
32
33 #include <QStringList>
34
35 class Config_WidgetAPI;
36 class QWidget;
37 class QLabel;
38 class QLineEdit;
39 class QToolButton;
40 class ModuleBase_IWorkshop;
41 class ModuleBase_ViewerPrs;
42 class ModelAPI_Validator;
43
44 /**
45 * \ingroup GUI
46 * Implementation of widget for shapes selection.
47 * This type of widget can be defined in XML file with 'shape_selector' keyword.
48 * For example:
49 * \code
50 *   <shape_selector id="main_object" 
51 *    label="Main object" 
52 *    icon=":icons/cut_shape.png" 
53 *    tooltip="Select an object solid"
54 *    shape_types="solid shell"
55 *    concealment="true"
56 *  />
57 * \endcode
58 * It can use following parameters:
59 * - id - name of object attribute
60 * - label - content of widget's label
61 * - icon - icon which can be used instead label
62 * - tooltip - the witget's tooltip text
63 * - shape_types - list of shape types for selection. 
64 *       Possible values: face, vertex, wire, edge, shell, solid
65 * - object_types - types of selectable objects. 
66 *       For today it supports only one type "construction" 
67 *        which corresponds to ModelAPI_ResultConstruction object type
68 * - concealment - hide or not hide selected object after operation
69 */
70 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
71 {
72 Q_OBJECT
73  public:
74
75   /// Constructor
76   /// \param theParent the parent object
77   /// \param theWorkshop instance of workshop interface
78   /// \param theData the widget configuation. The attribute of the model widget is obtained from
79   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
80                                  const Config_WidgetAPI* theData);
81
82   virtual ~ModuleBase_WidgetShapeSelector();
83
84   /// Set the given wrapped value to the current widget
85   /// This value should be processed in the widget according to the needs
86   /// The method is called by the current operation to process the operation preselection.
87   /// It is redefined to check the value validity and if it is, fill the attribute with by value
88   /// \param theValues the wrapped selection values
89   /// \param theToValidate a flag on validation of the values
90   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
91                             const bool theToValidate);
92
93   /// Returns list of widget controls
94   /// \return a control list
95   virtual QList<QWidget*> getControls() const;
96
97   /// Returns True if data of its feature was modified during operation
98   virtual bool isModified() const;
99
100  protected:
101   /// Saves the internal parameters to the given feature
102   /// \return True in success
103   virtual bool storeValueCustom();
104
105   virtual bool restoreValueCustom();
106
107   /// Computes and updates name of selected object in the widget
108   virtual void updateSelectionName();
109
110   // Update focus after the attribute value change
111   virtual void updateFocus();
112
113   /// Retunrs a list of possible shape types
114   /// \return a list of shapes
115   virtual QIntList shapeTypes() const;
116
117   /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
118   /// \return a shape
119   virtual GeomShapePtr getShape() const;
120
121   /// Return the attribute values wrapped in a list of viewer presentations
122   /// \return a list of viewer presentations, which contains an attribute result and
123   /// a shape. If the attribute do not uses the shape, it is empty
124   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
125
126   //----------- Class members -------------
127   protected:
128   /// Label of the widget
129   QLabel* myLabel;
130
131   /// Input control of the widget
132   QLineEdit* myTextLine;
133
134   /// List of accepting shapes types
135   QStringList myShapeTypes;
136 };
137
138 #endif