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
24 #include <ModelAPI_AttributeSelectionList.h>
26 class ModelAPI_CompositeFeature;
27 class ModelAPI_Document;
28 class ModelAPI_Feature;
29 class ModelAPI_Result;
30 class ModelAPI_ResultParameter;
31 class ModelAPI_ResultBody;
34 class GeomAPI_ShapeHierarchy;
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);
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
51 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
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.
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);
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.
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>());
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
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);
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
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);
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
101 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
102 const std::shared_ptr<ModelAPI_Feature>& theFeature);
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
110 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
111 bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
113 * Returns index of this result in parent (if parent exists, returned by bodyOwner)
114 * \returns zero-base index, or -1 if not found
116 MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
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
124 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
127 * collects recursively all subs of the given result
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);
134 * Adds the results of the given feature to theResults list: including disabled and sub-results
136 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
137 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
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
144 MODELAPI_EXPORT bool allDocumentsActivated(std::wstring& theNotActivatedNames);
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
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);
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
162 MODELAPI_EXPORT bool removeFeatures(
163 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
164 const bool theFlushRedisplay);
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.
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);
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
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);
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
196 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
197 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
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
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);
209 /*! Collect all parents for the given feature, including the Part
211 MODELAPI_EXPORT std::set<std::shared_ptr<ModelAPI_Feature> >
212 getParents(const std::shared_ptr<ModelAPI_Feature>& theFeature);
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
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);
224 /*! Creates a remove result features with the given results
226 MODELAPI_EXPORT void removeResults(const std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
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
232 MODELAPI_EXPORT double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult);
234 /*! Sets the deflection value
235 * \param theResult a result object
236 * \param a deflection value
238 MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
239 const double theDeflection);
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
245 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
246 std::vector<int>& theColor);
248 /*! Set color of the result
249 * \param[in] theResult a result object
250 * \param[in] theColor a color values
252 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
253 const std::vector<int>& theColor);
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
259 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
260 bool& isVisible, std::vector<int>& theNbLines);
262 /*! Set number of iso-lines of the result
263 * \param[in] theResult a result object
264 * \param[in] theIso nb iso-lines
266 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
267 const std::vector<int>& theIso);
269 /*! Set visibility of Iso lines
270 * \param[in] theResult a result object
271 * \param[in] theShow is a visibility flag
273 MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
275 MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
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
281 MODELAPI_EXPORT double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult);
283 /*! Set transparency for the given result
284 * \param theResult a result object
285 * \param a transparency value
287 MODELAPI_EXPORT void setTransparency(std::shared_ptr<ModelAPI_Result> theResult,
288 double theTransparency);
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
295 MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
296 std::shared_ptr<ModelAPI_Result> theDest);
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
302 MODELAPI_EXPORT void copyImageAttribute(std::shared_ptr<ModelAPI_Result> theSource,
303 std::shared_ptr<ModelAPI_Result> theDest);
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
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);
315 * Returns true if something in selection is presented in the results list
317 MODELAPI_EXPORT bool isInResults(AttributeSelectionListPtr theSelection,
318 const std::list<ResultPtr>& theResults,
319 std::set<ResultPtr>& theCashedResults);
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
327 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues, bool theReset = false);