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