]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Tools.h
Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
[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 class ModelAPI_CompositeFeature;
13 class ModelAPI_Document;
14 class ModelAPI_Feature;
15 class ModelAPI_Result;
16 class ModelAPI_ResultParameter;
17 class ModelAPI_ResultCompSolid;
18
19 class GeomAPI_Shape;
20
21 #include <vector>
22 #include <map>
23 #include <set>
24 #include <list>
25
26 namespace ModelAPI_Tools {
27 /// Returns shape from the given Result object
28 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(
29                                    const std::shared_ptr<ModelAPI_Result>& theResult);
30
31 /*! Returns the feature error generated according to feature error and exec state
32  * \param theFeature a feature
33  * \return error value or empty string
34  */
35 MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr<ModelAPI_Feature>& theFeature);
36
37 /*!
38  * Searches for variable with name \param theName in \param theDocument. 
39  * If found, set it value in the \param outValue and returns true.
40  * theSearcher must be located later in the history than the found variable.
41  */
42 MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
43                                   std::shared_ptr<ModelAPI_Feature> theSearcher,
44                                   const std::string& theName, double& outValue,
45                                   std::shared_ptr<ModelAPI_ResultParameter>& theParam);
46
47 /*!
48  * Searches for variable with name \param theName in the active document (Part), when
49  * in the root document (PartSet). If found, set it value in the \param outValue
50  * and returns true. If \param theDocument is empty active document is used.
51  * theSearcher must be located later in the history than the found variable.
52  */
53 MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
54   const std::string& theName,
55   double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
56   const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
57
58 /*!
59  * Searches for Part result that contains the reference to the given document.
60  * The result must be presented in the tree.
61  * \param theMain document that contains the searched feature
62  * \param theSub document that is searched, the resulting feature references to it
63  * \returns null if not found
64  */
65 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> findPartResult(
66                                               const std::shared_ptr<ModelAPI_Document>& theMain,
67                                               const std::shared_ptr<ModelAPI_Document>& theSub);
68
69 /*!
70  * Searches for Part the feature that contains in result the reference to the given document.
71  * The result may be disabled.
72  * \param theMain document that contains the searched feature
73  * \param theSub document that is searched, the resulting feature references to it
74  * \returns null if not found
75  */
76 MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> findPartFeature(
77                                            const std::shared_ptr<ModelAPI_Document>& theMain,
78                                            const std::shared_ptr<ModelAPI_Document>& theSub);
79
80 /*!
81  * Returns the composite feature - parent of this feature.
82  * \param theFeature the sub-element of composite
83  * \returns null if it is not sub-element of composite
84  */
85 MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
86                                         const std::shared_ptr<ModelAPI_Feature>& theFeature);
87
88 /*!
89  * Returns the compsolid result - parent of this result.
90  * \param theSub the sub-element of comp-solid
91  * \returns null if it is not sub-element of composite
92  */
93 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultCompSolid> compSolidOwner(
94                                             const std::shared_ptr<ModelAPI_Result>& theSub);
95
96 /*!
97 * Returns true if the result contains a not empty list of sub results.
98 * It processes result compsolid.
99 * \param theResult a result object
100 * \returns boolean value
101 */
102 MODELAPI_EXPORT bool hasSubResults(const std::shared_ptr<ModelAPI_Result>& theResult);
103
104 /*!
105 * Adds the results of the given feature to theResults list: including disabled and sub-results
106 */
107 MODELAPI_EXPORT void allResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
108                                 std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
109
110 /*!
111  Returns true if there are no parts in the document, which are not activated
112  \param theNotActivatedNames out string which contains not activated names
113  \return a boolean value
114  */
115 MODELAPI_EXPORT bool allDocumentsActivated(std::string& theNotActivatedNames);
116
117 /*! Removes features from the document
118 * \param theFeatures a list of features to be removed
119 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
120 * \return true if at least one feature is removed
121 */
122 MODELAPI_EXPORT bool removeFeaturesAndReferences(
123                        const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
124                                                  const bool theFlushRedisplay = false,
125                                                  const bool theUseComposite = false,
126                                                  const bool theUseRecursion = true);
127
128 /*! Removes features from the document
129 * \param theFeatures a list of features to be removed
130 * \param theFlushRedisplay a boolean value if the redisplay signal should be flushed
131 * \return true if at least one feature is removed
132 */
133 MODELAPI_EXPORT bool removeFeatures(
134                             const std::set<std::shared_ptr<ModelAPI_Feature> >& 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(
146   const std::set<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
147   std::map<std::shared_ptr<ModelAPI_Feature>,
148   std::set<std::shared_ptr<ModelAPI_Feature> > >& theReferences,
149   const bool theUseComposite = true,
150   const bool theUseRecursion = true);
151
152 /*! In the map of references find all features referenced to the source feature
153 * \param theFeatures a list of features to find references
154 * \param theReferences a map of all references to the features
155 * \param theFeaturesRefsTo an out list of referenced features
156 */
157 MODELAPI_EXPORT void findRefsToFeatures(
158   const std::set<std::shared_ptr<ModelAPI_Feature> >& aFeatures,
159   const std::map<std::shared_ptr<ModelAPI_Feature>,
160                  std::set<std::shared_ptr<ModelAPI_Feature> > >& aReferences,
161   std::set<std::shared_ptr<ModelAPI_Feature> >& aFeaturesRefsTo);
162
163 /*! Finds referenced of the feature to objects and collects concealed results.
164 * \param theFeatures a model feature
165 * \param theResults container for concealed results. It has no duplications
166 */
167 MODELAPI_EXPORT void getConcealedResults(const std::shared_ptr<ModelAPI_Feature>& theFeature,
168                                    std::list<std::shared_ptr<ModelAPI_Result> >& theResults);
169 }
170
171 #endif