Salome HOME
7aa9f9d647ed3fb71fc71110976eb40b9eae6a1d
[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  * \ingroup GUI
60  * Methods to modify a resource pixmap
61  */
62
63 //! Create composite pixmap. 
64 //! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
65 //! specified relatively to the upper left corner of \a theIcon.
66
67 //! \param theAdditionalIcon resource text of the additional pixmap
68 //! \param theIcon resource text of the background pixmap
69 //! \return resulting pixmap
70 MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon);
71
72 //! Generates the pixmap lighter than the resources pixmap. 
73 //! Pixmap \a theIcon is lighted according to the given value.
74 //! If the lighter value is greater than 100, this functions returns a lighter pixmap.
75 //! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
76 //! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
77
78 //! \param resource text of the pixmap
79 //! \param theLighterValue a lighter factor
80 //! \return resulting pixmap
81 MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
82
83 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
84 /// \param theSpin an X or Y coordinate widget
85 /// \param theValue a new value
86 MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue);
87
88 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
89 /// \param theSpin an X or Y coordinate widget
90 /// \param theValue a new value
91 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue);
92
93 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
94 /// \param theSpin an ModuleBase_ParamSpinBox that accepts text
95 /// \param theText a new value
96 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText);
97
98 /// Converts the object to the feature or a result and generate information string
99 /// \param theObj an object
100 /// \param isUseAttributesInfo a flag whether the attribute values information is used
101 /// \return a string
102 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
103
104 /// Converts string value (name of shape type) to shape enum value
105 /// \param theType - string with shape type name
106 /// \return TopAbs_ShapeEnum value
107 MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType);
108
109 /// Checks whether the object is a sub result. It gets the feature of the object,
110 /// obtains all results of the feature and check if the object is a sub result
111 /// \return boolean result
112 MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject);
113
114 /*!
115 Check types of objects which are in the given list
116 \param theObjects the list of objects
117 \param hasResult will be set to true if list contains Result objects
118 \param hasFeature will be set to true if list contains Feature objects
119 \param hasParameter will be set to true if list contains Parameter objects
120 \param hasSubFeature will be set to true if list contains Sub-Feature objects
121 */
122 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
123                            bool& hasFeature, bool& hasParameter, bool& hasSubFeature);
124
125 /*! Sets the default coeffient into the driver calculated accordingly the shape type.
126 It provides 1.e-4 for a shape withe Edge shape type
127 \param theShape a shape to define the deviation coeffient, 
128 \param theDrawer a drawer
129 */
130 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
131                                                       const Handle(Prs3d_Drawer)& theDrawer);
132
133 /*! Obtains the color from the property manager and converts it to the OCCT color
134 \param theSection a property section
135 \param theName a property item name
136 \param theDefault a default color value
137 \return quantity color
138 */
139 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
140                                        const std::string& theName,
141                                        const std::string& theDefault);
142
143
144 // Returns the object from the attribute
145 /// \param theObj an object
146 MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
147
148 // Returns the object from the attribute
149 /// \param theObj an object
150 MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
151
152 }
153
154 #endif