]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Tools.h
Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModelAPI_Tools_HeaderFile
22 #define ModelAPI_Tools_HeaderFile
23
24 #include "ModelAPI.h"
25
26 class ModelAPI_CompositeFeature;
27 class ModelAPI_Document;
28 class ModelAPI_Feature;
29 class ModelAPI_Result;
30 class ModelAPI_ResultParameter;
31 class ModelAPI_ResultCompSolid;
32
33 class GeomAPI_Shape;
34
35 #include <memory>
36 #include <vector>
37 #include <map>
38 #include <set>
39 #include <list>
40
41 namespace ModelAPI_Tools {
42 /// Returns shape from the given Result object
43 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
44                                    const std::shared_ptr<ModelAPI_Result>& theResult);
45
46 /*! Returns the feature error generated according to feature error and exec state
47  * \param theFeature a feature
48  * \return error value or empty string
49  */
50 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
51
52 /*!
53  * Searches for variable with name \param theName in \param theDocument. 
54  * If found, set it value in the \param outValue and returns true.
55  * theSearcher must be located later in the history than the found variable.
56  */
57 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
58                                   std::shared_ptr<ModelAPI_Feature> theSearcher,
59                                   const std::string& theName, double& outValue,
60                                   std::shared_ptr<ModelAPI_ResultParameter>& theParam);
61
62 /*!
63  * Searches for variable with name \param theName in the active document (Part), when
64  * in the root document (PartSet). If found, set it value in the \param outValue
65  * and returns true. If \param theDocument is empty active document is used.
66  * theSearcher must be located later in the history than the found variable.
67  */
68 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
69   const std::string& theName,
70   double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
71   const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
72
73 /*!
74  * Searches for Part result that contains the reference to the given document.
75  * The result must be presented in the tree.
76  * \param theMain document that contains the searched feature
77  * \param theSub document that is searched, the resulting feature references to it
78  * \returns null if not found
79  */
80 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> findPartResult(
81                                               const std::shared_ptr<ModelAPI_Document>& theMain,
82                                               const std::shared_ptr<ModelAPI_Document>& theSub);
83
84 /*!
85  * Searches for Part the feature that contains in result the reference to the given document.
86  * The result may be disabled.
87  * \param theMain document that contains the searched feature
88  * \param theSub document that is searched, the resulting feature references to it
89  * \returns null if not found
90  */
91 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
92                                            const std::shared_ptr<ModelAPI_Document>& theMain,
93                                            const std::shared_ptr<ModelAPI_Document>& theSub);
94
95 /*!
96  * Returns the composite feature - parent of this feature.
97  * \param theFeature the sub-element of composite
98  * \returns null if it is not sub-element of composite
99  */
100 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
101                                         const std::shared_ptr<ModelAPI_Feature>& theFeature);
102
103 /*!
104  * Returns the compsolid result - parent of this result.
105  * \param theSub the sub-element of comp-solid
106  * \returns null if it is not sub-element of composite
107  */
108 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultCompSolid> compSolidOwner(
109                                             const std::shared_ptr<ModelAPI_Result>& theSub);
110
111 /*!
112 * Returns true if the result contains a not empty list of sub results.
113 * It processes result compsolid.
114 * \param theResult a result object
115 * \returns boolean value
116 */
117 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
118
119 /*!
120 * Adds the results of the given feature to theResults list: including disabled and sub-results
121 */
122 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
123                                 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
124
125 /*!
126  Returns true if there are no parts in the document, which are not activated
127  \param theNotActivatedNames out string which contains not activated names
128  \return a boolean value
129  */
130 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
131
132 /*! Removes features from the document
133 * \param theFeatures a list of features to be removed
134 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
135 * \return true if at least one feature is removed
136 */
137 MODELAPI_EXPORT bool removeFeaturesAndReferences(
138                        const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
139                                                  const bool theFlushRedisplay = false,
140                                                  const bool theUseComposite = false,
141                                                  const bool theUseRecursion = true);
142
143 /*! Removes features from the document
144 * \param theFeatures a list of features to be removed
145 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
146 * \return true if at least one feature is removed
147 */
148 MODELAPI_EXPORT bool removeFeatures(
149                             const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
150                             const bool theFlushRedisplay);
151
152 /*! Build a map of references for the given set of features
153 * \param theFeatures a list of features
154 * \param theReferences a map of all references to the features
155 * \param theUseComposite state if the composite features of the reference should be in the map
156 * \param theUseRecursion state if references for features out of the sources feature
157          list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
158          contain references to this feature also.
159 */
160 MODELAPI_EXPORT void findAllReferences(
161   const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
162   std::map<std::shared_ptr<ModelAPI_Feature>,
163   std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
164   const bool theUseComposite = true,
165   const bool theUseRecursion = true);
166
167 /*! In the map of references find all features referenced to the source feature
168 * \param theFeatures a list of features to find references
169 * \param theReferences a map of all references to the features
170 * \param theFeaturesRefsTo an out list of referenced features
171 */
172 MODELAPI_EXPORT void findRefsToFeatures(
173   const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
174   const std::map<std::shared_ptr<ModelAPI_Feature>,
175                  std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
176   std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
177
178 /*! Finds referenced of the feature to objects and collects concealed results.
179 * \param theFeatures a model feature
180 * \param theResults container for concealed results. It has no duplications
181 */
182 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
183                                    std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
184 }
185
186 #endif