1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
22 #define MODULEBASE_WIDGETMULTISELECTOR_H_
24 #include <ModuleBase.h>
25 #include <ModuleBase_WidgetSelector.h>
27 #include <GeomAPI_Shape.h>
28 #include <ModelAPI_Result.h>
30 #include <NCollection_List.hxx>
31 #include <TopoDS_Shape.hxx>
35 #include <QStringList>
41 class ModuleBase_ListView;
42 class ModuleBase_IWorkshop;
46 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
47 * It can be defined in XML file as following:
49 * <multi_selector id="group_list"
50 * tooltip="Select a set of objects"
51 * type_choice="Vertices Edges Faces Solids" />
53 * It uses following parameters:
54 * - id - is a name of corresponded attribute
55 * - tooltip - a tooltip for the widget
56 * - type_choice - list of expected shape types.
58 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
63 /// \param theParent the parent object
64 /// \param theWorkshop instance of workshop interface
65 /// \param theData the widget configuration. The attribute of the model widget is obtained from
66 ModuleBase_WidgetMultiSelector(QWidget* theParent,
67 ModuleBase_IWorkshop* theWorkshop,
68 const Config_WidgetAPI* theData);
69 virtual ~ModuleBase_WidgetMultiSelector();
71 /// Returns list of widget controls
72 /// \return a control list
73 virtual QList<QWidget*> getControls() const;
75 /// The methiod called when widget is deactivated
76 virtual void deactivate();
78 /// Set the given wrapped value to the current widget
79 /// This value should be processed in the widget according to the needs
80 /// \param theValues the wrapped selection values
81 /// \param theToValidate a validation of the values flag
82 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
83 const bool theToValidate);
85 /// Returns values which should be highlighted when the whidget is active
86 /// \param theValues a list of presentations
87 virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
89 /// Returns true if the action can be processed. By default it is empty and returns false.
90 /// \param theActionType an action type
91 /// \param isActionEnabled if true, the enable state of the action
92 virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled);
94 /// Returns true if the event is processed. The default implementation is empty, returns false.
95 virtual bool processAction(ModuleBase_ActionType theActionType);
97 /// Activate or deactivate selection and selection filters
98 /// \return true if the selection filter of the widget is activated in viewer context
99 virtual bool activateSelectionAndFilters(bool toActivate);
101 /// Checks the widget validity. By default, it returns true.
102 /// \param thePrs a selected presentation in the view
103 /// \return a boolean value
104 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
107 /// Slot is called on selection type changed
108 void onSelectionTypeChanged();
110 /// Slot which is called on selection event. Redefined to process XML state about
111 /// clear selection in neutral point
112 virtual void onSelectionChanged();
115 /// Slot for delete command in a list pop-up menu
118 /// Slot is called on selection of list of selected items
119 void onListSelection();
122 /// Returns true if the event is processed. The default implementation is empty, returns false.
123 virtual bool processDelete();
125 /// The methiod called when widget is activated
126 virtual void activateCustom();
128 /// Saves the internal parameters to the given feature
129 /// \return True in success
130 virtual bool storeValueCustom();
132 /// restire type of selection by feature attribute
133 virtual bool restoreValueCustom();
135 /// Creates an element of the attribute current selection if history is empty
136 virtual void appendFirstSelectionInHistory();
138 /// Create an element in the history that stores the current selection,
139 /// position in the history is incremented
140 void appendSelectionInHistory();
142 /// Clear list of stored selected items, reset current position into '-1'
143 void clearSelectedHistory();
145 /// Set the focus on the last item in the list
146 virtual void updateFocus();
148 /// Computes and updates name of selected object in the widget
149 virtual void updateSelectionName();
151 /// Emits model changed info, updates the current control by selection change
152 /// \param theDone a state whether the selection is set
153 virtual void updateOnSelectionChanged(const bool theDone);
155 /// Retunrs a list of possible shape types
156 /// \return a list of shapes
157 virtual QIntList shapeTypes() const;
159 /// Set current shape type for selection
160 void setCurrentShapeType(const int theShapeType);
162 /// Return the attribute values wrapped in a list of viewer presentations
163 /// \return a list of viewer presentations, which contains an attribute result and
164 /// a shape. If the attribute do not uses the shape, it is empty
165 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
167 /// Fills the list control by the attribute values
168 void updateSelectionList();
170 /// Converts the XML defined type choice to the validator type
171 /// For example, the "Edges" is converted to "edge"
172 std::string validatorType(const QString& theType) const;
174 /// Clear selection in the viewer. The content of the widget is cleared also
175 void clearSelection();
178 /// Returns attribute indices selected in the widget selection list
179 /// \param theIndices a list of indices
180 void getSelectedAttributeIndices(std::set<int>& theIndices);
182 /// Gets the feature attribute and fill a list of viewer presentation for the attribute
183 /// indices. If the the container of indices is empty, it returns all objects.
184 /// \param theAttributeIds indices in attribute list to be returned
185 /// \param theValues the result presentations, filled with object and shape of an attribute item
186 void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
187 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) const;
189 /// Iterates throgh the model attribute list and remove elements which do not present in the list
190 /// \param theValues the wrapped selection values
191 /// \return true if at least one object is removed
192 virtual bool removeUnusedAttributeObjects(
193 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
195 /// Converts viewer presentation selection list to objects and shapes map
196 /// \param theValues the wrapped selection values
197 /// \return selection list
198 std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
199 (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
201 /// Returns true if the object and shape present in the container
202 /// \param theObject a model object, a set of shapes is searched by it
203 /// \param theShape a shape to be in the set of the object shapes
204 /// \param theGeomSelection a map built on selection
205 /// \param theWorkshop a current workshop
206 /// \return boolean result
207 static bool findInSelection(const ObjectPtr& theObject,
208 GeomShapePtr theShape,
209 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
210 ModuleBase_IWorkshop* theWorkshop);
213 ModuleBase_ListView* myListView; ///< List control
214 QComboBox* myTypeCombo; ///< Combobox of types
215 bool myIsUseChoice; /// A flag to store use_choice parameter state
217 /// A flag to clear selection by click in empty place in the viewer
218 bool myIsNeutralPointClear;
220 /// A flag to block set selection perform if the method is in process
221 bool myIsSetSelectionBlocked;
223 /// A container of selected objects
224 QList<QList<std::shared_ptr<ModuleBase_ViewerPrs> > > mySelectedHistoryValues;
225 /// Position in a container of selected values
226 int myCurrentHistoryIndex;
229 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */