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