Salome HOME
For the issue #1156 : do not cause Placement error on activation of previous Part...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Tools.h
4 // Created:     06 Aug 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef ModelAPI_Tools_HeaderFile
8 #define ModelAPI_Tools_HeaderFile
9
10 #include "ModelAPI.h"
11
12 #include <ModelAPI_CompositeFeature.h>
13 #include <ModelAPI_Document.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Result.h>
16 #include <ModelAPI_ResultParameter.h>
17 #include <ModelAPI_ResultCompSolid.h>
18
19 #include <GeomAPI_Shape.h>
20
21 #include <vector>
22
23 namespace ModelAPI_Tools {
24 /// Returns shape from the given Result object
25 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
26
27 /*! Returns the feature error generated according to feature error and exec state
28  * \param theFeature a feature
29  * \return error value or empty string
30  */
31 MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
32
33 /*!
34  * Searches for variable with name \param theName in \param theDocument. 
35  * If found, set it value in the \param outValue and returns true.
36  */
37 MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, 
38                                   const std::string& theName, double& outValue, ResultParameterPtr& theParam);
39
40 /*!
41  * Searches for variable with name \param theName in the active document (Part), when
42  * in the root document (PartSet). If found, set it value in the \param outValue
43  * and returns true. If \param theDocument is empty active document is used.
44  */
45 MODELAPI_EXPORT bool findVariable(const std::string& theName, double& outValue, ResultParameterPtr& theParam,
46                                   const DocumentPtr& theDocument = DocumentPtr());
47
48 /*!
49  * Returns the values of the next random color. The values are in range [0, 255]
50  * \param theValues a container of component of RGB value: red, green, blue
51  */
52 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
53
54 /*!
55  * Searches for Part result that contains the reference to the given document.
56  * The result must be presented in the tree.
57  * \param theMain document that contains the searched feature
58  * \param theSub document that is searched, the resulting feature references to it
59  * \returns null if not found
60  */
61 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
62
63 /*!
64  * Searches for Part the feature that contains in result the reference to the given document.
65  * The result may be disabled.
66  * \param theMain document that contains the searched feature
67  * \param theSub document that is searched, the resulting feature references to it
68  * \returns null if not found
69  */
70 MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
71
72 /*!
73  * Returns the composite feature - parent of this feature.
74  * \param theFeature the sub-element of composite
75  * \returns null if it is not sub-element of composite
76  */
77 MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);
78
79 /*!
80  * Returns the compsolid result - parent of this result.
81  * \param theSub the sub-element of comp-solid
82  * \returns null if it is not sub-element of composite
83  */
84 MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub);
85
86 /*!
87 * Returns true if the result contains a not empty list of sub results. It processes result compsolid.
88 * \param theResult a result object
89 * \returns boolean value
90 */
91 MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult);
92
93 /*!
94 * Adds the results of the given feature to theResults list: including disabled and sub-results
95 */
96 MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults);
97
98 }
99
100 #endif