1 // Copyright (C) 2014-2021 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 email : webmaster.salome@opencascade.com
20 #ifndef MODULEBASE_WIDGETMULTISELECTOR_H_
21 #define MODULEBASE_WIDGETMULTISELECTOR_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_WidgetSelector.h>
26 #include <GeomAPI_Shape.h>
27 #include <ModelAPI_Result.h>
29 #include <NCollection_List.hxx>
30 #include <TopoDS_Shape.hxx>
34 #include <QStringList>
42 class ModuleBase_ListView;
43 class ModuleBase_IWorkshop;
44 class ModuleBase_ChoiceCtrl;
45 class ModuleBase_FilterStarter;
49 * Implementation of widget for shapes selection. This widget provides selection of several shapes.
50 * It can be defined in XML file as following:
52 * <multi_selector id="group_list"
53 * tooltip="Select a set of objects"
54 * shape_types="Vertices Edges Faces Solids" />
56 * It uses following parameters:
57 * - id - is a name of corresponded attribute
58 * - tooltip - a tooltip for the widget
59 * - shape_types - list of expected shape types.
61 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_WidgetSelector
66 /// \param theParent the parent object
67 /// \param theWorkshop instance of workshop interface
68 /// \param theData the widget configuration. The attribute of the model widget is obtained from
69 ModuleBase_WidgetMultiSelector(QWidget* theParent,
70 ModuleBase_IWorkshop* theWorkshop,
71 const Config_WidgetAPI* theData);
72 virtual ~ModuleBase_WidgetMultiSelector();
74 /// Returns list of widget controls
75 /// \return a control list
76 virtual QList<QWidget*> getControls() const;
78 /// The methiod called when widget is deactivated
79 virtual void deactivate();
81 /// Update Undo/Redo actions state
82 virtual void updateAfterDeactivation();
84 /// Update Undo/Redo actions state
85 virtual void updateAfterActivation();
87 /// Set the given wrapped value to the current widget
88 /// This value should be processed in the widget according to the needs
89 /// \param theValues the wrapped selection values
90 /// \param theToValidate a validation of the values flag
91 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
92 const bool theToValidate);
94 /// Returns values which should be highlighted when the whidget is active
95 /// \param theValues a list of presentations
96 virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
98 /// Returns true if the action can be processed. By default it is empty and returns false.
99 /// \param theActionType an action type
100 /// \param isActionEnabled if true, the enable state of the action
101 virtual bool canProcessAction(ModuleBase_ActionType theActionType, bool& isActionEnabled);
103 /// Returns true if the event is processed. The default implementation is empty, returns false.
104 virtual bool processAction(ModuleBase_ActionType theActionType,
105 const ActionParamPtr& theParam = ActionParamPtr());
107 /// Checks the widget validity. By default, it returns true.
108 /// \param thePrs a selected presentation in the view
109 /// \return a boolean value
110 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
112 /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list.
113 /// \param theActionType type of action. It can be ActionUndo or ActionRedo.
114 virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const;
116 /// The slot is called when user press Ok or OkPlus buttons in the parent property panel
117 virtual void onFeatureAccepted();
119 /// Returns True if data of its feature was modified during operation
120 virtual bool isModified() const;
122 virtual void setReadOnly(bool isReadOnly);
125 /// Slot is called on selection type changed
126 void onSelectionTypeChanged();
129 /// Returns true if envent is processed.
130 /// Redefined to process XML state about clear selection in neutral point
131 virtual bool processSelection();
134 /// Slot for delete command in a list pop-up menu
137 /// Slot is called on selection of list of selected items
138 void onListSelection();
140 void onListActivated();
142 void onSameTopology(bool theOn);
144 void onShowOnly(bool);
147 /// Returns true if the event is processed. The default implementation is empty, returns false.
148 virtual bool processDelete();
150 /// The methiod called when widget is activated
151 virtual void activateCustom();
153 /// Saves the internal parameters to the given feature
154 /// \return True in success
155 virtual bool storeValueCustom();
157 /// restire type of selection by feature attribute
158 virtual bool restoreValueCustom();
160 /// Creates an element of the attribute current selection if history is empty
161 virtual void appendFirstSelectionInHistory();
163 /// Create an element in the history that stores the current selection,
164 /// position in the history is incremented
165 void appendSelectionInHistory();
167 /// Clear list of stored selected items, reset current position into '-1'
168 void clearSelectedHistory();
170 /// Set the focus on the last item in the list
171 virtual void updateFocus();
173 /// Computes and updates name of selected object in the widget
174 virtual void updateSelectionName();
176 /// Emits model changed info, updates the current control by selection change
177 /// \param theDone a state whether the selection is set
178 virtual void updateOnSelectionChanged(const bool theDone);
180 /// Retunrs a list of possible shape types
181 /// \return a list of shapes
182 virtual QIntList shapeTypes() const;
184 /// Set current shape type for selection
185 void setCurrentShapeType(const QString& theShapeType);
187 /// Return the attribute values wrapped in a list of viewer presentations
188 /// \return a list of viewer presentations, which contains an attribute result and
189 /// a shape. If the attribute do not uses the shape, it is empty
190 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
192 /// Fills the list control by the attribute values
193 void updateSelectionList();
195 /// Converts the XML defined type choice to the validator type
196 /// For example, the "Edges" is converted to "edge"
197 std::string validatorType(const QString& theType) const;
199 /// Clear selection in the viewer. The content of the widget is cleared also
200 void clearSelection();
203 /// Returns attribute indices selected in the widget selection list
204 /// \param theIndices a list of indices
205 void getSelectedAttributeIndices(std::set<int>& theIndices);
207 /// Gets the feature attribute and fill a list of viewer presentation for the attribute
208 /// indices. If the the container of indices is empty, it returns all objects.
209 /// \param theAttributeIds indices in attribute list to be returned
210 /// \param theValues the result presentations, filled with object and shape of an attribute item
211 void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
212 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues) const;
214 /// Iterates throgh the model attribute list and remove elements which do not present in the list
215 /// \param theValues the wrapped selection values
216 /// \return true if at least one object is removed
217 virtual bool removeUnusedAttributeObjects(
218 QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
220 /// Converts viewer presentation selection list to objects and shapes map
221 /// \param theValues the wrapped selection values
222 /// \return selection list
223 std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
224 (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
226 /// Returns true if the object and shape present in the container
227 /// \param theObject a model object, a set of shapes is searched by it
228 /// \param theShape a shape to be in the set of the object shapes
229 /// \param theGeomSelection a map built on selection
230 /// \param theWorkshop a current workshop
231 /// \return boolean result
232 static bool findInSelection(const ObjectPtr& theObject,
233 GeomShapePtr theShape,
234 const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection,
235 ModuleBase_IWorkshop* theWorkshop);
238 ModuleBase_ListView* myListView; ///< List control
240 bool myIsUseChoice; ///< A flag to store use_choice parameter state
242 QStringList myShapeTypes; ///< List of Shape types defined in XML
244 /// Control for types
245 ModuleBase_ChoiceCtrl* myTypeCtrl;
247 /// A flag to clear selection by click in empty place in the viewer
248 bool myIsNeutralPointClear;
250 /// A flag to block set selection perform if the method is in process
251 bool myIsSetSelectionBlocked;
253 /// A container of selected objects
254 QList<QList<std::shared_ptr<ModuleBase_ViewerPrs> > > mySelectedHistoryValues;
256 /// Position in a container of selected values
257 int myCurrentHistoryIndex;
260 std::string myDefMode;
262 QVBoxLayout* myMainLayout;
263 QCheckBox* myGeomCheck;
264 ModuleBase_FilterStarter* myFiltersWgt;
265 QPushButton* myShowOnlyBtn;
267 QObjectPtrList myVisibleObjects;
268 QStringList myAllowedObjects;
269 QStringList myTmpAllowed;
270 std::string myUseFilters;
273 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */