1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_Tools.h
4 // Created: 11 July 2014
5 // Author: Vitaly Smetannikov
7 #ifndef ModuleBase_Tools_H
8 #define ModuleBase_Tools_H
10 #include "ModuleBase.h"
11 #include "ModuleBase_Definitions.h"
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_Feature.h>
16 #include <TopAbs_ShapeEnum.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <Prs3d_Drawer.hxx>
20 #include <Quantity_Color.hxx>
27 class Handle_AIS_InteractiveContext;
33 class ModuleBase_ParamIntSpinBox;
34 class ModuleBase_ParamSpinBox;
35 class ModuleBase_IWorkshop;
39 namespace ModuleBase_Tools {
42 * Methods to adjust margins and spacings.
44 MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
45 MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
47 MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
48 MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
51 * Calls the same-named Qt method for the given widget.
52 * It sets the top-level widget containing this widget to be the active window.
53 * An active window is a visible top-level window that has the keyboard input focus.
54 * \param theWidget a widget to be activated
55 * \param theIndo a debug information
57 MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString());
60 * Calls the same-named Qt method for the given widget.
61 * Gives the keyboard input focus to this widget (or its focus proxy) if this widget or
62 * one of its parents is the active window.
63 * \param theWidget a widget to be activated
64 * \param theIndo a debug information
66 MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString());
69 //! Sets or removes the shadow effect to the widget
70 //! \param theWidget a widget to be styled
71 //! \param isSetEffect if true, the shadow effect is set, overwise cleared
72 //! \return resulting pixmap
73 MODULEBASE_EXPORT void setShadowEffect(QWidget* theWidget, const bool isSetEffect);
77 * Methods to modify a resource pixmap
80 //! Create composite pixmap.
81 //! Pixmap \a theAdditionalIcon is drawn over pixmap \a dest with coordinates
82 //! specified relatively to the upper left corner of \a theIcon.
84 //! \param theAdditionalIcon resource text of the additional pixmap
85 //! \param theIcon resource text of the background pixmap
86 //! \return resulting pixmap
87 MODULEBASE_EXPORT QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon);
89 //! Generates the pixmap lighter than the resources pixmap.
90 //! Pixmap \a theIcon is lighted according to the given value.
91 //! If the lighter value is greater than 100, this functions returns a lighter pixmap.
92 //! Setting lighter value to 150 returns a color that is 50% brighter. If the factor is less than 100,
93 //! the return pixmap is darker. If the factor is 0 or negative, the return pixmap is unspecified.
95 //! \param resource text of the pixmap
96 //! \param theLighterValue a lighter factor
97 //! \return resulting pixmap
98 MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterValue = 200);
100 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
101 /// \param theSpin an X or Y coordinate widget
102 /// \param theValue a new value
103 MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue);
105 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
106 /// \param theSpin an X or Y coordinate widget
107 /// \param theValue a new value
108 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue);
110 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
111 /// \param theSpin an ModuleBase_ParamSpinBox that accepts text
112 /// \param theText a new value
113 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText);
115 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
116 /// \param theSpin a ModuleBase_ParamIntSpinBox object
117 /// \param theValue a new value
118 MODULEBASE_EXPORT void setSpinValue(ModuleBase_ParamIntSpinBox* theSpin, int theValue);
120 /// Sets programmatically the value to the spin box without emitting any signals(e.g. valueChanged)
121 /// \param theSpin a SpinBox that accepts text
122 /// \param theText a new value
123 MODULEBASE_EXPORT void setSpinText(ModuleBase_ParamIntSpinBox* theSpin, const QString& theText);
125 /// Creates an action filled with the parameters
126 /// \param theIcon an action icon
127 /// \param theText an icon text
128 /// \param theParent an action object
129 /// \param theReceiver an object to process action triggered signal
130 /// \param theMember a slot to process the action triggered signal
131 /// \param theToolTip an action tool tip information, if empty the text is used
132 /// \param theStatusTip an action status tip information, if empty the text is used
133 MODULEBASE_EXPORT QAction* createAction(const QIcon& theIcon, const QString& theText,
134 QObject* theParent, const QObject* theReceiver = 0,
135 const char* theMember = "",
136 const QString& theToolTip = QString(),
137 const QString& theStatusTip = QString());
139 /// Converts the object to the feature or a result and generate information string
140 /// \param theObj an object
141 /// \param isUseAttributesInfo a flag whether the attribute values information is used
143 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
145 /// Converts the AIS context information in a string information.
146 /// \param theContext a viewer context
147 /// \param thePrefix additional information where the method is called
148 MODULEBASE_EXPORT void selectionInfo(Handle_AIS_InteractiveContext& theContext,
149 const std::string& thePrefix);
151 /// Converts string value (name of shape type) to shape enum value
152 /// \param theType - string with shape type name
153 /// \return TopAbs_ShapeEnum value
154 MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType);
156 /// Checks whether the object is a sub result. It gets the feature of the object,
157 /// obtains all results of the feature and check if the object is a sub result
158 /// \return boolean result
159 MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject);
162 Check types of objects which are in the given list
163 \param theObjects the list of objects
164 \param hasResult will be set to true if list contains Result objects
165 \param hasFeature will be set to true if list contains Feature objects
166 \param hasParameter will be set to true if list contains Parameter objects
167 \param hasCompositeOwner will be set to true if list contains Sub-Feature objects
169 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
170 bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner);
172 /*! Sets the default coeffient into the driver calculated accordingly the shape type.
173 It provides 1.e-4 for results of construction type
174 \param theResult a result object to define the deviation coeffient
175 \param theDrawer a drawer
177 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(
178 const std::shared_ptr<ModelAPI_Result>& theResult,
179 const Handle(Prs3d_Drawer)& theDrawer);
181 /*! Sets the default coeffient into the driver calculated accordingly the shape type.
182 It provides 1.e-4 for a shape withe Edge shape type
183 \param theShape a shape to define the deviation coeffient,
184 \param theDrawer a drawer
186 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
187 const Handle(Prs3d_Drawer)& theDrawer);
189 /*! Obtains the color from the property manager and converts it to the OCCT color
190 \param theSection a property section
191 \param theName a property item name
192 \param theDefault a default color value
193 \return quantity color
195 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
196 const std::string& theName,
197 const std::string& theDefault);
200 /// Returns the object from the attribute
201 /// \param theObj an object
202 MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
204 /// Returns the object from the attribute
205 /// \param theObj an object
206 MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
208 /// Returns list of parameters accessible in the active part and partset
209 /// \theParameters a list of parameter names
210 MODULEBASE_EXPORT void getParameters(QStringList& theParameters);
212 /// Returns list of parameters accessible in the active part and partset
213 /// \theParameters a list of parameter names
214 MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop,
215 const FeaturePtr& theFeature);
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 /// It is useful for attribute selection
225 MODULEBASE_EXPORT bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
226 const std::shared_ptr<GeomAPI_Shape>& theShape,
227 ModuleBase_IWorkshop* theWorkshop,
228 const bool theTemporarily);
230 /// Set the object to the attribute depending on the attribute type. If it is a list,
231 /// the values are appended if they are not in the list yet.
232 /// \param theAttribute an attribute where the object and shape are set
233 /// \param theObject an object
234 /// \param theShape a shape
235 /// \param theWorkshop to find an attribute for the given shape for attribute reference
236 /// \param theTemporarily if it is true, do not store and name the added in the data framework
237 /// \param theCheckIfAttributeHasObject if it is true, the check isInList is called
238 /// It is useful for attribute selection
239 MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
240 const std::shared_ptr<GeomAPI_Shape>& theShape,
241 ModuleBase_IWorkshop* theWorkshop,
242 const bool theTemporarily,
243 const bool theCheckIfAttributeHasObject);
245 /// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found
246 /// using current module of the given workshop.
247 /// \param theAttribute an attribute where the shape is set
248 /// \param theWorkshop to find a shape for the given attribute
249 MODULEBASE_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(const AttributePtr& theAttribute,
250 ModuleBase_IWorkshop* theWorkshop);
252 /// Flush updated signal for the object. The viewer update is blocked in the process
253 /// \param theObject parameter of the signal
254 MODULEBASE_EXPORT void flushUpdated(ObjectPtr theObject);
256 /// Sends a message about block/unblock viewer updating
257 /// \param theValue a boolean value
258 MODULEBASE_EXPORT void blockUpdateViewer(const bool theValue);
260 /// Generates a wrapped string to be less than value with '\n' separators
261 /// \param theValue a boolean value
262 /// \param theWidget a widget to know the font
263 /// \param theMaxLineInPixels a maximum line width in pixels
264 MODULEBASE_EXPORT QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
265 int theMaxLineInPixels = 150);
268 Returns a container of referenced feature to the current object in the object document.
269 \param theObject an object, which will be casted to a feature type
270 \param theRefFeatures an output container
272 void MODULEBASE_EXPORT refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
273 std::set<FeaturePtr>& theRefFeatures);
277 Returns true if the object if a sub child of the feature. The feature is casted to the
278 composite one. If it is possible, the sub object check happens. The method is applyed
279 recursively to the feature subs.
280 \param theObject a candidate to be a sub object
281 \param theFeature a candidate to be a composite feature
282 \return a boolean value
284 bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature);
288 * Returns true if the result is a sub object of some composite object
289 * \param theObject a result object
290 * \returns boolean value
292 bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject);
296 * Shows a dialog box about references. Ask whether they should be also removed.
297 * \param theFeatures a list of features
298 * \param theReferences a map of all references to the features
299 * \param theParent a parent widget for the question message box
300 * \param theReferencesToDelete an out set for references features to be removed
301 * \return true if in message box answer is Yes
303 bool MODULEBASE_EXPORT askToDelete(const std::set<FeaturePtr> aFeatures,
304 const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
306 std::set<FeaturePtr>& theReferencesToDelete);
309 * Converts a list of objects to set of corresponded features. If object is result, it is ingored
310 * because the feauture only might be removed. But if result is in a parameter group, the feature
311 * of this parameter is to be removed
312 * \param theObjects a list of objects
313 * \param theFeatures an out conteiner of features
315 void MODULEBASE_EXPORT convertToFeatures(const QObjectPtrList& theObjects, std::set<FeaturePtr>& theFeatures);