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 ModuleBase_ParamIntSpinBox;
28 class ModuleBase_ParamSpinBox;
29 class ModuleBase_IWorkshop;
33 namespace ModuleBase_Tools {
36 * Methods to adjust margins and spacings.
38 MODULEBASE_EXPORT void adjustMargins(QWidget* theWidget);
39 MODULEBASE_EXPORT void adjustMargins(QLayout* theLayout);
41 MODULEBASE_EXPORT void zeroMargins(QWidget* theWidget);
42 MODULEBASE_EXPORT void zeroMargins(QLayout* theLayout);
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
51 MODULEBASE_EXPORT void activateWindow(QWidget* theWidget, const QString& theInfo = QString());
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
60 MODULEBASE_EXPORT void setFocus(QWidget* theWidget, const QString& theInfo = QString());
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);
71 * Methods to modify a resource pixmap
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.
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);
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.
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);
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);
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);
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);
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);
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);
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
123 MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false);
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);
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);
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 hasCompositeOwner will be set to true if list contains Sub-Feature objects
143 MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
144 bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner);
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
151 MODULEBASE_EXPORT void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
152 const Handle(Prs3d_Drawer)& theDrawer);
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
160 MODULEBASE_EXPORT Quantity_Color color(const std::string& theSection,
161 const std::string& theName,
162 const std::string& theDefault);
165 /// Returns the object from the attribute
166 /// \param theObj an object
167 MODULEBASE_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
169 /// Returns the object from the attribute
170 /// \param theObj an object
171 MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
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);
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);
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);
195 /// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found
196 /// using current module of the given workshop.
197 /// \param theAttribute an attribute where the shape is set
198 /// \param theWorkshop to find a shape for the given attribute
199 MODULEBASE_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(const AttributePtr& theAttribute,
200 ModuleBase_IWorkshop* theWorkshop);
202 /// Flush updated signal for the object. The viewer update is blocked in the process
203 /// \param theObject parameter of the signal
204 MODULEBASE_EXPORT void flushUpdated(ObjectPtr theObject);
206 /// Sends a message about block/unblock viewer updating
207 /// \param theValue a boolean value
208 MODULEBASE_EXPORT void blockUpdateViewer(const bool theValue);
210 /// Generates a wrapped string to be less than value with '\n' separators
211 /// \param theValue a boolean value
212 /// \param theWidget a widget to know the font
213 /// \param theMaxLineInPixels a maximum line width in pixels
214 MODULEBASE_EXPORT QString wrapTextByWords(const QString& theValue, QWidget* theWidget,
215 int theMaxLineInPixels = 150);
217 //! Find all referenced features. Return direct and indirect lists of referenced object
218 //! \param theList an objects to be checked
219 //! \param aDirectRefFeatures a list of direct reference features
220 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
221 MODULEBASE_EXPORT void findReferences(const QObjectPtrList& theList,
222 std::set<FeaturePtr>& aDirectRefFeatures,
223 std::set<FeaturePtr>& aIndirectRefFeatures);
225 Returns a container of references feature to the source object. The search happens in the object
226 document and in other Part documents if the object belongs to the PartSet. The search is recursive,
227 in other words it is applyed to set of the found objects until it is possible.
228 It do not returns the referenced features to the object if this references is a composite feature
229 which has the object as a sub object.
230 \param theSourceObject an object, which references are searched
231 \param theObject an intermediate recursive object, should be set in the source object
232 \param theIgnoreList an ignore list, the found referernces which coincide with the objects are ignored
233 \param theDirectRefFeatures direct references
234 \param theIndirectRefFeatures indirect references. These are features that refers to the direct features
235 \param theAlreadyProcessed set of processed elements, used for optimization (do not reanalyse processed)
236 \return a boolean value
238 void MODULEBASE_EXPORT refsToFeatureInAllDocuments(const ObjectPtr& theSourceObject,
239 const ObjectPtr& theObject,
240 const QObjectPtrList& theIgnoreList,
241 std::set<FeaturePtr>& theDirectRefFeatures,
242 std::set<FeaturePtr>& theIndirectRefFeatures,
243 std::set<FeaturePtr>& theAlreadyProcessed);
247 void MODULEBASE_EXPORT refsDirectToFeatureInAllDocuments(const ObjectPtr& theSourceObject,
248 const ObjectPtr& theObject,
249 const QObjectPtrList& theIgnoreList,
250 std::set<FeaturePtr>& theDirectRefFeatures,
251 std::set<FeaturePtr>& theAlreadyProcessed);
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
258 void MODULEBASE_EXPORT refsToFeatureInFeatureDocument(const ObjectPtr& theObject,
259 std::set<FeaturePtr>& theRefFeatures);
263 Returns true if the object if a sub child of the feature. The feature is casted to the
264 composite one. If it is possible, the sub object check happens. The method is applyed
265 recursively to the feature subs.
266 \param theObject a candidate to be a sub object
267 \param theFeature a candidate to be a composite feature
268 \return a boolean value
270 bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature);
274 * Returns true if the result is a sub object of some composite object
275 * \param theObject a result object
276 * \returns boolean value
278 bool MODULEBASE_EXPORT isSubOfComposite(const ObjectPtr& theObject);
281 //! Shows a dialog box about references. Ask whether they should be also removed.
282 //! \param theList an objects to be checked
283 //! \param aDirectRefFeatures a list of direct reference features
284 //! \param aIndirectRefFeatures a list of features which depend on the feature through others
285 //! \param theParent a parent widget for the question message box
286 //! \param doDeleteReferences if there are parameters between features, ask if they should be
287 //! replaced to their meaning without corresponded features remove
288 //! \return true if in message box answer is Yes
289 bool MODULEBASE_EXPORT isDeleteFeatureWithReferences(const QObjectPtrList& theList,
290 const std::set<FeaturePtr>& aDirectRefFeatures,
291 const std::set<FeaturePtr>& aIndirectRefFeatures,
293 bool& doDeleteReferences);