]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Tools.h
Salome HOME
Preparations for Split operation. It includes:
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Tools.h
4 // Created:     06 Aug 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef ModelAPI_Tools_HeaderFile
8 #define ModelAPI_Tools_HeaderFile
9
10 #include "ModelAPI.h"
11
12 #include <ModelAPI_CompositeFeature.h>
13 #include <ModelAPI_Document.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Result.h>
16 #include <ModelAPI_ResultParameter.h>
17 #include <ModelAPI_ResultCompSolid.h>
18
19 #include <GeomAPI_Shape.h>
20
21 #include <vector>
22 #include <map>
23 #include <set>
24
25 namespace ModelAPI_Tools {
26 /// Returns shape from the given Result object
27 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
28
29 /// Creates a container of shape of the feature results satisfied the given shape type
30 /// \param theFeature a source feature
31 /// \param theType shape type
32 /// \param an output container for shapes
33 MODELAPI_EXPORT void shapesOfType(const FeaturePtr& theFeature,
34                                   const GeomAPI_Shape::ShapeType& theType,
35                                   std::set<GeomShapePtr>& theShapes);
36
37 /*! Returns the feature error generated according to feature error and exec state
38  * \param theFeature a feature
39  * \return error value or empty string
40  */
41 MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
42
43 /*!
44  * Searches for variable with name \param theName in \param theDocument. 
45  * If found, set it value in the \param outValue and returns true.
46  * theSearcher must be located later in the history than the found variable.
47  */
48 MODELAPI_EXPORT bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
49   const std::string& theName, double& outValue, ResultParameterPtr& theParam);
50
51 /*!
52  * Searches for variable with name \param theName in the active document (Part), when
53  * in the root document (PartSet). If found, set it value in the \param outValue
54  * and returns true. If \param theDocument is empty active document is used.
55  * theSearcher must be located later in the history than the found variable.
56  */
57 MODELAPI_EXPORT bool findVariable(FeaturePtr theSearcher, const std::string& theName,
58   double& outValue, ResultParameterPtr& theParam,
59   const DocumentPtr& theDocument = DocumentPtr());
60
61 /*!
62  * Returns the values of the next random color. The values are in range [0, 255]
63  * \param theValues a container of component of RGB value: red, green, blue
64  */
65 MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
66
67 /*!
68  * Searches for Part result that contains the reference to the given document.
69  * The result must be presented in the tree.
70  * \param theMain document that contains the searched feature
71  * \param theSub document that is searched, the resulting feature references to it
72  * \returns null if not found
73  */
74 MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
75
76 /*!
77  * Searches for Part the feature that contains in result the reference to the given document.
78  * The result may be disabled.
79  * \param theMain document that contains the searched feature
80  * \param theSub document that is searched, the resulting feature references to it
81  * \returns null if not found
82  */
83 MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
84
85 /*!
86  * Returns the composite feature - parent of this feature.
87  * \param theFeature the sub-element of composite
88  * \returns null if it is not sub-element of composite
89  */
90 MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);
91
92 /*!
93  * Returns the compsolid result - parent of this result.
94  * \param theSub the sub-element of comp-solid
95  * \returns null if it is not sub-element of composite
96  */
97 MODELAPI_EXPORT ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub);
98
99 /*!
100 * Returns true if the result contains a not empty list of sub results. It processes result compsolid.
101 * \param theResult a result object
102 * \returns boolean value
103 */
104 MODELAPI_EXPORT bool hasSubResults(const ResultPtr& theResult);
105
106 /*!
107 * Adds the results of the given feature to theResults list: including disabled and sub-results
108 */
109 MODELAPI_EXPORT void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults);
110
111 /*!
112  Returns true if there are no parts in the document, which are not activated
113  \param theNotActivatedNames out string which contains not activated names
114  \return a boolean value
115  */
116 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
117
118
119 /*! Removes features from the document
120 * \param theFeatures a list of features to be removed
121 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
122 * \return true if at least one feature is removed
123 */
124 MODELAPI_EXPORT bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
125                                                  const bool theFlushRedisplay = false,
126                                                  const bool theUseComposite = false,
127                                                  const bool theUseRecursion = true);
128
129 /*! Removes features from the document
130 * \param theFeatures a list of features to be removed
131 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
132 * \return true if at least one feature is removed
133 */
134 MODELAPI_EXPORT bool removeFeatures(const std::set<FeaturePtr>& theFeatures,
135                                     const bool theFlushRedisplay);
136
137 /*! Build a map of references for the given set of features
138 * \param theFeatures a list of features
139 * \param theReferences a map of all references to the features
140 * \param theUseComposite state if the composite features of the reference should be in the map
141 * \param theUseRecursion state if references for features out of the sources feature
142          list are put into the result container. E.g. if theFeatures contains "Sketch_2", map will
143          contain references to this feature also.
144 */
145 MODELAPI_EXPORT void findAllReferences(const std::set<FeaturePtr>& theFeatures,
146                                        std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
147                                        const bool theUseComposite = true,
148                                        const bool theUseRecursion = true);
149
150 /*! In the map of references find all features referenced to the source feature
151 * \param theFeatures a list of features to find references
152 * \param theReferences a map of all references to the features
153 * \param theFeaturesRefsTo an out list of referenced features
154 */
155 MODELAPI_EXPORT void findRefsToFeatures(const std::set<FeaturePtr>& aFeatures,
156                                         const std::map<FeaturePtr, std::set<FeaturePtr> >& aReferences,
157                                         std::set<FeaturePtr>& aFeaturesRefsTo);
158 }
159
160 #endif