Salome HOME
Selection correction for "objects" type defined in XML. It is not possible to use...
[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 #include <AIS_Shape.hxx>
20
21 #include <Quantity_Color.hxx>
22
23 #include <QIcon>
24 #include <QPixmap>
25
26 #include <map>
27
28 class Handle_AIS_InteractiveContext;
29
30 class QWidget;
31 class QLayout;
32 class QDoubleSpinBox;
33 class QAction;
34 class ModuleBase_ParamIntSpinBox;
35 class ModuleBase_ParamSpinBox;
36 class ModuleBase_IWorkshop;
37
38 class GeomAPI_Shape;
39
40 namespace ModuleBase_Tools {
41
42 /// Methods to adjust margins and spacings.
43 MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
44 MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
45
46 MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
47 MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
48
49 /// Calls the same-named Qt method for the given widget.
50 /// It sets the top-level widget containing this widget to be the active window.
51 /// An active window is a visible top-level window that has the keyboard input focus.
52 /// \param theWidget a widget to be activated
53 /// \param theIndo a debug information
54 MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString());
55
56 /// Calls the same-named Qt method for the given widget.
57 /// Gives the keyboard input focus to this widget (or its focus proxy) if this widget or
58 /// one of its parents is the active window.
59 /// \param theWidget a widget to be activated
60 /// \param theIndo a debug information
61 MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString());
62
63
64 /// Sets or removes the shadow effect to the widget
65 /// \param theWidget a widget to be styled
66 /// \param isSetEffect if true, the shadow effect is set, overwise cleared
67 /// \return resulting pixmap
68 MODULEBASE_EXPORT void setShadowEffect(QWidget* theWidget, const bool isSetEffect);
69
70 /// \ingroup GUI
71 /// Methods to modify a resource pixmap
72
73 /// Create composite pixmap. 
74 /// Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
75 /// specified relatively to the upper left corner of \a theIcon.
76
77 /// \param theAdditionalIcon resource text of the additional pixmap
78 /// \param theIcon resource text of the background pixmap
79 /// \return resulting pixmap
80 MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon);
81
82 /// Generates the pixmap lighter than the resources pixmap. 
83 /// Pixmap \a theIcon is lighted according to the given value.
84 /// If the lighter value is greater than 100, this functions returns a lighter pixmap.
85 /// Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
86 /// the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
87
88 /// \param resource text of the pixmap
89 /// \param theLighterValue a lighter factor
90 /// \return resulting pixmap
91 MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
92
93 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
94 /// \param theSpin an X or Y coordinate widget
95 /// \param theValue a new value
96 MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue);
97
98 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
99 /// \param theSpin an X or Y coordinate widget
100 /// \param theValue a new value
101 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue);
102
103 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
104 /// \param theSpin an ModuleBase_ParamSpinBox that accepts text
105 /// \param theText a new value
106 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText);
107
108 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
109 /// \param theSpin a ModuleBase_ParamIntSpinBox object
110 /// \param theValue a new value
111 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue);
112
113 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
114 /// \param theSpin a SpinBox that accepts text
115 /// \param theText a new value
116 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText);
117
118 /// Creates an action filled with the parameters
119 /// \param theIcon an action icon
120 /// \param theText an icon text
121 /// \param theParent an action object
122 /// \param theReceiver an object to process action triggered signal
123 /// \param theMember a slot to process the action triggered signal
124 /// \param theToolTip an action tool tip information, if empty the text is used
125 /// \param theStatusTip an action status tip information, if empty the text is used
126 MODULEBASE_EXPORT QAction* createAction(const QIcon& theIcon, const QString& theText,
127                                         QObject* theParent, const QObject* theReceiver = 0,
128                                         const char* theMember = "",
129                                         const QString& theToolTip = QString(),
130                                         const QString& theStatusTip = QString());
131
132 /// Converts the object to the feature or a result and generate information string
133 /// \param theObj an object
134 /// \param isUseAttributesInfo a flag whether the attribute values information is used
135 /// \return a string
136 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
137
138 /// Converts the AIS context information in a string information.
139 /// \param theContext a viewer context
140 /// \param thePrefix additional information where the method is called
141 MODULEBASE_EXPORT void selectionInfo(Handle_AIS_InteractiveContext& theContext,
142                                      const std::string& thePrefix);
143
144 /// Converts string value (name of shape type) to shape enum value
145 /// \param theType - string with shape type name
146 /// \return TopAbs_ShapeEnum value
147 MODULEBASE_EXPORT int shapeType(const QString& theType);
148
149 /// Checks whether the object is a sub result. It gets the feature of the object,
150 /// obtains all results of the feature and check if the object is a sub result
151 /// \return boolean result
152 MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject);
153
154 /// Check types of objects which are in the given list
155 /// \param theObjects the list of objects
156 /// \param hasResult will be set to true if list contains Result objects
157 /// \param hasFeature will be set to true if list contains Feature objects
158 /// \param hasParameter will be set to true if list contains Parameter objects
159 /// \param hasCompositeOwner will be set to true if list contains Sub-Feature objects
160 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
161                            bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner);
162
163 /// Sets the default coeffient into the driver calculated accordingly the shape type.
164 /// It provides 1.e-4 for results of construction type
165 /// \param theResult a result object to define the deviation coeffient
166 /// \param theDrawer a drawer
167 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(
168                            const std::shared_ptr<ModelAPI_Result>& theResult,
169                            const Handle(Prs3d_Drawer)& theDrawer);
170
171 /// Sets the default coeffient into the driver calculated accordingly the shape type.
172 /// It provides 1.e-4 for a shape withe Edge shape type
173 /// \param theShape a shape to define the deviation coeffient, 
174 /// \param theDrawer a drawer
175 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
176                                                       const Handle(Prs3d_Drawer)& theDrawer);
177
178 /// Obtains the color from the property manager and converts it to the OCCT color
179 /// \param theSection a property section
180 /// \param theName a property item name
181 /// \param theDefault a default color value
182 /// \return quantity color
183 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
184                                        const std::string& theName,
185                                        const std::string& theDefault);
186
187 /// Returns the object from the attribute
188 /// \param theObj an object
189 MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
190
191 /// Returns the object from the attribute
192 /// \param theObj an object
193 MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
194
195 /// Returns list of parameters accessible in the active part and partset
196 /// \theParameters a list of parameter names
197 MODULEBASE_EXPORT void getParameters(QStringList& theParameters);
198
199 /// Returns list of parameters accessible in the active part and partset
200 /// \theParameters a list of parameter names
201 MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
202                                                  const FeaturePtr& theFeature);
203
204 /// Set the object to the attribute depending on the attribute type. If it is a list,
205 /// the values are appended if they are not in the list yet.
206 /// \param theAttribute an attribute where the object and shape are set
207 /// \param theObject an object
208 /// \param theShape a shape
209 /// \param theWorkshop to find an attribute for the given shape for attribute reference
210 /// \param theTemporarily if it is true, do not store and name the added in the data framework
211 ///        It is useful for attribute selection
212 MODULEBASE_EXPORT bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
213                                  const std::shared_ptr<GeomAPI_Shape>& theShape,
214                                  ModuleBase_IWorkshop* theWorkshop,
215                                  const bool theTemporarily);
216
217 /// Set the object to the attribute depending on the attribute type. If it is a list,
218 /// the values are appended if they are not in the list yet.
219 /// \param theAttribute an attribute where the object and shape are set
220 /// \param theObject an object
221 /// \param theShape a shape
222 /// \param theWorkshop to find an attribute for the given shape for attribute reference
223 /// \param theTemporarily if it is true, do not store and name the added in the data framework
224 /// \param theCheckIfAttributeHasObject if it is true, the check isInList is called
225 ///        It is useful for attribute selection
226 MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
227                                  const std::shared_ptr<GeomAPI_Shape>& theShape,
228                                  ModuleBase_IWorkshop* theWorkshop,
229                                  const bool theTemporarily,
230                                  const bool theCheckIfAttributeHasObject);
231
232 /// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found
233 /// using current module of the given workshop.
234 /// \param theAttribute an attribute where the shape is set
235 /// \param theWorkshop to find a shape for the given attribute
236 MODULEBASE_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(const AttributePtr& theAttribute,
237                                                           ModuleBase_IWorkshop* theWorkshop);
238
239 /// Flush updated signal for the object. The viewer update is blocked in the process
240 /// \param theObject parameter of the signal
241 MODULEBASE_EXPORT void flushUpdated(ObjectPtr theObject);
242
243 /// Sends a message about block/unblock viewer updating
244 /// \param theValue a boolean value
245 MODULEBASE_EXPORT void blockUpdateViewer(const bool theValue);
246
247 /// Generates a wrapped string to be less than value with '\n' separators
248 /// \param theValue a boolean value
249 /// \param theWidget a widget to know the font
250 /// \param theMaxLineInPixels a maximum line width in pixels
251 MODULEBASE_EXPORT QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
252                                              int theMaxLineInPixels = 150);
253
254 /// Returns a container of referenced feature to the current object in the object document.
255 /// \param theObject an object, which will be casted to a feature type
256 /// \param theRefFeatures an output container
257 void MODULEBASE_EXPORT refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
258                                                       std::set<FeaturePtr>& theRefFeatures);
259
260
261 /// Returns true if the object if a sub child of the feature. The feature is casted to the
262 /// composite one. If it is possible, the sub object check happens. The method is applyed
263 /// recursively to the feature subs.
264 /// \param theObject a candidate to be a sub object
265 /// \param theFeature a candidate to be a composite feature
266 /// \return a boolean value
267 //bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature);
268
269
270 /// Returns true if the result is a sub object of some composite object
271 /// \param theObject a result object
272 /// \returns boolean value
273 //bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject);
274
275
276 /// Returns first result of the feature: the object itself if it is a result of
277 /// first result of the object's feature
278 /// \param theObject an object
279 /// \return first result or NULL
280 std::shared_ptr<ModelAPI_Result> MODULEBASE_EXPORT firstResult(const ObjectPtr& theObject);
281
282 /// Returns true if the list contains at least one feature from the module document(PartSet)
283 /// The Part features are skipped.
284 /// \param theFeatures a list of features
285 /// \bool true if it is found
286 bool MODULEBASE_EXPORT hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures);
287
288 /// Shows a dialog box about references. Ask whether they should be also removed.
289 /// \param theFeatures a list of features
290 /// \param theReferences a map of all references to the features
291 /// \param theParent a parent widget for the question message box
292 /// \param theReferencesToDelete an out set for references features to be removed
293 /// \return true if in message box answer is Yes
294 bool MODULEBASE_EXPORT askToDelete(const std::set<FeaturePtr> aFeatures,
295                                    const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
296                                    QWidget* theParent,
297                                    std::set<FeaturePtr>& theReferencesToDelete);
298
299 /// Converts a list of objects to set of corresponded features. If object is result, it is ingored
300 /// because the feauture only might be removed. But if result is in a parameter group, the feature
301 /// of this parameter is to be removed
302 /// \param theObjects a list of objects
303 /// \param theFeatures an out conteiner of features
304 void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures);
305
306
307 /// Returns translation from the given data.
308 /// If translation is not exists then it returns a string 
309 /// from the info data without translation
310 /// \param theContext context of the message (Feature Id)
311 /// \param theMessage a message which dave to be translated
312 /// \param theParams a list of parameters (can be empty)
313 void MODULEBASE_EXPORT translate(const std::string& theContext, std::string& theMessage);
314
315 /// Set Highlighting of points as a Ball shape
316 /// \param theAIS - the presentation
317 void MODULEBASE_EXPORT setPointBallHighlighting(AIS_Shape* theAIS);
318
319 }
320
321 #endif