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"
13 #include <ModuleBase_ViewerPrs.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Attribute.h>
17 #include <GeomAPI_Shape.h>
19 #include <TopAbs_ShapeEnum.hxx>
21 #include <QStringList>
23 class Config_WidgetAPI;
28 class ModuleBase_IWorkshop;
32 * Implementation of widget for shapes selection.
33 * This type of widget can be defined in XML file with 'shape_selector' keyword.
36 * <shape_selector id="main_object"
38 * icon=":icons/cut_shape.png"
39 * tooltip="Select an object solid"
40 * shape_types="solid shell"
44 * It can use following parameters:
45 * - id - name of object attribute
46 * - label - content of widget's label
47 * - icon - icon which can be used instead label
48 * - tooltip - the witget's tooltip text
49 * - shape_types - list of shape types for selection.
50 * Possible values: face, vertex, wire, edge, shell, solid
51 * - object_types - types of selectable objects.
52 * For today it supports only one type "construction"
53 * which corresponds to ModelAPI_ResultConstruction object type
54 * - concealment - hide or not hide selected object after operation
56 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
61 /// Converts string value (name of shape type) to shape enum value
62 /// \param theType - string with shape type name
63 /// \return TopAbs_ShapeEnum value
64 static TopAbs_ShapeEnum shapeType(const QString& theType);
67 /// \param theParent the parent object
68 /// \param theWorkshop instance of workshop interface
69 /// \param theData the widget configuation. The attribute of the model widget is obtained from
70 /// \param theParentId is Id of a parent of the current attribute
71 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
72 const Config_WidgetAPI* theData, const std::string& theParentId);
74 virtual ~ModuleBase_WidgetShapeSelector();
76 virtual bool restoreValue();
78 /// Defines if it is supposed that the widget should interact with the viewer.
79 virtual bool isViewerSelector() { return true; }
81 /// Returns list of widget controls
82 /// \return a control list
83 virtual QList<QWidget*> getControls() const;
85 /// Fills the attribute with the value of the selected owner
86 /// \param theOwner a selected owner
87 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
89 /// The methiod called when widget is deactivated
90 virtual void deactivate();
94 /// Activate or deactivate selection
95 void activateSelection(bool toActivate);
98 /// Slot which is called on selection event
99 void onSelectionChanged();
102 /// Saves the internal parameters to the given feature
103 /// \return True in success
104 virtual bool storeValueCustom() const;
106 /// The methiod called when widget is activated
107 virtual void activateCustom();
109 /// Creates a backup of the current values of the attribute
110 /// It should be realized in the specific widget because of different
111 /// parameters of the current attribute
112 virtual void storeAttributeValue();
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 /// \param theValid a boolean flag, if restore happens for valid parameters
118 virtual void restoreAttributeValue(const bool theValid);
120 /// Computes and updates name of selected object in the widget
121 void updateSelectionName();
123 /// Raise panel which contains this widget
124 void raisePanel() const;
126 /// Returns true if selected shape corresponds to requested shape types
127 /// \param theShape a shape
128 virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
130 // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
132 GeomShapePtr getShape() const;
135 void clearAttribute();
137 /// Store the values to the model attribute of the widget. It casts this attribute to
138 /// the specific type and set the given values
139 /// \param theSelectedObject an object
140 /// \param theShape a selected shape, which is used in the selection attribute
141 /// \return true if it is succeed
142 virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
144 //----------- Class members -------------
146 /// Label of the widget
149 /// Input control of the widget
150 QLineEdit* myTextLine;
152 /// Reference to workshop
153 ModuleBase_IWorkshop* myWorkshop;
155 /// List of accepting shapes types
156 QStringList myShapeTypes;
158 /// Active/inactive flag
161 /// backup parameters of the model attribute. The class processes three types of attribute:
162 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
163 /// values are reserved in the backup
164 /// An attribute object
166 /// An attribute shape
167 GeomShapePtr myShape;
168 /// A reference of the attribute
169 AttributePtr myRefAttribute;
170 /// A boolean value whether refAttr uses reference of object