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;
29 class ModelAPI_Validator;
30 class GeomValidators_ShapeType;
34 * Implementation of widget for shapes selection.
35 * This type of widget can be defined in XML file with 'shape_selector' keyword.
38 * <shape_selector id="main_object"
40 * icon=":icons/cut_shape.png"
41 * tooltip="Select an object solid"
42 * shape_types="solid shell"
46 * It can use following parameters:
47 * - id - name of object attribute
48 * - label - content of widget's label
49 * - icon - icon which can be used instead label
50 * - tooltip - the witget's tooltip text
51 * - shape_types - list of shape types for selection.
52 * Possible values: face, vertex, wire, edge, shell, solid
53 * - object_types - types of selectable objects.
54 * For today it supports only one type "construction"
55 * which corresponds to ModelAPI_ResultConstruction object type
56 * - concealment - hide or not hide selected object after operation
58 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetValidated
64 /// \param theParent the parent object
65 /// \param theWorkshop instance of workshop interface
66 /// \param theData the widget configuation. The attribute of the model widget is obtained from
67 /// \param theParentId is Id of a parent of the current attribute
68 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
69 const Config_WidgetAPI* theData, const std::string& theParentId);
71 virtual ~ModuleBase_WidgetShapeSelector();
73 virtual bool restoreValue();
75 /// Defines if it is supposed that the widget should interact with the viewer.
76 virtual bool isViewerSelector() { return true; }
78 /// Returns list of widget controls
79 /// \return a control list
80 virtual QList<QWidget*> getControls() const;
82 /// Checks the widget validity. By default, it returns true.
83 /// \param theValue a selected presentation in the view
84 /// \return a boolean value
85 virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
87 /// Fills the attribute with the value of the selected owner
88 /// \param theOwner a selected owner
89 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
91 /// The methiod called when widget is deactivated
92 virtual void deactivate();
95 /// Activate or deactivate selection
96 void activateSelection(bool toActivate);
99 /// Slot which is called on selection event
100 void onSelectionChanged();
103 /// Saves the internal parameters to the given feature
104 /// \return True in success
105 virtual bool storeValueCustom() const;
107 /// The methiod called when widget is activated
108 virtual void activateCustom();
110 /// Creates a backup of the current values of the attribute
111 /// It should be realized in the specific widget because of different
112 /// parameters of the current attribute
113 virtual void storeAttributeValue();
115 /// Creates a backup of the current values of the attribute
116 /// It should be realized in the specific widget because of different
117 /// parameters of the current attribute
118 /// \param theValid a boolean flag, if restore happens for valid parameters
119 virtual void restoreAttributeValue(const bool theValid);
121 /// Computes and updates name of selected object in the widget
122 void updateSelectionName();
124 /// Raise panel which contains this widget
125 void raisePanel() const;
127 /// Returns true if selected shape corresponds to requested shape types
128 /// \param theShape a shape
129 bool acceptSubShape(const TopoDS_Shape& theShape) const;
132 void clearAttribute();
134 /// Store the values to the model attribute of the widget. It casts this attribute to
135 /// the specific type and set the given values
136 /// \param theSelectedObject an object
137 /// \param theShape a selected shape, which is used in the selection attribute
138 /// \return true if it is succeed
139 virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
141 /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
143 virtual GeomShapePtr getShape() const;
145 /// Return the attribute values wrapped in a list of viewer presentations
146 /// \return a list of viewer presentations, which contains an attribute result and
147 /// a shape. If the attribute do not uses the shape, it is empty
148 QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
150 /// Return an object and geom shape by the viewer presentation
151 /// \param thePrs a selection
152 /// \param theObject an output object
153 /// \param theShape a shape of the selection
154 virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
155 ObjectPtr& theObject,
156 GeomShapePtr& theShape);
158 //----------- Class members -------------
160 /// Label of the widget
163 /// Input control of the widget
164 QLineEdit* myTextLine;
166 /// Reference to workshop
167 ModuleBase_IWorkshop* myWorkshop;
169 /// List of accepting shapes types
170 QStringList myShapeTypes;
172 /// backup parameters of the model attribute. The class processes three types of attribute:
173 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
174 /// values are reserved in the backup
175 /// An attribute object
177 /// An attribute shape
178 GeomShapePtr myShape;
179 /// A reference of the attribute
180 AttributePtr myRefAttribute;
181 /// A boolean value whether refAttr uses reference of object
184 /// An instance of the "shape_type" validator. It is returns on validating in customValidator()
185 GeomValidators_ShapeType* myShapeValidator;