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 class ModelAPI_CompositeFeature;
13 class ModelAPI_Document;
14 class ModelAPI_Feature;
15 class ModelAPI_Result;
16 class ModelAPI_ResultParameter;
17 class ModelAPI_ResultCompSolid;
27 namespace ModelAPI_Tools {
28 /// Returns shape from the given Result object
29 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
30 const std::shared_ptr<ModelAPI_Result>& theResult);
32 /*! Returns the feature error generated according to feature error and exec state
33 * \param theFeature a feature
34 * \return error value or empty string
36 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
39 * Searches for variable with name \param theName in \param theDocument.
40 * If found, set it value in the \param outValue and returns true.
41 * theSearcher must be located later in the history than the found variable.
43 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
44 std::shared_ptr<ModelAPI_Feature> theSearcher,
45 const std::string& theName, double& outValue,
46 std::shared_ptr<ModelAPI_ResultParameter>& theParam);
49 * Searches for variable with name \param theName in the active document (Part), when
50 * in the root document (PartSet). If found, set it value in the \param outValue
51 * and returns true. If \param theDocument is empty active document is used.
52 * theSearcher must be located later in the history than the found variable.
54 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
55 const std::string& theName,
56 double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
57 const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
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 std::shared_ptr<ModelAPI_Result> findPartResult(
67 const std::shared_ptr<ModelAPI_Document>& theMain,
68 const std::shared_ptr<ModelAPI_Document>& theSub);
71 * Searches for Part the feature that contains in result the reference to the given document.
72 * The result may be disabled.
73 * \param theMain document that contains the searched feature
74 * \param theSub document that is searched, the resulting feature references to it
75 * \returns null if not found
77 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
78 const std::shared_ptr<ModelAPI_Document>& theMain,
79 const std::shared_ptr<ModelAPI_Document>& theSub);
82 * Returns the composite feature - parent of this feature.
83 * \param theFeature the sub-element of composite
84 * \returns null if it is not sub-element of composite
86 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
87 const std::shared_ptr<ModelAPI_Feature>& theFeature);
90 * Returns the compsolid result - parent of this result.
91 * \param theSub the sub-element of comp-solid
92 * \returns null if it is not sub-element of composite
94 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultCompSolid> compSolidOwner(
95 const std::shared_ptr<ModelAPI_Result>& theSub);
98 * Returns true if the result contains a not empty list of sub results.
99 * It processes result compsolid.
100 * \param theResult a result object
101 * \returns boolean value
103 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
106 * Adds the results of the given feature to theResults list: including disabled and sub-results
108 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
109 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
112 Returns true if there are no parts in the document, which are not activated
113 \param theNotActivatedNames out string which contains not activated names
114 \return a boolean value
116 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
118 /*! Removes features from the document
119 * \param theFeatures a list of features to be removed
120 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
121 * \return true if at least one feature is removed
123 MODELAPI_EXPORT bool removeFeaturesAndReferences(
124 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
125 const bool theFlushRedisplay = false,
126 const bool theUseComposite = false,
127 const bool theUseRecursion = true);
129 /*! Removes features from the document
130 * \param theFeatures a list of features to be removed
131 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
132 * \return true if at least one feature is removed
134 MODELAPI_EXPORT bool removeFeatures(
135 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
136 const bool theFlushRedisplay);
138 /*! Build a map of references for the given set of features
139 * \param theFeatures a list of features
140 * \param theReferences a map of all references to the features
141 * \param theUseComposite state if the composite features of the reference should be in the map
142 * \param theUseRecursion state if references for features out of the sources feature
143 list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
144 contain references to this feature also.
146 MODELAPI_EXPORT void findAllReferences(
147 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
148 std::map<std::shared_ptr<ModelAPI_Feature>,
149 std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
150 const bool theUseComposite = true,
151 const bool theUseRecursion = true);
153 /*! In the map of references find all features referenced to the source feature
154 * \param theFeatures a list of features to find references
155 * \param theReferences a map of all references to the features
156 * \param theFeaturesRefsTo an out list of referenced features
158 MODELAPI_EXPORT void findRefsToFeatures(
159 const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
160 const std::map<std::shared_ptr<ModelAPI_Feature>,
161 std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
162 std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
164 /*! Finds referenced of the feature to objects and collects concealed results.
165 * \param theFeatures a model feature
166 * \param theResults container for concealed results. It has no duplications
168 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
169 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);