1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_WidgetShapeSelector_H
21 #define ModuleBase_WidgetShapeSelector_H
23 #include "ModuleBase.h"
24 #include "ModuleBase_WidgetSelector.h"
25 #include "ModuleBase_ViewerFilters.h"
27 #include <ModelAPI_Object.h>
28 #include <ModelAPI_Attribute.h>
29 #include <GeomAPI_Shape.h>
31 #include <TopAbs_ShapeEnum.hxx>
33 #include <QStringList>
35 class Config_WidgetAPI;
40 class ModuleBase_IWorkshop;
41 class ModuleBase_ViewerPrs;
42 class ModelAPI_Validator;
46 * Implementation of widget for shapes selection.
47 * This type of widget can be defined in XML file with 'shape_selector' keyword.
50 * <shape_selector id="main_object"
52 * icon=":icons/cut_shape.png"
53 * tooltip="Select an object solid"
54 * shape_types="solid shell"
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
70 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
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);
82 virtual ~ModuleBase_WidgetShapeSelector();
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);
93 /// Returns list of widget controls
94 /// \return a control list
95 virtual QList<QWidget*> getControls() const;
97 /// Returns True if data of its feature was modified during operation
98 virtual bool isModified() const;
101 /// Saves the internal parameters to the given feature
102 /// \return True in success
103 virtual bool storeValueCustom();
105 virtual bool restoreValueCustom();
107 /// Computes and updates name of selected object in the widget
108 virtual void updateSelectionName();
110 // Update focus after the attribute value change
111 virtual void updateFocus();
113 /// Retunrs a list of possible shape types
114 /// \return a list of shapes
115 virtual QIntList shapeTypes() const;
117 /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
119 virtual GeomShapePtr getShape() const;
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;
126 //----------- Class members -------------
128 /// Label of the widget
131 /// Input control of the widget
132 QLineEdit* myTextLine;
134 /// List of accepting shapes types
135 QStringList myShapeTypes;