1 // Copyright (C) 2014-2023 CEA, EDF
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;
33 class GeomAlgoAPI_MakeShape;
35 class GeomAPI_ShapeHierarchy;
43 namespace ModelAPI_Tools {
44 /// Returns shape from the given Result object
45 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
46 const std::shared_ptr<ModelAPI_Result>& theResult);
48 /*! Returns the feature error generated according to feature error and exec state
49 * \param theFeature a feature
50 * \return error value or empty string
52 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
54 struct ResultBaseAlgo {
55 std::shared_ptr<ModelAPI_ResultBody> resultBody;
56 std::shared_ptr<GeomAPI_Shape> baseShape;
57 std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
60 MODELAPI_EXPORT void loadModifiedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
61 const std::list<std::shared_ptr<GeomAPI_Shape>>& theBaseShapes,
62 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
63 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
64 const std::shared_ptr<GeomAPI_Shape> theResultShape,
65 const std::string& theNamePrefix = "");
67 MODELAPI_EXPORT void loadModifiedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
68 const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
69 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
70 const std::string theName);
71 /// Stores deleted shapes.
72 MODELAPI_EXPORT void loadDeletedShapes(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
73 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
74 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
75 const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
76 const std::shared_ptr<GeomAPI_Shape> theResultShapesCompound);
78 /// Stores deleted shapes.
79 MODELAPI_EXPORT void loadDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
80 const std::list<std::shared_ptr<GeomAPI_Shape>>& theTools,
81 const std::shared_ptr<GeomAPI_Shape> theResultShapesCompound);
84 * Searches for variable with name \param theName in \param theDocument.
85 * If found, set it value in the \param outValue and returns true.
86 * theSearcher must be located later in the history than the found variable.
88 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
89 std::shared_ptr<ModelAPI_Feature> theSearcher,
90 const std::wstring& theName, double& outValue,
91 std::shared_ptr<ModelAPI_ResultParameter>& theParam);
94 * Searches for variable with name \param theName in the active document (Part), when
95 * in the root document (PartSet). If found, set it value in the \param outValue
96 * and returns true. If \param theDocument is empty active document is used.
97 * theSearcher must be located later in the history than the found variable.
99 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
100 const std::wstring& theName,
101 double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
102 const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
105 * Searches for Part result that contains the reference to the given document.
106 * The result must be presented in the tree.
107 * \param theMain document that contains the searched feature
108 * \param theSub document that is searched, the resulting feature references to it
109 * \returns null if not found
111 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> findPartResult(
112 const std::shared_ptr<ModelAPI_Document>& theMain,
113 const std::shared_ptr<ModelAPI_Document>& theSub);
116 * Searches for Part the feature that contains in result the reference to the given document.
117 * The result may be disabled.
118 * \param theMain document that contains the searched feature
119 * \param theSub document that is searched, the resulting feature references to it
120 * \returns null if not found
122 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
123 const std::shared_ptr<ModelAPI_Document>& theMain,
124 const std::shared_ptr<ModelAPI_Document>& theSub);
127 * Returns the composite feature - parent of this feature.
128 * \param theFeature the sub-element of composite
129 * \returns null if it is not sub-element of composite
131 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
132 const std::shared_ptr<ModelAPI_Feature>& theFeature);
135 * Returns the result - parent of this result.
136 * \param theSub the sub-element of composit result
137 * \param theRoot if it is true, returns the root father
138 * \returns null if it is not sub-element of composite
140 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
141 bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
143 * Returns index of this result in parent (if parent exists, returned by bodyOwner)
144 * \returns zero-base index, or -1 if not found
146 MODELAPI_EXPORT int bodyIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
149 * Returns true if the result contains a not empty list of sub results.
150 * It processes result compsolid.
151 * \param theResult a result object
152 * \returns boolean value
154 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
157 * collects recursively all subs of the given result
159 MODELAPI_EXPORT void allSubs(const std::shared_ptr<ModelAPI_ResultBody>& theResult,
160 std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
161 const bool theLowerOnly = false);
164 * Adds the results of the given feature to theResults list: including disabled and sub-results
166 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
167 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
170 Returns true if there are no parts in the document, which are not activated
171 \param theNotActivatedNames out string which contains not activated names
172 \return a boolean value
174 MODELAPI_EXPORT bool allDocumentsActivated(std::wstring& theNotActivatedNames);
176 /*! Removes features from the document
177 * \param theFeatures a list of features to be removed
178 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
179 * \return true if at least one feature is removed
181 MODELAPI_EXPORT bool removeFeaturesAndReferences(
182 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
183 const bool theFlushRedisplay = false,
184 const bool theUseComposite = false,
185 const bool theUseRecursion = true);
187 /*! Removes features from the document
188 * \param theFeatures a list of features to be removed
189 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
190 * \return true if at least one feature is removed
192 MODELAPI_EXPORT bool removeFeatures(
193 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
194 const bool theFlushRedisplay);
196 /*! Build a map of references for the given set of features
197 * \param theFeatures a list of features
198 * \param theReferences a map of all references to the features
199 * \param theUseComposite state if the composite features of the reference should be in the map
200 * \param theUseRecursion state if references for features out of the sources feature
201 list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
202 contain references to this feature also.
204 MODELAPI_EXPORT void findAllReferences(
205 const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
206 std::map<std::shared_ptr<ModelAPI_Feature>,
207 std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
208 const bool theUseComposite = true,
209 const bool theUseRecursion = true);
211 /*! In the map of references find all features referenced to the source feature
212 * \param theFeatures a list of features to find references
213 * \param theReferences a map of all references to the features
214 * \param theFeaturesRefsTo an out list of referenced features
216 MODELAPI_EXPORT void findRefsToFeatures(
217 const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
218 const std::map<std::shared_ptr<ModelAPI_Feature>,
219 std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
220 std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
222 /*! Finds referenced of the feature to objects and collects concealed results.
223 * \param theFeatures a model feature
224 * \param theResults container for concealed results. It has no duplications
226 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
227 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
229 /*! Return the default name of the result according the features it depends or name of the feature.
230 * Return also whether the name is get from the concealing result of parent object
231 * (means that concealing result has user-defined name).
232 * \param[in] theRecursive recursively check the concealed results if they have user-defined names
234 MODELAPI_EXPORT std::pair<std::wstring, bool> getDefaultName(
235 const std::shared_ptr<ModelAPI_Result>& theResult,
236 const bool theInherited = true,
237 const bool theRecursive = false);
239 /*! Collect all parents for the given feature, including the Part
241 MODELAPI_EXPORT std::set<std::shared_ptr<ModelAPI_Feature> >
242 getParents(const std::shared_ptr<ModelAPI_Feature>& theFeature);
244 /*! Store shape and its parent shape to the hierarchy data structure
245 * \param[in] theShape the shape to store
246 * \param[in] theContext the result (parent shape) for the given shape
247 * \param[out] theHierarchy container for shape hierarchy
249 MODELAPI_EXPORT void fillShapeHierarchy(
250 const std::shared_ptr<GeomAPI_Shape>& theShape,
251 const std::shared_ptr<ModelAPI_Result>& theContext,
252 GeomAPI_ShapeHierarchy& theHierarchy);
254 /*! Creates a remove result features with the given results
256 MODELAPI_EXPORT void removeResults(const std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
258 /*! Returns current deflection in the given result
259 * \param theResult a result object
260 * \return a deflection value or -1 if it was not defined
262 MODELAPI_EXPORT double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult);
264 /*! Sets the deflection value
265 * \param theResult a result object
266 * \param a deflection value
268 MODELAPI_EXPORT void setDeflection(std::shared_ptr<ModelAPI_Result> theResult,
269 const double theDeflection);
271 /*! Returns current color of the current result
272 * \param[in] theResult a result object
273 * \param[out] theColor a color values if it is defined
275 MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
276 std::vector<int>& theColor);
278 /*! Set color of the result
279 * \param[in] theResult a result object
280 * \param[in] theColor a color values
282 MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
283 const std::vector<int>& theColor);
285 /*! Returns number of iso-lines of the current result
286 * \param[in] theResult a result object
287 * \param[out] theNbLines values of iso-lines
289 MODELAPI_EXPORT void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
290 bool& isVisible, std::vector<int>& theNbLines);
292 /*! Set number of iso-lines of the result
293 * \param[in] theResult a result object
294 * \param[in] theIso nb iso-lines
296 MODELAPI_EXPORT void setIsoLines(std::shared_ptr<ModelAPI_Result> theResult,
297 const std::vector<int>& theIso);
299 /*! Set visibility of Iso lines
300 * \param[in] theResult a result object
301 * \param[in] theShow is a visibility flag
303 MODELAPI_EXPORT void showIsoLines(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
305 MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr<ModelAPI_Result> theResult);
307 /*! Set visibility of edges direction
308 * \param[in] theResult a result object
309 * \param[in] theShow is a visibility flag
311 MODELAPI_EXPORT void showEdgesDirection(std::shared_ptr<ModelAPI_Result> theResult, bool theShow);
313 MODELAPI_EXPORT bool isShowEdgesDirection(std::shared_ptr<ModelAPI_Result> theResult);
315 /*! Set flag to bring result in front of other results
316 * \param[in] theResult a result object
317 * \param[in] theFlag is a flag
319 MODELAPI_EXPORT void bringToFront(std::shared_ptr<ModelAPI_Result> theResult, bool theFlag);
321 MODELAPI_EXPORT bool isBringToFront(std::shared_ptr<ModelAPI_Result> theResult);
323 /*! Returns current transparency in the given result
324 * \param theResult a result object
325 * \return a transparency value or -1 if it was not defined
327 MODELAPI_EXPORT double getTransparency(const std::shared_ptr<ModelAPI_Result>& theResult);
329 /*! Set transparency for the given result
330 * \param theResult a result object
331 * \param a transparency value
333 MODELAPI_EXPORT void setTransparency(std::shared_ptr<ModelAPI_Result> theResult,
334 double theTransparency);
337 /*! Copies all visualization attributes from one result to another.
338 * \param theSource a result that contains the copied attributes
339 * \param theDest a destination result that takes the visualization attributes
341 MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
342 std::shared_ptr<ModelAPI_Result> theDest);
344 /*! Copies image attribute from one result to another.
345 * \param theSource a result that contains the image data
346 * \param theDest a destination result that takes the image data
348 MODELAPI_EXPORT void copyImageAttribute(std::shared_ptr<ModelAPI_Result> theSource,
349 std::shared_ptr<ModelAPI_Result> theDest);
351 /*! Produces list of features that reference to the given target (directly or through sub-results)
352 * \param theTarget the referenced result
353 * \param theFeatureKind the resulting features filter: the feature kind or all for the empty string
354 * \param theSortResults to sort the resulting list of features by the features creation order
356 MODELAPI_EXPORT std::list<std::shared_ptr<ModelAPI_Feature> > referencedFeatures(
357 std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
358 const bool theSortResults);
361 * Returns true if something in selection is presented in the results list
363 MODELAPI_EXPORT bool isInResults(AttributeSelectionListPtr theSelection,
364 const std::list<ResultPtr>& theResults,
365 std::set<ResultPtr>& theCashedResults);
367 /*! Returns a container with the current color value.
368 * These are tree int values for RGB definition.
369 * It returns the next random color.
370 * \param theValues vector of values
371 * \param theReset flag to call when disabling Auto-color
373 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues, bool theReset = false);
376 * Checks the movement of features possibility. The feature cannot appear before the feature
377 * depended on it. Used in drag and drop part features.
378 * \param theAfter feature after which the moved features are placed, or null for the first place
379 * \param theMoved ordered list of the moved features
380 * \returns string with error text, dependencies that do not allow make movement or empty string
382 MODELAPI_EXPORT std::wstring validateMovement(
383 const FeaturePtr& theAfter, const std::list<FeaturePtr> theMoved);