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>
18 #include <ModelAPI_AttributeSelectionList.h>
20 #include <NCollection_List.hxx>
21 #include <TopoDS_Shape.hxx>
25 #include <QStringList>
32 class ModuleBase_IWorkshop;
33 class GeomValidators_ShapeType;
39 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
40 * It can be defined in XML file as following:
42 * <multi_selector id="group_list"
43 * tooltip="Select a set of objects"
44 * type_choice="Vertices Edges Faces Solids" />
46 * It uses following parameters:
47 * - id - is a name of corresponded attribute
48 * - tooltip - a tooltip for the widget
49 * - type_choice - list of expected shape types.
51 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
56 /// \param theParent the parent object
57 /// \param theWorkshop instance of workshop interface
58 /// \param theData the widget configuration. The attribute of the model widget is obtained from
59 /// \param theParentId is Id of a parent of the current attribute
60 ModuleBase_WidgetMultiSelector(QWidget* theParent,
61 ModuleBase_IWorkshop* theWorkshop,
62 const Config_WidgetAPI* theData,
63 const std::string& theParentId);
64 virtual ~ModuleBase_WidgetMultiSelector();
66 /// Returns list of widget controls
67 /// \return a control list
68 virtual QList<QWidget*> getControls() const;
70 /// Set the given wrapped value to the current widget
71 /// This value should be processed in the widget according to the needs
72 /// \param theValues the wrapped selection values
73 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
74 const bool theToValidate);
76 /// Checks the widget validity. By default, it returns true.
77 /// \param theValue a selected presentation in the view
78 /// \return a boolean value
79 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
82 /// Slot is called on selection type changed
83 void onSelectionTypeChanged();
86 /// Slot for copy command in a list pop-up menu
89 /// Slot is called on selection of list of selected items
90 void onListSelection();
93 /// Saves the internal parameters to the given feature
94 /// \return True in success
95 virtual bool storeValueCustom() const;
97 virtual bool restoreValueCustom();
99 /// Creates a backup of the current values of the attribute
100 /// It should be realized in the specific widget because of different
101 /// parameters of the current attribute
102 virtual void storeAttributeValue();
105 virtual void clearAttribute();
107 // Set the focus on the last item in the list
108 virtual void updateFocus();
110 /// Computes and updates name of selected object in the widget
111 virtual void updateSelectionName();
113 /// Retunrs a list of possible shape types
114 /// \return a list of shapes
115 virtual QIntList getShapeTypes() const;
117 /// Append the values to the model attribute of the widget. It casts this attribute to
118 /// the specific type and set the given values
119 /// \param theSelectedObject an object
120 /// \param theShape a selected shape, which is used in the selection attribute
121 /// \return true if it is succeed
122 void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
124 /// Creates a backup of the current values of the attribute
125 /// It should be realized in the specific widget because of different
126 /// parameters of the current attribute
127 /// \param theValid a boolean flag, if restore happens for valid parameters
128 virtual void restoreAttributeValue(const bool theValid);
130 /// Set current shape type for selection
131 void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
133 /// Return the attribute values wrapped in a list of viewer presentations
134 /// \return a list of viewer presentations, which contains an attribute result and
135 /// a shape. If the attribute do not uses the shape, it is empty
136 virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
138 /// Update selection list
139 void updateSelectionList(AttributeSelectionListPtr);
141 /// Converts the XML defined type choice to the validator type
142 /// For example, the "Edges" is converted to "edge"
143 std::string validatorType(const QString& theType) const;
147 QListWidget* myListControl;
149 /// Combobox of types
150 QComboBox* myTypeCombo;
152 /// Provides correspondance between Result object and its shape
153 typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
155 /// An action for pop-up menu in a list control
156 QAction* myCopyAction;
158 /// backup parameters of the model attribute. The class processes three types of attribute:
159 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
160 /// values are reserved in the backup
161 /// Variable of selection type
162 std::string mySelectionType;
164 /// Variable of GeomSelection
165 //QList<GeomSelection> mySelection;
166 int mySelectionCount; // number of elements in the attribute selection list when store
171 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */