1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Tools.h
4 // Created: 06 Aug 2014
5 // Author: Vitaly Smetannikov
7 #ifndef ModelAPI_Tools_HeaderFile
8 #define ModelAPI_Tools_HeaderFile
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>
19 #include <GeomAPI_Shape.h>
23 namespace ModelAPI_Tools {
24 /// Returns shape from the given Result object
25 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
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
31 MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
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 * theSearcher must be located later in the history than the found variable.
38 MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
39 const std::string& theName, double& outValue, ResultParameterPtr& theParam);
42 * Searches for variable with name \param theName in the active document (Part), when
43 * in the root document (PartSet). If found, set it value in the \param outValue
44 * and returns true. If \param theDocument is empty active document is used.
45 * theSearcher must be located later in the history than the found variable.
47 MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName,
48 double& outValue, ResultParameterPtr& theParam,
49 const DocumentPtr& theDocument = DocumentPtr());
52 * Returns the values of the next random color. The values are in range [0, 255]
53 * \param theValues a container of component of RGB value: red, green, blue
55 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
58 * Searches for Part result that contains the reference to the given document.
59 * The result must be presented in the tree.
60 * \param theMain document that contains the searched feature
61 * \param theSub document that is searched, the resulting feature references to it
62 * \returns null if not found
64 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
67 * Searches for Part the feature that contains in result the reference to the given document.
68 * The result may be disabled.
69 * \param theMain document that contains the searched feature
70 * \param theSub document that is searched, the resulting feature references to it
71 * \returns null if not found
73 MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
76 * Returns the composite feature - parent of this feature.
77 * \param theFeature the sub-element of composite
78 * \returns null if it is not sub-element of composite
80 MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);
83 * Returns the compsolid result - parent of this result.
84 * \param theSub the sub-element of comp-solid
85 * \returns null if it is not sub-element of composite
87 MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub);
90 * Returns true if the result contains a not empty list of sub results. It processes result compsolid.
91 * \param theResult a result object
92 * \returns boolean value
94 MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult);
97 * Adds the results of the given feature to theResults list: including disabled and sub-results
99 MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults);