Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_Tools.h
4 // Created:     11 July 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef ModuleBase_Tools_H
8 #define ModuleBase_Tools_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_Definitions.h"
12
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_Feature.h>
15
16 #include <TopAbs_ShapeEnum.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <Prs3d_Drawer.hxx>
19
20 #include <Quantity_Color.hxx>
21
22 #include <QPixmap>
23
24 class QWidget;
25 class QLayout;
26 class QDoubleSpinBox;
27 class ModuleBase_ParamIntSpinBox;
28 class ModuleBase_ParamSpinBox;
29 class ModuleBase_IWorkshop;
30
31 namespace ModuleBase_Tools {
32
33 /*
34  * Methods to adjust margins and spacings.
35  */
36 MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
37 MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
38
39 MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
40 MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
41
42 /*
43  * Calls the same-named Qt method for the given widget.
44  * It sets the top-level widget containing this widget to be the active window.
45  * An active window is a visible top-level window that has the keyboard input focus.
46  * \param theWidget a widget to be activated
47  * \param theIndo a debug information
48  */
49 MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString());
50
51 /*
52  * Calls the same-named Qt method for the given widget.
53  * Gives the keyboard input focus to this widget (or its focus proxy) if this widget or
54  * one of its parents is the active window.
55  * \param theWidget a widget to be activated
56  * \param theIndo a debug information
57  */
58 MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString());
59
60
61 //! Sets or removes the shadow effect to the widget
62 //! \param theWidget a widget to be styled
63 //! \param isSetEffect if true, the shadow effect is set, overwise cleared
64 //! \return resulting pixmap
65 MODULEBASE_EXPORT void setShadowEffect(QWidget* theWidget, const bool isSetEffect);
66
67 /**
68  * \ingroup GUI
69  * Methods to modify a resource pixmap
70  */
71
72 //! Create composite pixmap. 
73 //! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
74 //! specified relatively to the upper left corner of \a theIcon.
75
76 //! \param theAdditionalIcon resource text of the additional pixmap
77 //! \param theIcon resource text of the background pixmap
78 //! \return resulting pixmap
79 MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon);
80
81 //! Generates the pixmap lighter than the resources pixmap. 
82 //! Pixmap \a theIcon is lighted according to the given value.
83 //! If the lighter value is greater than 100, this functions returns a lighter pixmap.
84 //! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
85 //! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
86
87 //! \param resource text of the pixmap
88 //! \param theLighterValue a lighter factor
89 //! \return resulting pixmap
90 MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
91
92 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
93 /// \param theSpin an X or Y coordinate widget
94 /// \param theValue a new value
95 MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue);
96
97 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
98 /// \param theSpin an X or Y coordinate widget
99 /// \param theValue a new value
100 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue);
101
102 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
103 /// \param theSpin an ModuleBase_ParamSpinBox that accepts text
104 /// \param theText a new value
105 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText);
106
107 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
108 /// \param theSpin a ModuleBase_ParamIntSpinBox object
109 /// \param theValue a new value
110 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue);
111
112 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
113 /// \param theSpin a SpinBox that accepts text
114 /// \param theText a new value
115 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText);
116
117 /// Converts the object to the feature or a result and generate information string
118 /// \param theObj an object
119 /// \param isUseAttributesInfo a flag whether the attribute values information is used
120 /// \return a string
121 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
122
123 /// Converts string value (name of shape type) to shape enum value
124 /// \param theType - string with shape type name
125 /// \return TopAbs_ShapeEnum value
126 MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType);
127
128 /// Checks whether the object is a sub result. It gets the feature of the object,
129 /// obtains all results of the feature and check if the object is a sub result
130 /// \return boolean result
131 MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject);
132
133 /*!
134 Check types of objects which are in the given list
135 \param theObjects the list of objects
136 \param hasResult will be set to true if list contains Result objects
137 \param hasFeature will be set to true if list contains Feature objects
138 \param hasParameter will be set to true if list contains Parameter objects
139 \param hasSubFeature will be set to true if list contains Sub-Feature objects
140 */
141 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
142                            bool& hasFeature, bool& hasParameter, bool& hasSubFeature);
143
144 /*! Sets the default coeffient into the driver calculated accordingly the shape type.
145 It provides 1.e-4 for a shape withe Edge shape type
146 \param theShape a shape to define the deviation coeffient, 
147 \param theDrawer a drawer
148 */
149 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
150                                                       const Handle(Prs3d_Drawer)& theDrawer);
151
152 /*! Obtains the color from the property manager and converts it to the OCCT color
153 \param theSection a property section
154 \param theName a property item name
155 \param theDefault a default color value
156 \return quantity color
157 */
158 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
159                                        const std::string& theName,
160                                        const std::string& theDefault);
161
162
163 /// Returns the object from the attribute
164 /// \param theObj an object
165 MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
166
167 /// Returns the object from the attribute
168 /// \param theObj an object
169 MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
170
171 /// Returns list of parameters accessible in the active part and partset
172 /// \theParameters a list of parameter names
173 MODULEBASE_EXPORT void getParameters(QStringList& theParameters);
174
175 /// Returns list of parameters accessible in the active part and partset
176 /// \theParameters a list of parameter names
177 MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
178                                                  const FeaturePtr& theFeature);
179 }
180
181 #endif