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>
25 namespace ModelAPI_Tools {
26 /// Returns shape from the given Result object
27 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
29 /*! Returns the feature error generated according to feature error and exec state
30 * \param theFeature a feature
31 * \return error value or empty string
33 MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
36 * Searches for variable with name \param theName in \param theDocument.
37 * If found, set it value in the \param outValue and returns true.
38 * theSearcher must be located later in the history than the found variable.
40 MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
41 const std::string& theName, double& outValue, ResultParameterPtr& theParam);
44 * Searches for variable with name \param theName in the active document (Part), when
45 * in the root document (PartSet). If found, set it value in the \param outValue
46 * and returns true. If \param theDocument is empty active document is used.
47 * theSearcher must be located later in the history than the found variable.
49 MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName,
50 double& outValue, ResultParameterPtr& theParam,
51 const DocumentPtr& theDocument = DocumentPtr());
54 * Returns the values of the next random color. The values are in range [0, 255]
55 * \param theValues a container of component of RGB value: red, green, blue
57 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
60 * Searches for Part result that contains the reference to the given document.
61 * The result must be presented in the tree.
62 * \param theMain document that contains the searched feature
63 * \param theSub document that is searched, the resulting feature references to it
64 * \returns null if not found
66 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
69 * Searches for Part the feature that contains in result the reference to the given document.
70 * The result may be disabled.
71 * \param theMain document that contains the searched feature
72 * \param theSub document that is searched, the resulting feature references to it
73 * \returns null if not found
75 MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
78 * Returns the composite feature - parent of this feature.
79 * \param theFeature the sub-element of composite
80 * \returns null if it is not sub-element of composite
82 MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);
85 * Returns the compsolid result - parent of this result.
86 * \param theSub the sub-element of comp-solid
87 * \returns null if it is not sub-element of composite
89 MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub);
92 * Returns true if the result contains a not empty list of sub results. It processes result compsolid.
93 * \param theResult a result object
94 * \returns boolean value
96 MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult);
99 * Adds the results of the given feature to theResults list: including disabled and sub-results
101 MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults);
104 Returns true if there are no parts in the document, which are not activated
105 \param theNotActivatedNames out string which contains not activated names
106 \return a boolean value
108 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
111 /*! Removes features from the document
112 * \param theFeatures a list of features to be removed
113 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
114 * \return true if at least one feature is removed
116 MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
117 const bool theFlushRedisplay = false,
118 const bool theUseComposite = false,
119 const bool theUseRecursion = true);
121 /*! Removes features from the document
122 * \param theFeatures a list of features to be removed
123 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
124 * \return true if at least one feature is removed
126 MODELAPI_EXPORT bool removeFeatures(const std::set<FeaturePtr>& theFeatures,
127 const bool theFlushRedisplay);
129 /*! Build a map of references for the given set of features
130 * \param theFeatures a list of features
131 * \param theReferences a map of all references to the features
132 * \param theUseComposite state if the composite features of the reference should be in the map
133 * \param theUseRecursion state if references for features out of the sources feature
134 list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
135 contain references to this feature also.
137 MODELAPI_EXPORT void findAllReferences(const std::set<FeaturePtr>& theFeatures,
138 std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
139 const bool theUseComposite = true,
140 const bool theUseRecursion = true);
142 /*! In the map of references find all features referenced to the source feature
143 * \param theFeatures a list of features to find references
144 * \param theReferences a map of all references to the features
145 * \param theFeaturesRefsTo an out list of referenced features
147 MODELAPI_EXPORT void findRefsToFeatures(const std::set<FeaturePtr>& aFeatures,
148 const std::map<FeaturePtr, std::set<FeaturePtr> >& aReferences,
149 std::set<FeaturePtr>& aFeaturesRefsTo);