Salome HOME
Feature selector widget for recover feature.
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
2 \r
3 // File:        ModelAPI_Tools.h\r
4 // Created:     06 Aug 2014\r
5 // Author:      Vitaly Smetannikov\r
6 \r
7 #ifndef ModelAPI_Tools_HeaderFile\r
8 #define ModelAPI_Tools_HeaderFile\r
9 \r
10 #include "ModelAPI.h"\r
11 \r
12 #include <ModelAPI_CompositeFeature.h>\r
13 #include <ModelAPI_Document.h>\r
14 #include <ModelAPI_Feature.h>\r
15 #include <ModelAPI_Result.h>\r
16 #include <ModelAPI_ResultParameter.h>\r
17 #include <ModelAPI_ResultCompSolid.h>\r
18 \r
19 #include <GeomAPI_Shape.h>\r
20 \r
21 #include <vector>\r
22 #include <map>\r
23 #include <set>\r
24 \r
25 namespace ModelAPI_Tools {\r
26 /// Returns shape from the given Result object\r
27 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);\r
28 \r
29 /// Creates a container of shape of the feature results satisfied the given shape type\r
30 /// \param theFeature a source feature\r
31 /// \param theType shape type\r
32 /// \param an output container for shapes\r
33 MODELAPI_EXPORT void shapesOfType(const FeaturePtr& theFeature,\r
34                                   const GeomAPI_Shape::ShapeType& theType,\r
35                                   std::set<GeomShapePtr>& theShapes);\r
36 \r
37 /*! Returns the feature error generated according to feature error and exec state\r
38  * \param theFeature a feature\r
39  * \return error value or empty string\r
40  */\r
41 MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);\r
42 \r
43 /*!\r
44  * Searches for variable with name \param theName in \param theDocument. \r
45  * If found, set it value in the \param outValue and returns true.\r
46  * theSearcher must be located later in the history than the found variable.\r
47  */\r
48 MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,\r
49   const std::string& theName, double& outValue, ResultParameterPtr& theParam);\r
50 \r
51 /*!\r
52  * Searches for variable with name \param theName in the active document (Part), when\r
53  * in the root document (PartSet). If found, set it value in the \param outValue\r
54  * and returns true. If \param theDocument is empty active document is used.\r
55  * theSearcher must be located later in the history than the found variable.\r
56  */\r
57 MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName,\r
58   double& outValue, ResultParameterPtr& theParam,\r
59   const DocumentPtr& theDocument = DocumentPtr());\r
60 \r
61 /*!\r
62  * Returns the values of the next random color. The values are in range [0, 255]\r
63  * \param theValues a container of component of RGB value: red, green, blue\r
64  */\r
65 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);\r
66 \r
67 /*!\r
68  * Searches for Part result that contains the reference to the given document.\r
69  * The result must be presented in the tree.\r
70  * \param theMain document that contains the searched feature\r
71  * \param theSub document that is searched, the resulting feature references to it\r
72  * \returns null if not found\r
73  */\r
74 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);\r
75 \r
76 /*!\r
77  * Searches for Part the feature that contains in result the reference to the given document.\r
78  * The result may be disabled.\r
79  * \param theMain document that contains the searched feature\r
80  * \param theSub document that is searched, the resulting feature references to it\r
81  * \returns null if not found\r
82  */\r
83 MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);\r
84 \r
85 /*!\r
86  * Returns the composite feature - parent of this feature.\r
87  * \param theFeature the sub-element of composite\r
88  * \returns null if it is not sub-element of composite\r
89  */\r
90 MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);\r
91 \r
92 /*!\r
93  * Returns the compsolid result - parent of this result.\r
94  * \param theSub the sub-element of comp-solid\r
95  * \returns null if it is not sub-element of composite\r
96  */\r
97 MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub);\r
98 \r
99 /*!\r
100 * Returns true if the result contains a not empty list of sub results. It processes result compsolid.\r
101 * \param theResult a result object\r
102 * \returns boolean value\r
103 */\r
104 MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult);\r
105 \r
106 /*!\r
107 * Adds the results of the given feature to theResults list: including disabled and sub-results\r
108 */\r
109 MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults);\r
110 \r
111 /*!\r
112  Returns true if there are no parts in the document, which are not activated\r
113  \param theNotActivatedNames out string which contains not activated names\r
114  \return a boolean value\r
115  */\r
116 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);\r
117 \r
118 \r
119 /*! Removes features from the document\r
120 * \param theFeatures a list of features to be removed\r
121 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed\r
122 * \return true if at least one feature is removed\r
123 */\r
124 MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,\r
125                                                  const bool theFlushRedisplay = false,\r
126                                                  const bool theUseComposite = false,\r
127                                                  const bool theUseRecursion = true);\r
128 \r
129 /*! Removes features from the document\r
130 * \param theFeatures a list of features to be removed\r
131 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed\r
132 * \return true if at least one feature is removed\r
133 */\r
134 MODELAPI_EXPORT bool removeFeatures(const std::set<FeaturePtr>& theFeatures,\r
135                                     const bool theFlushRedisplay);\r
136 \r
137 /*! Build a map of references for the given set of features\r
138 * \param theFeatures a list of features\r
139 * \param theReferences a map of all references to the features\r
140 * \param theUseComposite state if the composite features of the reference should be in the map\r
141 * \param theUseRecursion state if references for features out of the sources feature\r
142          list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will\r
143          contain references to this feature also.\r
144 */\r
145 MODELAPI_EXPORT void findAllReferences(const std::set<FeaturePtr>& theFeatures,\r
146                                        std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,\r
147                                        const bool theUseComposite = true,\r
148                                        const bool theUseRecursion = true);\r
149 \r
150 /*! In the map of references find all features referenced to the source feature\r
151 * \param theFeatures a list of features to find references\r
152 * \param theReferences a map of all references to the features\r
153 * \param theFeaturesRefsTo an out list of referenced features\r
154 */\r
155 MODELAPI_EXPORT void findRefsToFeatures(const std::set<FeaturePtr>& aFeatures,\r
156                                         const std::map<FeaturePtr, std::set<FeaturePtr> >& aReferences,\r
157                                         std::set<FeaturePtr>& aFeaturesRefsTo);\r
158 \r
159 /*! Finds referenced of the feature to objects and collects concealed results.\r
160 * \param theFeatures a model feature\r
161 * \param theResults container for concealed results. It has no duplications\r
162 */\r
163 MODELAPI_EXPORT void getConcealedResults(const FeaturePtr& theFeature,\r
164                                          std::list<std::shared_ptr<ModelAPI_Result> >& theResults);\r
165 }\r
166 \r
167 #endif\r