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_WidgetValidated.h"
12 #include "ModuleBase_ViewerFilters.h"
14 #include <ModelAPI_Object.h>
15 #include <GeomAPI_Shape.h>
17 #include <TopAbs_ShapeEnum.hxx>
19 #include <QStringList>
21 class Config_WidgetAPI;
26 class ModuleBase_IWorkshop;
30 * Implementation of widget for shapes selection.
31 * This type of widget can be defined in XML file with 'shape_selector' keyword.
34 * <shape_selector id="main_object"
36 * icon=":icons/cut_shape.png"
37 * tooltip="Select an object solid"
38 * shape_types="solid shell"
42 * It can use following parameters:
43 * - id - name of object attribute
44 * - label - content of widget's label
45 * - icon - icon which can be used instead label
46 * - tooltip - the witget's tooltip text
47 * - shape_types - list of shape types for selection.
48 * Possible values: face, vertex, wire, edge, shell, solid
49 * - object_types - types of selectable objects.
50 * For today it supports only one type "construction"
51 * which corresponds to ModelAPI_ResultConstruction object type
52 * - concealment - hide or not hide selected object after operation
54 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
59 /// Converts string value (name of shape type) to shape enum value
60 /// \param theType - string with shape type name
61 /// \return TopAbs_ShapeEnum value
62 static TopAbs_ShapeEnum shapeType(const QString& theType);
65 /// \param theParent the parent object
66 /// \param theWorkshop instance of workshop interface
67 /// \param theData the widget configuation. The attribute of the model widget is obtained from
68 /// \param theParentId is Id of a parent of the current attribute
69 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
70 const Config_WidgetAPI* theData, const std::string& theParentId);
72 virtual ~ModuleBase_WidgetShapeSelector();
74 virtual bool restoreValue();
76 /// Defines if it is supposed that the widget should interact with the viewer.
77 virtual bool isViewerSelector() { return true; }
79 /// Returns list of widget controls
80 /// \return a control list
81 virtual QList<QWidget*> getControls() const;
83 /// Set the given wrapped value to the current widget
84 /// This value should be processed in the widget according to the needs
85 /// \param theValue the wrapped widget value
86 virtual bool setSelection(ModuleBase_ViewerPrs theValue);
88 /// The methiod called when widget is deactivated
89 virtual void deactivate();
91 // Get the object from the attribute
92 /// \param theObj an object
93 static ObjectPtr getObject(const AttributePtr& theAttribute) const;
97 /// Activate or deactivate selection
98 void activateSelection(bool toActivate);
101 /// Slot which is called on selection event
102 void onSelectionChanged();
105 /// Saves the internal parameters to the given feature
106 /// \return True in success
107 virtual bool storeValueCustom() const;
109 /// The methiod called when widget is activated
110 virtual void activateCustom();
112 /// Computes and updates name of selected object in the widget
113 void updateSelectionName();
115 /// Raise panel which contains this widget
116 void raisePanel() const;
118 /// Returns true if selected shape corresponds to requested shape types
119 /// \param theShape a shape
120 virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
122 // Set the given object as a value of the widget
123 /// \param theObj an object
124 /// \param theShape a shape
125 void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
127 // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
129 GeomShapePtr getShape() const;
131 /// Check the selected with validators if installed
132 /// \param theObj the object for checking
133 /// \param theShape the shape for checking
134 virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
137 void clearAttribute();
139 /// Store the values to the model attribute of the widget. It casts this attribute to
140 /// the specific type and set the given values
141 /// \param theSelectedObject an object
142 /// \param theShape a selected shape, which is used in the selection attribute
143 virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
145 //----------- Class members -------------
147 /// Label of the widget
150 /// Input control of the widget
151 QLineEdit* myTextLine;
153 /// Reference to workshop
154 ModuleBase_IWorkshop* myWorkshop;
156 /// List of accepting shapes types
157 QStringList myShapeTypes;
159 /// Active/inactive flag