1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetMultiSelector.h
6 * Created on: Oct 8, 2014
10 #ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
11 #define MODULEBASE_WIDGETMULTISELECTOR_H_
13 #include <ModuleBase.h>
14 #include <ModuleBase_WidgetSelector.h>
16 #include <GeomAPI_Shape.h>
17 #include <ModelAPI_Result.h>
19 #include <NCollection_List.hxx>
20 #include <TopoDS_Shape.hxx>
24 #include <QStringList>
31 class ModuleBase_IWorkshop;
37 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
38 * It can be defined in XML file as following:
40 * <multi_selector id="group_list"
41 * tooltip="Select a set of objects"
42 * type_choice="Vertices Edges Faces Solids" />
44 * It uses following parameters:
45 * - id - is a name of corresponded attribute
46 * - tooltip - a tooltip for the widget
47 * - type_choice - list of expected shape types.
49 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
54 /// \param theParent the parent object
55 /// \param theWorkshop instance of workshop interface
56 /// \param theData the widget configuration. The attribute of the model widget is obtained from
57 /// \param theParentId is Id of a parent of the current attribute
58 ModuleBase_WidgetMultiSelector(QWidget* theParent,
59 ModuleBase_IWorkshop* theWorkshop,
60 const Config_WidgetAPI* theData,
61 const std::string& theParentId);
62 virtual ~ModuleBase_WidgetMultiSelector();
64 /// Returns list of widget controls
65 /// \return a control list
66 virtual QList<QWidget*> getControls() const;
68 /// Set the given wrapped value to the current widget
69 /// This value should be processed in the widget according to the needs
70 /// \param theValues the wrapped selection values
71 /// \param theToValidate a validation of the values flag
72 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
73 const bool theToValidate);
75 /// Checks the widget validity. By default, it returns true.
76 /// \param thePrs a selected presentation in the view
77 /// \return a boolean value
78 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
81 /// Slot is called on selection type changed
82 void onSelectionTypeChanged();
85 /// Signals about items selected in the list view
86 void itemsSelected(const QList<ModuleBase_ViewerPrs>& theItems);
89 /// Slot for copy command in a list pop-up menu
92 /// Slot for delete command in a list pop-up menu
95 /// Slot is called on selection of list of selected items
96 void onListSelection();
99 /// Saves the internal parameters to the given feature
100 /// \return True in success
101 virtual bool storeValueCustom() const;
103 virtual bool restoreValueCustom();
105 /// Creates a backup of the current values of the attribute
106 /// It should be realized in the specific widget because of different
107 /// parameters of the current attribute
108 virtual void storeAttributeValue();
111 virtual void clearAttribute();
113 /// Set the focus on the last item in the list
114 virtual void updateFocus();
116 /// Computes and updates name of selected object in the widget
117 virtual void updateSelectionName();
119 /// Retunrs a list of possible shape types
120 /// \return a list of shapes
121 virtual QIntList getShapeTypes() const;
123 /// Append the values to the model attribute of the widget. It casts this attribute to
124 /// the specific type and set the given values
125 /// \param theSelectedObject an object
126 /// \param theShape a selected shape, which is used in the selection attribute
127 /// \return true if it is succeed
128 void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
130 /// Creates a backup of the current values of the attribute
131 /// It should be realized in the specific widget because of different
132 /// parameters of the current attribute
133 /// \param theValid a boolean flag, if restore happens for valid parameters
134 virtual void restoreAttributeValue(const bool theValid);
136 /// Set current shape type for selection
137 void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
139 /// Return the attribute values wrapped in a list of viewer presentations
140 /// \return a list of viewer presentations, which contains an attribute result and
141 /// a shape. If the attribute do not uses the shape, it is empty
142 virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
144 /// Fills the list control by the attribute values
145 void updateSelectionList();
147 /// Converts the XML defined type choice to the validator type
148 /// For example, the "Edges" is converted to "edge"
149 std::string validatorType(const QString& theType) const;
153 QListWidget* myListControl;
155 /// Combobox of types
156 QComboBox* myTypeCombo;
158 /// Provides correspondance between Result object and its shape
159 typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
161 /// An action for pop-up menu in a list control
162 QAction* myCopyAction;
163 QAction* myDeleteAction;
165 /// backup parameters of the model attribute. The class processes three types of attribute:
166 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
167 /// values are reserved in the backup
168 /// Variable of selection type
169 std::string mySelectionType;
171 /// Variable of GeomSelection
172 int mySelectionCount; // number of elements in the attribute selection list when store
174 /// A flag to store use_choice parameter state
178 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */