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