1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetShapeSelector.h
4 // Created: 2 June 2014
5 // Author: Vitaly Smetannikov
7 #ifndef ModuleBase_WidgetShapeSelector_H
8 #define ModuleBase_WidgetShapeSelector_H
10 #include "ModuleBase.h"
11 #include "ModuleBase_ModelWidget.h"
12 #include "ModuleBase_ViewerFilters.h"
14 #include <ModelAPI_Object.h>
15 #include <GeomAPI_Shape.h>
17 #include <TopAbs_ShapeEnum.hxx>
18 #include <SelectMgr_ListOfFilter.hxx>
20 #include <QStringList>
22 class Config_WidgetAPI;
27 class ModuleBase_IWorkshop;
31 * Implementation of widget for shapes selection.
32 * This type of widget can be defined in XML file with 'shape_selector' keyword.
35 * <shape_selector id="main_object"
37 * icon=":icons/cut_shape.png"
38 * tooltip="Select an object solid"
39 * shape_types="solid shell"
43 * It can use following parameters:
44 * - id - name of object attribute
45 * - label - content of widget's label
46 * - icon - icon which can be used instead label
47 * - tooltip - the witget's tooltip text
48 * - shape_types - list of shape types for selection.
49 * Possible values: face, vertex, wire, edge, shell, solid
50 * - object_types - types of selectable objects.
51 * For today it supports only one type "construction"
52 * which corresponds to ModelAPI_ResultConstruction object type
53 * - concealment - hide or not hide selected object after operation
55 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
60 /// Converts string value (name of shape type) to shape enum value
61 /// \param theType - string with shape type name
62 /// \return TopAbs_ShapeEnum value
63 static TopAbs_ShapeEnum shapeType(const QString& theType);
66 /// \param theParent the parent object
67 /// \param theWorkshop instance of workshop interface
68 /// \param theData the widget configuation. The attribute of the model widget is obtained from
69 /// \param theParentId is Id of a parent of the current attribute
70 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
71 const Config_WidgetAPI* theData, const std::string& theParentId);
73 virtual ~ModuleBase_WidgetShapeSelector();
75 virtual bool restoreValue();
77 /// Defines if it is supposed that the widget should interact with the viewer.
78 virtual bool isViewerSelector() { return true; }
80 /// Returns list of widget controls
81 /// \return a control list
82 virtual QList<QWidget*> getControls() const;
84 /// Returns currently selected data object
85 ObjectPtr selectedFeature() const
87 return mySelectedObject;
90 /// Set the given wrapped value to the current widget
91 /// This value should be processed in the widget according to the needs
92 /// \param theValue the wrapped widget value
93 virtual bool setSelection(ModuleBase_ViewerPrs theValue);
96 /// The methiod called when widget is deactivated
97 virtual void deactivate();
102 /// Activate or deactivate selection
103 void activateSelection(bool toActivate);
106 /// Slot which is called on selection event
107 void onSelectionChanged();
110 /// Saves the internal parameters to the given feature
111 /// \return True in success
112 virtual bool storeValueCustom() const;
114 /// The methiod called when widget is activated
115 virtual void activateCustom();
117 /// Computes and updates name of selected object in the widget
118 void updateSelectionName();
120 /// Raise panel which contains this widget
121 void raisePanel() const;
123 /// Returns true if selected shape corresponds to requested shape types
124 /// \param theShape a shape
125 virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
127 /// Returns true if selected object corresponds to requested Object type
128 /// Thid method is used in any selection mode
129 /// \param theObject an object
130 virtual bool acceptObjectType(const ObjectPtr theObject) const;
133 // Set the given object as a value of the widget
134 /// \param theObj an object
135 /// \param theShape a shape
136 void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
138 /// Check the selected with validators if installed
139 /// \param theObj the object for checking
140 /// \param theShape the shape for checking
141 virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
144 void clearAttribute();
146 /// Fills the given list with all widget filters. It can be used by activation widget for the viewer
147 /// or by checking the selection parameter in addition to check validity of the selection argument
148 /// It creates an object type filter if it has not been created yet and save it in the class field
149 /// \param theFilters a list of filter
150 void selectionFilters(SelectMgr_ListOfFilter& theFilters);
152 //----------- Class members -------------
154 /// Label of the widget
157 /// Input control of the widget
158 QLineEdit* myTextLine;
160 /// Reference to workshop
161 ModuleBase_IWorkshop* myWorkshop;
163 /// Pointer to selected object
164 ObjectPtr mySelectedObject;
166 /// Pointer to selected shape
167 GeomShapePtr myShape;
169 /// List of accepting shapes types
170 QStringList myShapeTypes;
172 /// List of accepting object types
173 QStringList myObjectTypes;
175 /// Active/inactive flag
178 /// Filter by objects types
179 Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;