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_WidgetSelector.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;
33 * Implementation of widget for shapes selection.
34 * This type of widget can be defined in XML file with 'shape_selector' keyword.
37 * <shape_selector id="main_object"
39 * icon=":icons/cut_shape.png"
40 * tooltip="Select an object solid"
41 * shape_types="solid shell"
45 * It can use following parameters:
46 * - id - name of object attribute
47 * - label - content of widget's label
48 * - icon - icon which can be used instead label
49 * - tooltip - the witget's tooltip text
50 * - shape_types - list of shape types for selection.
51 * Possible values: face, vertex, wire, edge, shell, solid
52 * - object_types - types of selectable objects.
53 * For today it supports only one type "construction"
54 * which corresponds to ModelAPI_ResultConstruction object type
55 * - concealment - hide or not hide selected object after operation
57 class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
63 /// \param theParent the parent object
64 /// \param theWorkshop instance of workshop interface
65 /// \param theData the widget configuation. The attribute of the model widget is obtained from
66 /// \param theParentId is Id of a parent of the current attribute
67 ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
68 const Config_WidgetAPI* theData, const std::string& theParentId);
70 virtual ~ModuleBase_WidgetShapeSelector();
72 /// Returns list of widget controls
73 /// \return a control list
74 virtual QList<QWidget*> getControls() const;
77 /// Saves the internal parameters to the given feature
78 /// \return True in success
79 virtual bool storeValueCustom() const;
81 virtual bool restoreValueCustom();
83 /// Creates a backup of the current values of the attribute
84 /// It should be realized in the specific widget because of different
85 /// parameters of the current attribute
86 virtual void storeAttributeValue();
88 /// Creates a backup of the current values of the attribute
89 /// It should be realized in the specific widget because of different
90 /// parameters of the current attribute
91 /// \param theValid a boolean flag, if restore happens for valid parameters
92 virtual void restoreAttributeValue(const bool theValid);
94 /// Computes and updates name of selected object in the widget
95 virtual void updateSelectionName();
97 // Update focus after the attribute value change
98 virtual void updateFocus();
100 /// Retunrs a list of possible shape types
101 /// \return a list of shapes
102 virtual QIntList getShapeTypes() const;
104 /// Store the values to the model attribute of the widget. It casts this attribute to
105 /// the specific type and set the given values
106 /// \param theSelectedObject an object
107 /// \param theShape a selected shape, which is used in the selection attribute
108 /// \return true if it is succeed
109 virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
111 /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
113 virtual GeomShapePtr getShape() const;
115 /// Return the attribute values wrapped in a list of viewer presentations
116 /// \return a list of viewer presentations, which contains an attribute result and
117 /// a shape. If the attribute do not uses the shape, it is empty
118 virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
120 //----------- Class members -------------
122 /// Label of the widget
125 /// Input control of the widget
126 QLineEdit* myTextLine;
128 /// List of accepting shapes types
129 QStringList myShapeTypes;
131 /// backup parameters of the model attribute. The class processes three types of attribute:
132 /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
133 /// values are reserved in the backup
134 /// An attribute object
136 /// An attribute shape
137 GeomShapePtr myShape;
138 /// A reference of the attribute
139 AttributePtr myRefAttribute;
140 /// A boolean value whether refAttr uses reference of object