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 ModuleBase_WidgetMultiSelector(QWidget* theParent,
58 ModuleBase_IWorkshop* theWorkshop,
59 const Config_WidgetAPI* theData);
60 virtual ~ModuleBase_WidgetMultiSelector();
62 /// Returns list of widget controls
63 /// \return a control list
64 virtual QList<QWidget*> getControls() const;
66 /// The methiod called when widget is deactivated
67 virtual void deactivate();
69 /// Set the given wrapped value to the current widget
70 /// This value should be processed in the widget according to the needs
71 /// \param theValues the wrapped selection values
72 /// \param theToValidate a validation of the values flag
73 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
74 const bool theToValidate);
76 /// Returns values which should be highlighted when the whidget is active
77 /// \param theValues a list of presentations
78 virtual void getHighlighted(QList<ModuleBase_ViewerPrs>& theValues);
80 /// Checks the widget validity. By default, it returns true.
81 /// \param thePrs a selected presentation in the view
82 /// \return a boolean value
83 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
85 /// Returns true if the event is processed. The default implementation is empty, returns false.
86 virtual bool processDelete();
89 /// Slot is called on selection type changed
90 void onSelectionTypeChanged();
93 /// Slot for copy command in a list pop-up menu
96 /// Slot for delete command in a list pop-up menu
99 /// Slot is called on selection of list of selected items
100 void onListSelection();
103 /// The methiod called when widget is activated
104 virtual void activateCustom();
106 /// Saves the internal parameters to the given feature
107 /// \return True in success
108 virtual bool storeValueCustom() const;
110 virtual bool restoreValueCustom();
112 /// Creates a backup of the current values of the attribute
113 /// It should be realized in the specific widget because of different
114 /// parameters of the current attribute
115 virtual void storeAttributeValue();
117 /// Set the focus on the last item in the list
118 virtual void updateFocus();
120 /// Computes and updates name of selected object in the widget
121 virtual void updateSelectionName();
123 /// Retunrs a list of possible shape types
124 /// \return a list of shapes
125 virtual QIntList getShapeTypes() const;
127 /// Append the values to the model attribute of the widget. It casts this attribute to
128 /// the specific type and set the given values
129 /// \param theObject an object
130 /// \param theShape a selected shape, which is used in the selection attribute
131 /// \return true if it is succeed
132 void setObject(ObjectPtr theObject, GeomShapePtr theShape);
134 /// Creates a backup of the current values of the attribute
135 /// It should be realized in the specific widget because of different
136 /// parameters of the current attribute
137 /// \param theValid a boolean flag, if restore happens for valid parameters
138 virtual void restoreAttributeValue(const bool theValid);
140 /// Set current shape type for selection
141 void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
143 /// Return the attribute values wrapped in a list of viewer presentations
144 /// \return a list of viewer presentations, which contains an attribute result and
145 /// a shape. If the attribute do not uses the shape, it is empty
146 virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
148 /// Fills the list control by the attribute values
149 void updateSelectionList();
151 /// Converts the XML defined type choice to the validator type
152 /// For example, the "Edges" is converted to "edge"
153 std::string validatorType(const QString& theType) const;
156 /// Returns attribute indices selected in the widget selection list
157 /// \param theIndices a list of indices
158 void getSelectedAttributeIndices(std::set<int>& theIndices);
160 /// Gets the feature attribute and fill a list of viewer presentation for the attribute
161 /// indices. If the the container of indices is empty, it returns all objects.
162 /// \param theAttributeIds indices in attribute list to be returned
163 /// \param theValues the result presentations, filled with object and shape of an attribute item
164 void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
165 QList<ModuleBase_ViewerPrs>& theValues) const;
167 /// Iterates throgh the model attribute list and remove elements which do not present in the list
168 /// \param theValues the wrapped selection values
169 virtual void removeUnusedAttributeObjects(QList<ModuleBase_ViewerPrs>& theValues);
171 /// Converts viewer presentation selection list to objects and shapes map
172 /// \param theValues the wrapped selection values
173 /// \return selection list
174 std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
175 (QList<ModuleBase_ViewerPrs>& theValues);
177 /// Returns true if the object and shape present in the container
178 /// \param theObject a model object, a set of shapes is searched by it
179 /// \param theShape a shape to be in the set of the object shapes
180 /// \param theGeomSelection a map built on selection
181 /// \return boolean result
182 static bool findInSelection(const ObjectPtr& theObject,
183 const GeomShapePtr& theShape,
184 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection);
188 QListWidget* myListControl;
190 /// Combobox of types
191 QComboBox* myTypeCombo;
193 /// Provides correspondance between Result object and its shape
194 typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
196 /// An action for pop-up menu in a list control
197 QAction* myCopyAction;
198 QAction* myDeleteAction;
200 /// backup parameters of the model attribute. The class processes three types of attribute:
201 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
202 /// values are reserved in the backup
203 /// Variable of selection type
204 std::string mySelectionType;
206 /// Variable of GeomSelection
207 int mySelectionCount; // number of elements in the attribute selection list when store
209 /// A flag to store use_choice parameter state
213 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */