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;
32 class GeomAlgoAPI_MakeShape;
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);
53 MODELAPI_EXPORT struct ResultBaseAlgo {
54 std::shared_ptr<ModelAPI_ResultBody> resultBody;
55 std::shared_ptr<GeomAPI_Shape> baseShape;
56 std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
59 MODELAPI_EXPORT void loadModifiedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
60 const std::list<std::shared_ptr<GeomAPI_Shape>>& theBaseShapes,
61 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
62 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
63 const std::shared_ptr<GeomAPI_Shape> theResultShape,
64 const std::string& theNamePrefix = "");
66 MODELAPI_EXPORT void loadModifiedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
67 const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
68 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
69 const std::string theName);
70 /// Stores deleted shapes.
71 MODELAPI_EXPORT void loadDeletedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
72 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
73 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
74 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
75 const std::shared_ptr<GeomAPI_Shape> theResultShapesCompound);
77 /// Stores deleted shapes.
78 MODELAPI_EXPORT void loadDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
79 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
80 const std::shared_ptr<GeomAPI_Shape> theResultShapesCompound);
83 * Searches for variable with name \param theName in \param theDocument.
84 * If found, set it value in the \param outValue and returns true.
85 * theSearcher must be located later in the history than the found variable.
87 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
88 std::shared_ptr<ModelAPI_Feature> theSearcher,
89 const std::wstring& theName, double& outValue,
90 std::shared_ptr<ModelAPI_ResultParameter>& theParam);
93 * Searches for variable with name \param theName in the active document (Part), when
94 * in the root document (PartSet). If found, set it value in the \param outValue
95 * and returns true. If \param theDocument is empty active document is used.
96 * theSearcher must be located later in the history than the found variable.
98 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
99 const std::wstring& theName,
100 double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
101 const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
104 * Searches for Part result that contains the reference to the given document.
105 * The result must be presented in the tree.
106 * \param theMain document that contains the searched feature
107 * \param theSub document that is searched, the resulting feature references to it
108 * \returns null if not found
110 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> findPartResult(
111 const std::shared_ptr<ModelAPI_Document>& theMain,
112 const std::shared_ptr<ModelAPI_Document>& theSub);
115 * Searches for Part the feature that contains in result the reference to the given document.
116 * The result may be disabled.
117 * \param theMain document that contains the searched feature
118 * \param theSub document that is searched, the resulting feature references to it
119 * \returns null if not found
121 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
122 const std::shared_ptr<ModelAPI_Document>& theMain,
123 const std::shared_ptr<ModelAPI_Document>& theSub);
126 * Returns the composite feature - parent of this feature.
127 * \param theFeature the sub-element of composite
128 * \returns null if it is not sub-element of composite
130 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
131 const std::shared_ptr<ModelAPI_Feature>& theFeature);
134 * Returns the result - parent of this result.
135 * \param theSub the sub-element of composit result
136 * \param theRoot if it is true, returns the root father
137 * \returns null if it is not sub-element of composite
139 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
140 bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
142 * Returns index of this result in parent (if parent exists, returned by bodyOwner)
143 * \returns zero-base index, or -1 if not found
145 MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
148 * Returns true if the result contains a not empty list of sub results.
149 * It processes result compsolid.
150 * \param theResult a result object
151 * \returns boolean value
153 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
156 * collects recursively all subs of the given result
158 MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
159 std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
160 const bool theLowerOnly = false);
163 * Adds the results of the given feature to theResults list: including disabled and sub-results
165 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
166 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
169 Returns true if there are no parts in the document, which are not activated
170 \param theNotActivatedNames out string which contains not activated names
171 \return a boolean value
173 MODELAPI_EXPORT bool allDocumentsActivated(std::wstring& theNotActivatedNames);
175 /*! Removes features from the document
176 * \param theFeatures a list of features to be removed
177 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
178 * \return true if at least one feature is removed
180 MODELAPI_EXPORT bool removeFeaturesAndReferences(
181 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
182 const bool theFlushRedisplay = false,
183 const bool theUseComposite = false,
184 const bool theUseRecursion = true);
186 /*! Removes features from the document
187 * \param theFeatures a list of features to be removed
188 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
189 * \return true if at least one feature is removed
191 MODELAPI_EXPORT bool removeFeatures(
192 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
193 const bool theFlushRedisplay);
195 /*! Build a map of references for the given set of features
196 * \param theFeatures a list of features
197 * \param theReferences a map of all references to the features
198 * \param theUseComposite state if the composite features of the reference should be in the map
199 * \param theUseRecursion state if references for features out of the sources feature
200 list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
201 contain references to this feature also.
203 MODELAPI_EXPORT void findAllReferences(
204 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
205 std::map<std::shared_ptr<ModelAPI_Feature>,
206 std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
207 const bool theUseComposite = true,
208 const bool theUseRecursion = true);
210 /*! In the map of references find all features referenced to the source feature
211 * \param theFeatures a list of features to find references
212 * \param theReferences a map of all references to the features
213 * \param theFeaturesRefsTo an out list of referenced features
215 MODELAPI_EXPORT void findRefsToFeatures(
216 const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
217 const std::map<std::shared_ptr<ModelAPI_Feature>,
218 std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
219 std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
221 /*! Finds referenced of the feature to objects and collects concealed results.
222 * \param theFeatures a model feature
223 * \param theResults container for concealed results. It has no duplications
225 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
226 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
228 /*! Return the default name of the result according the features it depends or name of the feature.
229 * Return also whether the name is get from the concealing result of parent object
230 * (means that concealing result has user-defined name).
231 * \param[in] theRecursive recursively check the concealed results if they have user-defined names
233 MODELAPI_EXPORT std::pair<std::wstring, bool> getDefaultName(
234 const std::shared_ptr<ModelAPI_Result>& theResult,
235 const bool theInherited = true,
236 const bool theRecursive = false);
238 /*! Collect all parents for the given feature, including the Part
240 MODELAPI_EXPORT std::set<std::shared_ptr<ModelAPI_Feature> >
241 getParents(const std::shared_ptr<ModelAPI_Feature>& theFeature);
243 /*! Store shape and its parent shape to the hierarchy data structure
244 * \param[in] theShape the shape to store
245 * \param[in] theContext the result (parent shape) for the given shape
246 * \param[out] theHierarchy container for shape hierarchy
248 MODELAPI_EXPORT void fillShapeHierarchy(
249 const std::shared_ptr<GeomAPI_Shape>& theShape,
250 const std::shared_ptr<ModelAPI_Result>& theContext,
251 GeomAPI_ShapeHierarchy& theHierarchy);
253 /*! Creates a remove result features with the given results
255 MODELAPI_EXPORT void removeResults(const std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
257 /*! Returns current deflection in the given result
258 * \param theResult a result object
259 * \return a deflection value or -1 if it was not defined
261 MODELAPI_EXPORT double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult);
263 /*! Sets the deflection value
264 * \param theResult a result object
265 * \param a deflection value
267 MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
268 const double theDeflection);
270 /*! Returns current color of the current result
271 * \param[in] theResult a result object
272 * \param[out] theColor a color values if it is defined
274 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
275 std::vector<int>& theColor);
277 /*! Set color of the result
278 * \param[in] theResult a result object
279 * \param[in] theColor a color values
281 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
282 const std::vector<int>& theColor);
284 /*! Returns number of iso-lines of the current result
285 * \param[in] theResult a result object
286 * \param[out] theNbLines values of iso-lines
288 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
289 bool& isVisible, std::vector<int>& theNbLines);
291 /*! Set number of iso-lines of the result
292 * \param[in] theResult a result object
293 * \param[in] theIso nb iso-lines
295 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
296 const std::vector<int>& theIso);
298 /*! Set visibility of Iso lines
299 * \param[in] theResult a result object
300 * \param[in] theShow is a visibility flag
302 MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
304 MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
306 /*! Returns current transparency in the given result
307 * \param theResult a result object
308 * \return a transparency value or -1 if it was not defined
310 MODELAPI_EXPORT double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult);
312 /*! Set transparency for the given result
313 * \param theResult a result object
314 * \param a transparency value
316 MODELAPI_EXPORT void setTransparency(std::shared_ptr<ModelAPI_Result> theResult,
317 double theTransparency);
320 /*! Copies all visualization attributes from one result to another.
321 * \param theSource a result that contains the copied attributes
322 * \param theDest a destination result that takes the visualization attributes
324 MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
325 std::shared_ptr<ModelAPI_Result> theDest);
327 /*! Produces list of features that reference to the given target (directly or through sub-results)
328 * \param theTarget the referenced result
329 * \param theFeatureKind the resulting features filter: the feature kind or all for the empty string
330 * \param theSortResults to sort the resulting list of features by the features creation order
332 MODELAPI_EXPORT std::list<std::shared_ptr<ModelAPI_Feature> > referencedFeatures(
333 std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
334 const bool theSortResults);
337 /*! Returns a container with the current color value.
338 * These are tree int values for RGB definition.
339 * It returns the next random color.
340 * \param theValues vector of values
341 * \param theReset flag to call when disabling Auto-color
343 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues, bool theReset = false);