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_WidgetValidated.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 folloing 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_WidgetValidated
56 /// \param theParent the parent object
57 /// \param theWorkshop instance of workshop interface
58 /// \param theData the widget configuation. 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 //TODO: nds stabilization hotfix
67 virtual void disconnectSignals();
69 virtual bool restoreValue();
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 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
83 /// Checks the widget validity. By default, it returns true.
84 /// \param theValue a selected presentation in the view
85 /// \return a boolean value
86 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
88 /// Fills the attribute with the value of the selected owner
89 /// \param theOwner a selected owner
90 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
93 /// Slot is called on selection type changed
94 void onSelectionTypeChanged();
96 /// Slot is called on selection changed
97 virtual void onSelectionChanged();
100 /// Slot for copy command in a list pop-up menu
103 /// Slot is called on selection of list of selected items
104 void onListSelection();
107 /// The methiod called when widget is activated
108 virtual void activateCustom();
110 /// Saves the internal parameters to the given feature
111 /// \return True in success
112 virtual bool storeValueCustom() const;
114 /// Creates a backup of the current values of the attribute
115 /// It should be realized in the specific widget because of different
116 /// parameters of the current attribute
117 virtual void storeAttributeValue();
119 /// Append the values to the model attribute of the widget. It casts this attribute to
120 /// the specific type and set the given values
121 /// \param theSelectedObject an object
122 /// \param theShape a selected shape, which is used in the selection attribute
123 /// \return true if it is succeed
124 void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
126 /// Creates a backup of the current values of the attribute
127 /// It should be realized in the specific widget because of different
128 /// parameters of the current attribute
129 /// \param theValid a boolean flag, if restore happens for valid parameters
130 virtual void restoreAttributeValue(const bool theValid);
132 /// Returns true if selected shape corresponds to requested shape types
133 /// \param theShape a shape
134 bool acceptSubShape(const TopoDS_Shape& theShape) const;
136 /// Set current shape type for selection
137 void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
139 /// Start shape selection
140 /// \param isActivated a state whether the shape is activated or deactivated in selection
141 void activateShapeSelection(const bool isActivated);
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 QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
148 /// Update selection list
149 void updateSelectionList(AttributeSelectionListPtr);
151 /// Return an object and geom shape by the viewer presentation
152 /// \param thePrs a selection
153 /// \param theObject an output object
154 /// \param theShape a shape of the selection
155 virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
156 ObjectPtr& theObject,
157 GeomShapePtr& theShape);
159 /// Converts the XML defined type choice to the validator type
160 /// For example, the "Edges" is converted to "edge"
161 std::string validatorType(const QString& theType) const;
164 QListWidget* myListControl;
166 /// Combobox of types
167 QComboBox* myTypeCombo;
169 //TODO: Move into the base of selectors
170 ModuleBase_IWorkshop* myWorkshop;
172 /// Provides correspondance between Result object and its shape
173 typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
175 /// An action for pop-up menu in a list control
176 QAction* myCopyAction;
178 /// backup parameters of the model attribute. The class processes three types of attribute:
179 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
180 /// values are reserved in the backup
181 /// Variable of selection type
182 std::string mySelectionType;
184 /// Variable of GeomSelection
185 QList<GeomSelection> mySelection;
187 /// An instance of the "type_choice" validator. It is returns on validating in customValidator()
188 GeomValidators_ShapeType* myShapeValidator;
190 //bool myIsUseChoice;
193 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */