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<std::shared_ptr<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<std::shared_ptr<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 std::shared_ptr<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();
110 virtual bool restoreValueCustom();
112 /// Set the focus on the last item in the list
113 virtual void updateFocus();
115 /// Computes and updates name of selected object in the widget
116 virtual void updateSelectionName();
118 /// Retunrs a list of possible shape types
119 /// \return a list of shapes
120 virtual QIntList getShapeTypes() const;
122 /// Set current shape type for selection
123 void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
125 /// Return the attribute values wrapped in a list of viewer presentations
126 /// \return a list of viewer presentations, which contains an attribute result and
127 /// a shape. If the attribute do not uses the shape, it is empty
128 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
130 /// Fills the list control by the attribute values
131 void updateSelectionList();
133 /// Converts the XML defined type choice to the validator type
134 /// For example, the "Edges" is converted to "edge"
135 std::string validatorType(const QString& theType) const;
138 /// Returns attribute indices selected in the widget selection list
139 /// \param theIndices a list of indices
140 void getSelectedAttributeIndices(std::set<int>& theIndices);
142 /// Gets the feature attribute and fill a list of viewer presentation for the attribute
143 /// indices. If the the container of indices is empty, it returns all objects.
144 /// \param theAttributeIds indices in attribute list to be returned
145 /// \param theValues the result presentations, filled with object and shape of an attribute item
146 void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
147 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) const;
149 /// Iterates throgh the model attribute list and remove elements which do not present in the list
150 /// \param theValues the wrapped selection values
151 /// \return true if at least one object is removed
152 virtual bool removeUnusedAttributeObjects(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
154 /// Converts viewer presentation selection list to objects and shapes map
155 /// \param theValues the wrapped selection values
156 /// \return selection list
157 std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
158 (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
160 /// Returns true if the object and shape present in the container
161 /// \param theObject a model object, a set of shapes is searched by it
162 /// \param theShape a shape to be in the set of the object shapes
163 /// \param theGeomSelection a map built on selection
164 /// \return boolean result
165 static bool findInSelection(const ObjectPtr& theObject,
166 const GeomShapePtr& theShape,
167 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection);
171 QListWidget* myListControl;
173 /// Combobox of types
174 QComboBox* myTypeCombo;
176 /// Provides correspondance between Result object and its shape
177 typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
179 /// An action for pop-up menu in a list control
180 QAction* myCopyAction;
181 QAction* myDeleteAction;
183 /// A flag to store use_choice parameter state
187 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */