1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_Tools_HeaderFile
21 #define ModelAPI_Tools_HeaderFile
25 class ModelAPI_CompositeFeature;
26 class ModelAPI_Document;
27 class ModelAPI_Feature;
28 class ModelAPI_Result;
29 class ModelAPI_ResultParameter;
30 class ModelAPI_ResultBody;
33 class GeomAPI_ShapeHierarchy;
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);
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
50 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
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.
57 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
58 std::shared_ptr<ModelAPI_Feature> theSearcher,
59 const std::wstring& theName, double& outValue,
60 std::shared_ptr<ModelAPI_ResultParameter>& theParam);
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.
68 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
69 const std::wstring& theName,
70 double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
71 const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
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
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);
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
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);
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
100 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
101 const std::shared_ptr<ModelAPI_Feature>& theFeature);
104 * Returns the result - parent of this result.
105 * \param theSub the sub-element of composit result
106 * \param theRoot if it is true, returns the root father
107 * \returns null if it is not sub-element of composite
109 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
110 bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
112 * Returns index of this result in parent (if parent exists, returned by bodyOwner)
113 * \returns zero-base index, or -1 if not found
115 MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
118 * Returns true if the result contains a not empty list of sub results.
119 * It processes result compsolid.
120 * \param theResult a result object
121 * \returns boolean value
123 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
126 * collects recursively all subs of the given result
128 MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
129 std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
130 const bool theLowerOnly = false);
133 * Adds the results of the given feature to theResults list: including disabled and sub-results
135 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
136 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
139 Returns true if there are no parts in the document, which are not activated
140 \param theNotActivatedNames out string which contains not activated names
141 \return a boolean value
143 MODELAPI_EXPORT bool allDocumentsActivated(std::wstring& theNotActivatedNames);
145 /*! Removes features from the document
146 * \param theFeatures a list of features to be removed
147 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
148 * \return true if at least one feature is removed
150 MODELAPI_EXPORT bool removeFeaturesAndReferences(
151 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
152 const bool theFlushRedisplay = false,
153 const bool theUseComposite = false,
154 const bool theUseRecursion = true);
156 /*! Removes features from the document
157 * \param theFeatures a list of features to be removed
158 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
159 * \return true if at least one feature is removed
161 MODELAPI_EXPORT bool removeFeatures(
162 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
163 const bool theFlushRedisplay);
165 /*! Build a map of references for the given set of features
166 * \param theFeatures a list of features
167 * \param theReferences a map of all references to the features
168 * \param theUseComposite state if the composite features of the reference should be in the map
169 * \param theUseRecursion state if references for features out of the sources feature
170 list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
171 contain references to this feature also.
173 MODELAPI_EXPORT void findAllReferences(
174 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
175 std::map<std::shared_ptr<ModelAPI_Feature>,
176 std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
177 const bool theUseComposite = true,
178 const bool theUseRecursion = true);
180 /*! In the map of references find all features referenced to the source feature
181 * \param theFeatures a list of features to find references
182 * \param theReferences a map of all references to the features
183 * \param theFeaturesRefsTo an out list of referenced features
185 MODELAPI_EXPORT void findRefsToFeatures(
186 const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
187 const std::map<std::shared_ptr<ModelAPI_Feature>,
188 std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
189 std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
191 /*! Finds referenced of the feature to objects and collects concealed results.
192 * \param theFeatures a model feature
193 * \param theResults container for concealed results. It has no duplications
195 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
196 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
198 /*! Return the default name of the result according the features it depends or name of the feature.
199 * Return also whether the name is get from the concealing result of parent object
200 * (means that concealing result has user-defined name).
201 * \param[in] theRecursive recursively check the concealed results if they have user-defined names
203 MODELAPI_EXPORT std::pair<std::wstring, bool> getDefaultName(
204 const std::shared_ptr<ModelAPI_Result>& theResult,
205 const bool theInherited = true,
206 const bool theRecursive = false);
208 /*! Collect all parents for the given feature, including the Part
210 MODELAPI_EXPORT std::set<std::shared_ptr<ModelAPI_Feature> >
211 getParents(const std::shared_ptr<ModelAPI_Feature>& theFeature);
213 /*! Store shape and its parent shape to the hierarchy data structure
214 * \param[in] theShape the shape to store
215 * \param[in] theContext the result (parent shape) for the given shape
216 * \param[out] theHierarchy container for shape hierarchy
218 MODELAPI_EXPORT void fillShapeHierarchy(
219 const std::shared_ptr<GeomAPI_Shape>& theShape,
220 const std::shared_ptr<ModelAPI_Result>& theContext,
221 GeomAPI_ShapeHierarchy& theHierarchy);
223 /*! Creates a remove result features with the given results
225 MODELAPI_EXPORT void removeResults(const std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
227 /*! Returns current deflection in the given result
228 * \param theResult a result object
229 * \return a deflection value or -1 if it was not defined
231 MODELAPI_EXPORT double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult);
233 /*! Sets the deflection value
234 * \param theResult a result object
235 * \param a deflection value
237 MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
238 const double theDeflection);
240 /*! Returns current color of the current result
241 * \param[in] theResult a result object
242 * \param[out] theColor a color values if it is defined
244 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
245 std::vector<int>& theColor);
247 /*! Set color of the result
248 * \param[in] theResult a result object
249 * \param[in] theColor a color values
251 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
252 const std::vector<int>& theColor);
254 /*! Returns number of iso-lines of the current result
255 * \param[in] theResult a result object
256 * \param[out] theNbLines values of iso-lines
258 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
259 bool& isVisible, std::vector<int>& theNbLines);
261 /*! Set number of iso-lines of the result
262 * \param[in] theResult a result object
263 * \param[in] theIso nb iso-lines
265 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
266 const std::vector<int>& theIso);
268 /*! Set visibility of Iso lines
269 * \param[in] theResult a result object
270 * \param[in] theShow is a visibility flag
272 MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
274 MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
276 /*! Returns current transparency in the given result
277 * \param theResult a result object
278 * \return a transparency value or -1 if it was not defined
280 MODELAPI_EXPORT double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult);
282 /*! Set transparency for the given result
283 * \param theResult a result object
284 * \param a transparency value
286 MODELAPI_EXPORT void setTransparency(std::shared_ptr<ModelAPI_Result> theResult,
287 double theTransparency);
290 /*! Copies all visualization attributes from one result to another.
291 * \param theSource a result that contains the copied attributes
292 * \param theDest a destination result that takes the visualization attributes
294 MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
295 std::shared_ptr<ModelAPI_Result> theDest);
297 /*! Copies image attribute from one result to another.
298 * \param theSource a result that contains the image data
299 * \param theDest a destination result that takes the image data
301 MODELAPI_EXPORT void copyImageAttribute(std::shared_ptr<ModelAPI_Result> theSource,
302 std::shared_ptr<ModelAPI_Result> theDest);
304 /*! Produces list of features that reference to the given target (directly or through sub-results)
305 * \param theTarget the referenced result
306 * \param theFeatureKind the resulting features filter: the feature kind or all for the empty string
307 * \param theSortResults to sort the resulting list of features by the features creation order
309 MODELAPI_EXPORT std::list<std::shared_ptr<ModelAPI_Feature> > referencedFeatures(
310 std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
311 const bool theSortResults);
314 /*! Returns a container with the current color value.
315 * These are tree int values for RGB definition.
316 * It returns the next random color.
317 * \param theValues vector of values
318 * \param theReset flag to call when disabling Auto-color
320 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues, bool theReset = false);