Salome HOME
It provides error messages for validators.
[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_Feature.h>
14 #include <TopAbs_ShapeEnum.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <Prs3d_Drawer.hxx>
17
18 #include <Quantity_Color.hxx>
19
20 #include <QPixmap>
21
22 class QWidget;
23 class QLayout;
24 class QDoubleSpinBox;
25 class ModuleBase_ParamSpinBox;
26
27 namespace ModuleBase_Tools {
28
29 /*
30  * Methods to adjust margins and spacings.
31  */
32 MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
33 MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
34
35 MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
36 MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
37
38
39 /**
40  * \ingroup GUI
41  * Methods to modify a resource pixmap
42  */
43
44 //! Create composite pixmap. 
45 //! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
46 //! specified relatively to the upper left corner of \a theIcon.
47
48 //! \param theAdditionalIcon resource text of the additional pixmap
49 //! \param theIcon resource text of the background pixmap
50 //! \return resulting pixmap
51 MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon);
52
53 //! Generates the pixmap lighter than the resources pixmap. 
54 //! Pixmap \a theIcon is lighted according to the given value.
55 //! If the lighter value is greater than 100, this functions returns a lighter pixmap.
56 //! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
57 //! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
58
59 //! \param resource text of the pixmap
60 //! \param theLighterValue a lighter factor
61 //! \return resulting pixmap
62 MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
63
64 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
65 /// \param theSpin an X or Y coordinate widget
66 /// \param theValue a new value
67 MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue);
68
69 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
70 /// \param theSpin an X or Y coordinate widget
71 /// \param theValue a new value
72 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue);
73
74 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
75 /// \param theSpin an ModuleBase_ParamSpinBox that accepts text
76 /// \param theText a new value
77 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText);
78
79 /// Converts the object to the feature or a result and generate information string
80 /// \param theObj an object
81 /// \param isUseAttributesInfo a flag whether the attribute values information is used
82 /// \return a string
83 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
84
85 /// Converts string value (name of shape type) to shape enum value
86 /// \param theType - string with shape type name
87 /// \return TopAbs_ShapeEnum value
88 MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType);
89
90 /// Checks whether the object is a sub result. It gets the feature of the object,
91 /// obtains all results of the feature and check if the object is a sub result
92 /// \return boolean result
93 MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject);
94
95 /*!
96 Check types of objects which are in the given list
97 \param theObjects the list of objects
98 \param hasResult will be set to true if list contains Result objects
99 \param hasFeature will be set to true if list contains Feature objects
100 \param hasParameter will be set to true if list contains Parameter objects
101 \param hasSubFeature will be set to true if list contains Sub-Feature objects
102 */
103 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
104                            bool& hasFeature, bool& hasParameter, bool& hasSubFeature);
105
106 /*! Sets the default coeffient into the driver calculated accordingly the shape type.
107 It provides 1.e-4 for a shape withe Edge shape type
108 \param theShape a shape to define the deviation coeffient, 
109 \return double value
110 */
111 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
112                                                       const Handle(Prs3d_Drawer)& theDrawer);
113
114 /*! Obtains the color from the property manager and converts it to the OCCT color
115 \param theSection a property section
116 \param theName a property item name
117 \param theDefault a default color value
118 \return quantity color
119 */
120 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
121                                        const std::string& theName,
122                                        const std::string& theDefault);
123 }
124
125 #endif