]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Tools.h
Salome HOME
26451: Import Result with Groups
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.h
1 // Copyright (C) 2014-2021  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_Tools_HeaderFile
21 #define ModelAPI_Tools_HeaderFile
22
23 #include "ModelAPI.h"
24 #include <ModelAPI_AttributeSelectionList.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_ResultBody;
32
33 class GeomAPI_Shape;
34 class GeomAPI_ShapeHierarchy;
35
36 #include <memory>
37 #include <vector>
38 #include <map>
39 #include <set>
40 #include <list>
41
42 namespace ModelAPI_Tools {
43 /// Returns shape from the given Result object
44 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
45                                    const std::shared_ptr<ModelAPI_Result>& theResult);
46
47 /*! Returns the feature error generated according to feature error and exec state
48  * \param theFeature a feature
49  * \return error value or empty string
50  */
51 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
52
53 /*!
54  * Searches for variable with name \param theName in \param theDocument.
55  * If found, set it value in the \param outValue and returns true.
56  * theSearcher must be located later in the history than the found variable.
57  */
58 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
59                                   std::shared_ptr<ModelAPI_Feature> theSearcher,
60                                   const std::wstring& theName, double& outValue,
61                                   std::shared_ptr<ModelAPI_ResultParameter>& theParam);
62
63 /*!
64  * Searches for variable with name \param theName in the active document (Part), when
65  * in the root document (PartSet). If found, set it value in the \param outValue
66  * and returns true. If \param theDocument is empty active document is used.
67  * theSearcher must be located later in the history than the found variable.
68  */
69 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
70   const std::wstring& theName,
71   double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
72   const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
73
74 /*!
75  * Searches for Part result that contains the reference to the given document.
76  * The result must be presented in the tree.
77  * \param theMain document that contains the searched feature
78  * \param theSub document that is searched, the resulting feature references to it
79  * \returns null if not found
80  */
81 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> findPartResult(
82                                               const std::shared_ptr<ModelAPI_Document>& theMain,
83                                               const std::shared_ptr<ModelAPI_Document>& theSub);
84
85 /*!
86  * Searches for Part the feature that contains in result the reference to the given document.
87  * The result may be disabled.
88  * \param theMain document that contains the searched feature
89  * \param theSub document that is searched, the resulting feature references to it
90  * \returns null if not found
91  */
92 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
93                                            const std::shared_ptr<ModelAPI_Document>& theMain,
94                                            const std::shared_ptr<ModelAPI_Document>& theSub);
95
96 /*!
97  * Returns the composite feature - parent of this feature.
98  * \param theFeature the sub-element of composite
99  * \returns null if it is not sub-element of composite
100  */
101 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
102                                         const std::shared_ptr<ModelAPI_Feature>& theFeature);
103
104 /*!
105  * Returns the result - parent of this result.
106  * \param theSub the sub-element of composit result
107  * \param theRoot if it is true, returns the root father
108  * \returns null if it is not sub-element of composite
109  */
110 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
111   bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
112 /*!
113  * Returns index of this result in parent (if parent exists, returned by bodyOwner)
114  * \returns zero-base index, or -1 if not found
115  */
116 MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
117
118 /*!
119 * Returns true if the result contains a not empty list of sub results.
120 * It processes result compsolid.
121 * \param theResult a result object
122 * \returns boolean value
123 */
124 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
125
126 /*!
127 *  collects recursively all subs of the given result
128 */
129 MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
130                              std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
131                              const bool theLowerOnly = false);
132
133 /*!
134 * Adds the results of the given feature to theResults list: including disabled and sub-results
135 */
136 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
137                                 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
138
139 /*!
140  Returns true if there are no parts in the document, which are not activated
141  \param theNotActivatedNames out string which contains not activated names
142  \return a boolean value
143  */
144 MODELAPI_EXPORT bool allDocumentsActivated(std::wstring& theNotActivatedNames);
145
146 /*! Removes features from the document
147 * \param theFeatures a list of features to be removed
148 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
149 * \return true if at least one feature is removed
150 */
151 MODELAPI_EXPORT bool removeFeaturesAndReferences(
152                        const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
153                                                  const bool theFlushRedisplay = false,
154                                                  const bool theUseComposite = false,
155                                                  const bool theUseRecursion = true);
156
157 /*! Removes features from the document
158 * \param theFeatures a list of features to be removed
159 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
160 * \return true if at least one feature is removed
161 */
162 MODELAPI_EXPORT bool removeFeatures(
163                             const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
164                             const bool theFlushRedisplay);
165
166 /*! Build a map of references for the given set of features
167 * \param theFeatures a list of features
168 * \param theReferences a map of all references to the features
169 * \param theUseComposite state if the composite features of the reference should be in the map
170 * \param theUseRecursion state if references for features out of the sources feature
171          list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
172          contain references to this feature also.
173 */
174 MODELAPI_EXPORT void findAllReferences(
175   const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
176   std::map<std::shared_ptr<ModelAPI_Feature>,
177   std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
178   const bool theUseComposite = true,
179   const bool theUseRecursion = true);
180
181 /*! In the map of references find all features referenced to the source feature
182 * \param theFeatures a list of features to find references
183 * \param theReferences a map of all references to the features
184 * \param theFeaturesRefsTo an out list of referenced features
185 */
186 MODELAPI_EXPORT void findRefsToFeatures(
187   const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
188   const std::map<std::shared_ptr<ModelAPI_Feature>,
189                  std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
190   std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
191
192 /*! Finds referenced of the feature to objects and collects concealed results.
193 * \param theFeatures a model feature
194 * \param theResults container for concealed results. It has no duplications
195 */
196 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
197                                    std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
198
199 /*! Return the default name of the result according the features it depends or name of the feature.
200  *  Return also whether the name is get from the concealing result of parent object
201  *  (means that concealing result has user-defined name).
202  * \param[in] theRecursive  recursively check the concealed results if they have user-defined names
203  */
204 MODELAPI_EXPORT std::pair<std::wstring, bool> getDefaultName(
205   const std::shared_ptr<ModelAPI_Result>& theResult,
206   const bool theInherited = true,
207   const bool theRecursive = false);
208
209 /*! Collect all parents for the given feature, including the Part
210  */
211 MODELAPI_EXPORT std::set<std::shared_ptr<ModelAPI_Feature> >
212     getParents(const std::shared_ptr<ModelAPI_Feature>& theFeature);
213
214 /*! Store shape and its parent shape to the hierarchy data structure
215  *  \param[in] theShape      the shape to store
216  *  \param[in] theContext    the result (parent shape) for the given shape
217  *  \param[out] theHierarchy container for shape hierarchy
218  */
219 MODELAPI_EXPORT void fillShapeHierarchy(
220     const std::shared_ptr<GeomAPI_Shape>& theShape,
221     const std::shared_ptr<ModelAPI_Result>& theContext,
222     GeomAPI_ShapeHierarchy& theHierarchy);
223
224 /*! Creates a remove result features with the given results
225 */
226 MODELAPI_EXPORT void removeResults(const std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
227
228 /*! Returns current deflection in the given result
229 * \param theResult a result object
230 * \return a deflection value or -1 if it was not defined
231 */
232 MODELAPI_EXPORT double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult);
233
234 /*! Sets the deflection value
235 * \param theResult a result object
236 * \param a deflection value
237 */
238 MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
239   const double theDeflection);
240
241 /*! Returns current color of the current result
242 * \param[in] theResult a result object
243 * \param[out] theColor a color values if it is defined
244 */
245 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
246   std::vector<int>& theColor);
247
248 /*! Set color of the result
249 * \param[in] theResult a result object
250 * \param[in] theColor a color values
251 */
252 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
253   const std::vector<int>& theColor);
254
255 /*! Returns number of iso-lines of the current result
256 * \param[in] theResult a result object
257 * \param[out] theNbLines values of iso-lines
258 */
259 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
260   bool& isVisible, std::vector<int>& theNbLines);
261
262 /*! Set number of iso-lines of the result
263 * \param[in] theResult a result object
264 * \param[in] theIso nb iso-lines
265 */
266 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
267   const std::vector<int>& theIso);
268
269 /*! Set visibility of Iso lines
270 * \param[in] theResult a result object
271 * \param[in] theShow is a visibility flag
272 */
273 MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
274
275 MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
276
277 /*! Returns current transparency in the given result
278 * \param theResult a result object
279 * \return a transparency value or -1 if it was not defined
280 */
281 MODELAPI_EXPORT double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult);
282
283 /*! Set transparency for the given result
284 * \param theResult a result object
285 * \param a transparency value
286 */
287 MODELAPI_EXPORT void setTransparency(std::shared_ptr<ModelAPI_Result> theResult,
288   double theTransparency);
289
290
291 /*! Copies all visualization attributes from one result to another.
292 * \param theSource a result that contains the copied attributes
293 * \param theDest a destination result that takes the visualization attributes
294 */
295 MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
296                                             std::shared_ptr<ModelAPI_Result> theDest);
297
298 /*! Copies image attribute from one result to another.
299 * \param theSource a result that contains the image data
300 * \param theDest a destination result that takes the image data
301 */
302 MODELAPI_EXPORT void copyImageAttribute(std::shared_ptr<ModelAPI_Result> theSource,
303                                         std::shared_ptr<ModelAPI_Result> theDest);
304
305 /*! Produces list of features that reference to the given target (directly or through sub-results)
306 * \param theTarget the referenced result
307 * \param theFeatureKind the resulting features filter: the feature kind or all for the empty string
308 * \param theSortResults to sort the resulting list of features by the features creation order
309 */
310 MODELAPI_EXPORT std::list<std::shared_ptr<ModelAPI_Feature> > referencedFeatures(
311   std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
312   const bool theSortResults);
313
314 /*!
315  * Returns true if something in selection is presented in the results list
316  */
317 MODELAPI_EXPORT bool isInResults(AttributeSelectionListPtr theSelection,
318                                  const std::list<ResultPtr>& theResults,
319                                  std::set<ResultPtr>& theCashedResults);
320
321 /*! Returns a container with the current color value.
322 *   These are tree int values for RGB definition.
323 *   It returns the next random color.
324 * \param theValues vector of values
325 * \param theReset flag to call when disabling Auto-color
326 */
327 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues, bool theReset = false);
328
329 }
330
331 #endif