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