]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Tools.cpp
Salome HOME
Fix for the issue #2165 : reuse of the variable in expression of this variable is...
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Tools.cpp
4 // Created:     06 Aug 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "ModelAPI_Tools.h"
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_CompositeFeature.h>
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Object.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_ResultCompSolid.h>
14 #include <ModelAPI_ResultParameter.h>
15 #include <ModelAPI_ResultPart.h>
16 #include <ModelAPI_AttributeDocRef.h>
17 #include <ModelAPI_Validator.h>
18 #include <list>
19 #include <map>
20 #include <iostream>
21
22 #include <Events_Loop.h>
23 #include <ModelAPI_Events.h>
24
25 #define RECURSE_TOP_LEVEL 50
26
27 //#define DEBUG_REMOVE_FEATURES
28 //#define DEBUG_REMOVE_FEATURES_RECURSE
29 //#define DEBUG_CYCLING_1550
30
31 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
32 #include <sstream>
33 std::string getFeatureInfo(FeaturePtr theFeature)
34 {
35   if (!theFeature.get())
36     return "";
37   //std::ostringstream aPtrStr;
38   //aPtrStr << "[" << theFeature.get() << "] ";
39   std::string aFeatureInfo = /*aPtrStr.str() + */theFeature->name();
40   CompositeFeaturePtr aComposite = ModelAPI_Tools::compositeOwner(theFeature);
41   if (aComposite.get()) {
42       aFeatureInfo = aFeatureInfo + "[in " + aComposite->name() + "]";
43   }
44   return aFeatureInfo;
45 }
46 #endif
47
48 #ifdef DEBUG_REMOVE_FEATURES
49 void printMapInfo(const std::map<FeaturePtr, std::set<FeaturePtr> >& theMainList,
50                   const std::string& thePrefix)
51 {
52   std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = theMainList.begin(),
53                                                               aMainLast = theMainList.end();
54   std::string anInfo;
55   for (; aMainIt != aMainLast; aMainIt++) {
56     FeaturePtr aMainListFeature = aMainIt->first;
57     std::set<FeaturePtr> aMainRefList = aMainIt->second;
58     std::set<FeaturePtr>::const_iterator anIt = aMainRefList.begin(), aLast = aMainRefList.end();
59     std::string aRefsInfo;
60     for (; anIt != aLast; anIt++) {
61       aRefsInfo += (*anIt)->name().c_str();
62       if (anIt != aLast)
63         aRefsInfo += ", ";
64     }
65     if (!aRefsInfo.empty()) {
66       anInfo = anInfo + aMainListFeature->name().c_str() + ": " + aRefsInfo + "\n";
67     }
68   }
69   std::cout << thePrefix.c_str() << " [feature: references to]: \n" << anInfo.c_str() << std::endl;
70 }
71
72 void printListInfo(const std::set<FeaturePtr>& theMainList,
73                   const std::string& thePrefix)
74 {
75   std::set<FeaturePtr>::const_iterator aMainIt = theMainList.begin(),
76                                        aMainLast = theMainList.end();
77   std::string anInfo;
78   for (; aMainIt != aMainLast; aMainIt++) {
79     FeaturePtr aRefFeature = *aMainIt;
80     anInfo += aRefFeature->name().c_str();
81     if (aMainIt != aMainLast)
82       anInfo += ", ";
83   }
84   std::cout << thePrefix.c_str() << ": " << anInfo.c_str() << std::endl;
85 }
86 #endif
87
88 namespace ModelAPI_Tools {
89
90 std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
91 {
92   return theResult->shape();
93 }
94
95 const char* toString(ModelAPI_ExecState theExecState)
96 {
97 #define TO_STRING(__NAME__) case __NAME__: return #__NAME__;
98   switch (theExecState) {
99   TO_STRING(ModelAPI_StateDone)
100   TO_STRING(ModelAPI_StateMustBeUpdated)
101   TO_STRING(ModelAPI_StateExecFailed)
102   TO_STRING(ModelAPI_StateInvalidArgument)
103   TO_STRING(ModelAPI_StateNothing)
104   default: return "Unknown ExecState.";
105   }
106 #undef TO_STRING
107 }
108
109 std::string getFeatureError(const FeaturePtr& theFeature)
110 {
111   std::string anError;
112   if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
113     return anError;
114
115   // to be removed later, this error should be got from the feature
116   if (theFeature->data()->execState() == ModelAPI_StateDone ||
117       theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
118     return anError;
119
120   // set error indication
121   anError = theFeature->error();
122   if (anError.empty()) {
123     bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
124                  || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
125     if (!isDone) {
126       anError = toString(theFeature->data()->execState());
127       // If the feature is Composite and error is StateInvalidArgument,
128       // error text should include error of first invalid sub-feature. Otherwise
129       // it is not clear what is the reason of the invalid argument.
130       if (theFeature->data()->execState() == ModelAPI_StateInvalidArgument) {
131         CompositeFeaturePtr aComposite =
132                     std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
133         if (aComposite) {
134           for (int i = 0, aSize = aComposite->numberOfSubs(); i < aSize; i++) {
135             FeaturePtr aSubFeature = aComposite->subFeature(i);
136             std::string aSubFeatureError = getFeatureError(aSubFeature);
137             if (!aSubFeatureError.empty()) {
138               anError = anError + " in " + aSubFeature->getKind() + ".\n" + aSubFeatureError;
139               break;
140             }
141           }
142         }
143       }
144     }
145   }
146
147   return anError;
148 }
149
150 ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup,
151                        const std::string& theName)
152 {
153   for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) {
154     ObjectPtr anObject = theDocument->object(theGroup, anIndex);
155     if (anObject->data()->name() == theName)
156       return anObject;
157   }
158   // not found
159   return ObjectPtr();
160 }
161
162 bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher,
163                   const std::string& theName, double& outValue, ResultParameterPtr& theParam)
164 {
165   ObjectPtr aParamObj = objectByName(theDocument, ModelAPI_ResultParameter::group(), theName);
166   theParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
167   if (!theParam.get())
168     return false;
169   // avoid usage of parameters created later than the initial parameter
170
171   if (theSearcher.get()) {
172     FeaturePtr aParamFeat = theDocument->feature(theParam);
173     if (aParamFeat == theSearcher || theDocument->isLater(aParamFeat, theSearcher))
174       return false;
175   }
176   AttributeDoublePtr aValueAttribute = theParam->data()->real(ModelAPI_ResultParameter::VALUE());
177   outValue = aValueAttribute->value();
178   return true;
179 }
180
181 bool findVariable(FeaturePtr theSearcher, const std::string& theName, double& outValue,
182                   ResultParameterPtr& theParam, const DocumentPtr& theDocument)
183 {
184   SessionPtr aSession = ModelAPI_Session::get();
185   std::list<DocumentPtr> aDocList;
186   DocumentPtr aDocument = theDocument.get() ? theDocument : aSession->activeDocument();
187   if (findVariable(aDocument, theSearcher, theName, outValue, theParam))
188     return true;
189   DocumentPtr aRootDocument = aSession->moduleDocument();
190   if (aDocument != aRootDocument) {
191     // any parameters in PartSet is okindependently on the Part position (issu #1504)
192     if (findVariable(aRootDocument, FeaturePtr(), theName, outValue, theParam))
193       return true;
194   }
195   return false;
196 }
197
198 ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
199 {
200   // to optimize and avoid of crash on partset document close
201   // (don't touch the sub-document structure)
202   if (theMain != theSub) {
203     for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
204       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
205           theMain->object(ModelAPI_ResultPart::group(), a));
206       if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
207         return aPart;
208       }
209     }
210   }
211   return ResultPtr();
212 }
213
214 FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub)
215 {
216   // to optimize and avoid of crash on partset document close
217   // (don't touch the sub-document structure)
218   if (theMain != theSub) {
219     // iteration from top to bottom to avoid finding the movement documents before the original
220     int aSize = theMain->size(ModelAPI_Feature::group());
221     for (int a = 0; a < aSize; a++) {
222       FeaturePtr aPartFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(
223           theMain->object(ModelAPI_Feature::group(), a));
224       if (aPartFeat.get()) {
225         const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aPartFeat->results();
226         std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
227         for(; aRes != aResList.end(); aRes++) {
228           ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
229           if (aPart.get()) {
230             if (aPart->isActivated() && aPart->partDoc() == theSub)
231               return aPartFeat;
232           } else break; // if the first is not Part, others are also not
233         }
234       }
235     }
236   }
237   return FeaturePtr();
238 }
239
240 CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
241 {
242   if (theFeature.get() && theFeature->data()->isValid()) {
243     const std::set<std::shared_ptr<ModelAPI_Attribute> >& aRefs = theFeature->data()->refsToMe();
244     std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aRefIter = aRefs.begin();
245     for(; aRefIter != aRefs.end(); aRefIter++) {
246       CompositeFeaturePtr aComp = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
247         ((*aRefIter)->owner());
248       if (aComp.get() && aComp->data()->isValid() && aComp->isSub(theFeature))
249         return aComp;
250     }
251   }
252   return CompositeFeaturePtr(); // not found
253 }
254
255 ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
256 {
257   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
258   if (aBody.get()) {
259     FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
260     if (aFeatureOwner.get()) {
261       std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
262         aFeatureOwner->results().cbegin();
263       for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
264         ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
265         if (aComp && aComp->isSub(aBody))
266           return aComp;
267       }
268     }
269   }
270   return ResultCompSolidPtr(); // not found
271 }
272
273 bool hasSubResults(const ResultPtr& theResult)
274 {
275   ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
276   return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
277 }
278
279 void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults)
280 {
281   if (!theFeature.get()) // safety: for empty feature no results
282     return;
283   const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
284   std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
285   for (; aRIter != aResults.cend(); aRIter++) {
286     theResults.push_back(*aRIter);
287     // iterate sub-bodies of compsolid
288     ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
289     if (aComp.get()) {
290       int aNumSub = aComp->numberOfSubs();
291       for(int a = 0; a < aNumSub; a++) {
292         theResults.push_back(aComp->subResult(a));
293       }
294     }
295   }
296 }
297
298 //******************************************************************
299 bool allDocumentsActivated(std::string& theNotActivatedNames)
300 {
301   theNotActivatedNames = "";
302   bool anAllPartActivated = true;
303
304   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
305   int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
306   for (int i = 0; i < aSize; i++) {
307     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
308     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
309     if (!aPart->isActivated()) {
310       anAllPartActivated = false;
311       if (!theNotActivatedNames.empty())
312         theNotActivatedNames += ", ";
313       theNotActivatedNames += aObject->data()->name().c_str();
314     }
315   }
316   return anAllPartActivated;
317 }
318
319 bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
320                                  const bool theFlushRedisplay,
321                                  const bool theUseComposite,
322                                  const bool theUseRecursion)
323 {
324 #ifdef DEBUG_REMOVE_FEATURES
325   printListInfo(theFeatures, "selection: ");
326 #endif
327
328   std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
329   ModelAPI_Tools::findAllReferences(theFeatures, aReferences, theUseComposite, theUseRecursion);
330 #ifdef DEBUG_REMOVE_FEATURES
331   printMapInfo(aReferences, "allDependencies: ");
332 #endif
333
334   std::set<FeaturePtr> aFeaturesRefsTo;
335   ModelAPI_Tools::findRefsToFeatures(theFeatures, aReferences, aFeaturesRefsTo);
336 #ifdef DEBUG_REMOVE_FEATURES
337   printListInfo(aFeaturesRefsTo, "references: ");
338 #endif
339
340   std::set<FeaturePtr> aFeatures = theFeatures;
341   if (!aFeaturesRefsTo.empty())
342     aFeatures.insert(aFeaturesRefsTo.begin(), aFeaturesRefsTo.end());
343 #ifdef DEBUG_REMOVE_FEATURES
344   printListInfo(aFeatures, "removeFeatures: ");
345 #endif
346
347   return ModelAPI_Tools::removeFeatures(aFeatures, false);
348 }
349
350 bool removeFeatures(const std::set<FeaturePtr>& theFeatures,
351                     const bool theFlushRedisplay)
352 {
353   bool isDone = false;
354   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
355                                        aLast = theFeatures.end();
356   for (; anIt != aLast; anIt++) {
357     FeaturePtr aFeature = *anIt;
358     if (aFeature.get()) {
359       DocumentPtr aDoc = aFeature->document();
360       // flush REDISPLAY signal after remove feature
361       aDoc->removeFeature(aFeature);
362       isDone = true;
363     }
364   }
365   if (isDone && theFlushRedisplay) {
366     // the redisplay signal should be flushed in order to erase
367     // the feature presentation in the viewer
368     // if should be done after removeFeature() of document
369     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
370   }
371   return true;
372 }
373
374 // Fills the references list by all references of the feature from the references map.
375 // This is a recusive method to find references by next found feature in the map of references.
376 // \param theFeature a feature to find references
377 // \param theReferencesMap a map of references
378 // \param theReferences an out container of references
379 void addRefsToFeature(const FeaturePtr& theFeature,
380                       const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferencesMap,
381                       std::map<FeaturePtr, std::set<FeaturePtr> >& theProcessedReferences,
382                       int theRecLevel,
383                       std::set<FeaturePtr>& theReferences)
384 {
385   if (theRecLevel > RECURSE_TOP_LEVEL)
386     return;
387   theRecLevel++;
388
389   // if the feature is already processed, get the ready references from the map
390   if (theProcessedReferences.find(theFeature) != theProcessedReferences.end()) {
391     std::set<FeaturePtr> aReferences = theProcessedReferences.at(theFeature);
392     theReferences.insert(aReferences.begin(), aReferences.end());
393     return;
394   }
395
396   if (theReferencesMap.find(theFeature) == theReferencesMap.end())
397     return; // this feature is not in the selection list, so exists without references to it
398   std::set<FeaturePtr> aMainReferences = theReferencesMap.at(theFeature);
399
400   std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
401                                        aLast = aMainReferences.end();
402 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
403   std::string aSpacing;
404   for (int i = 0; i < theRecLevel; i++)
405     aSpacing.append(" ");
406 #endif
407
408   for (; anIt != aLast; anIt++) {
409     FeaturePtr aRefFeature = *anIt;
410 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
411   std::cout << aSpacing << " Ref: " << getFeatureInfo(aRefFeature) << std::endl;
412 #endif
413     if (theReferences.find(aRefFeature) == theReferences.end())
414       theReferences.insert(aRefFeature);
415     addRefsToFeature(aRefFeature, theReferencesMap, theProcessedReferences,
416                      theRecLevel, theReferences);
417   }
418 }
419
420 // For each feature from the feature list it searches references to the feature and append them
421 // to the references map. This is a recusive method.
422 // \param theFeature a feature to find references
423 // \param theReferencesMap a map of references
424 // \param theReferences an out container of references
425 void findReferences(const std::set<FeaturePtr>& theFeatures,
426                     std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
427                     const bool theUseComposite, const bool theUseRecursion, int theRecLevel)
428 {
429   if (theRecLevel > RECURSE_TOP_LEVEL)
430     return;
431   theRecLevel++;
432   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
433                                         aLast = theFeatures.end();
434   for (; anIt != aLast; anIt++) {
435     FeaturePtr aFeature = *anIt;
436     if (aFeature.get() && theReferences.find(aFeature) == theReferences.end()) {
437       DocumentPtr aSelFeatureDoc = aFeature->document();
438       std::set<FeaturePtr> aSelRefFeatures;
439       aSelFeatureDoc->refsToFeature(aFeature, aSelRefFeatures, false/*do not emit signals*/);
440       if (theUseComposite) { // do not filter selection
441         theReferences[aFeature] = aSelRefFeatures;
442       }
443       else { // filter references to skip composition features of the current feature
444         std::set<FeaturePtr> aFilteredFeatures;
445         std::set<FeaturePtr>::const_iterator anIt = aSelRefFeatures.begin(),
446                                              aLast = aSelRefFeatures.end();
447         for (; anIt != aLast; anIt++) {
448           FeaturePtr aCFeature = *anIt;
449           CompositeFeaturePtr aComposite =
450             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCFeature);
451           if (aComposite.get() && aComposite->isSub(aFeature))
452             continue; /// composite of the current feature should be skipped
453           aFilteredFeatures.insert(aCFeature);
454         }
455         theReferences[aFeature] = aFilteredFeatures;
456       }
457       if (theUseRecursion) {
458 #ifdef DEBUG_CYCLING_1550
459         findReferences(aSelRefFeatures, theReferences, theUseComposite,
460                        theUseRecursion, theRecLevel);
461 #else
462         findReferences(theReferences[aFeature], theReferences, theUseComposite, theUseRecursion,
463                        theRecLevel);
464 #endif
465       }
466     }
467   }
468 }
469
470 void findAllReferences(const std::set<FeaturePtr>& theFeatures,
471                        std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
472                        const bool theUseComposite,
473                        const bool theUseRecursion)
474 {
475   // For dependencies, find main_list:
476   // sk_1(ext_1, vertex_1)
477   // ext_1(bool_1, sk_3)
478   // vertex_1()
479   // sk_2(ext_2)
480   // ext_2(bool_2)
481   // sk_3()
482   // Information: bool_1 is not selected, ext_2(bool_2) exists
483   // find all referenced features
484   std::map<FeaturePtr, std::set<FeaturePtr> > aMainList;
485   int aRecLevel = 0;
486   findReferences(theFeatures, aMainList, theUseComposite, theUseRecursion, aRecLevel);
487
488 #ifdef DEBUG_REMOVE_FEATURES
489   printMapInfo(aMainList, "firstDependencies");
490 #endif
491   // find all dependencies for each object:
492   // sk_1(ext_1, vertex_1) + (sk_3, bool_1)
493   // ext_1(bool_1, sk_3)
494   // vertex_1()
495   // sk_2(ext_2) + (bool_1)
496   // ext_2(bool_1)
497   // sk_3()
498   std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aMainList.begin(),
499                                                               aMainLast = aMainList.end();
500   for (; aMainIt != aMainLast; aMainIt++) {
501     FeaturePtr aMainListFeature = aMainIt->first;
502
503     //std::string aName = aMainListFeature->name();
504     std::set<FeaturePtr> aMainRefList = aMainIt->second;
505
506 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
507     char aBuf[50];
508     int n = sprintf(aBuf, "%d", aMainRefList.size());
509     std::string aSize(aBuf);
510     std::cout << "_findAllReferences for the Feature: " << getFeatureInfo(aMainListFeature)
511               << ", references size = " << aSize << std::endl;
512 #endif
513     std::set<FeaturePtr>::const_iterator anIt = aMainRefList.begin(),
514                                          aLast = aMainRefList.end();
515     std::set<FeaturePtr> aResultRefList;
516     aResultRefList.insert(aMainRefList.begin(), aMainRefList.end());
517     for (; anIt != aLast; anIt++) {
518       FeaturePtr aFeature = *anIt;
519       int aRecLevel = 0;
520 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
521       std::cout << " Ref: " << getFeatureInfo(aFeature) << std::endl;
522 #endif
523       aRecLevel++;
524       addRefsToFeature(aFeature, aMainList, theReferences,
525                        aRecLevel, aResultRefList/*aMainRefList*/);
526     }
527     theReferences[aMainListFeature] = aResultRefList;
528   }
529 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
530     std::cout << std::endl;
531 #endif
532
533 #ifdef DEBUG_REMOVE_FEATURES
534   printMapInfo(theReferences, "allDependencies");
535 #endif
536 }
537
538 void findRefsToFeatures(const std::set<FeaturePtr>& theFeatures,
539                         const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
540                         std::set<FeaturePtr>& theFeaturesRefsTo)
541 {
542   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
543                                        aLast = theFeatures.end();
544   for (; anIt != aLast; anIt++) {
545     FeaturePtr aFeature = *anIt;
546     if (theReferences.find(aFeature) == theReferences.end())
547       continue;
548     std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
549     std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
550     for (; aRefIt != aRefLast; aRefIt++) {
551       FeaturePtr aRefFeature = *aRefIt;
552       CompositeFeaturePtr aComposite =
553         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aRefFeature);
554       if (aComposite.get() && aComposite->isSub(aFeature))
555         continue; /// composite of the current feature should not be removed
556
557       if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
558           theFeaturesRefsTo.find(aRefFeature) == theFeaturesRefsTo.end()) // it is not added
559         theFeaturesRefsTo.insert(aRefFeature);
560     }
561   }
562 }
563
564 void getConcealedResults(const FeaturePtr& theFeature,
565                          std::list<std::shared_ptr<ModelAPI_Result> >& theResults)
566 {
567   SessionPtr aSession = ModelAPI_Session::get();
568
569   std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > > aRefs;
570   theFeature->data()->referencesToObjects(aRefs);
571   std::list<std::pair<std::string, std::list<ObjectPtr> > >::const_iterator
572                                                   anIt = aRefs.begin(), aLast = aRefs.end();
573   std::set<ResultPtr> alreadyThere; // to avoid duplications
574   for (; anIt != aLast; anIt++) {
575     if (!aSession->validators()->isConcealed(theFeature->getKind(), anIt->first))
576       continue; // use only concealed attributes
577     std::list<ObjectPtr> anObjects = (*anIt).second;
578     std::list<ObjectPtr>::const_iterator anOIt = anObjects.begin(), anOLast = anObjects.end();
579     for (; anOIt != anOLast; anOIt++) {
580       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*anOIt);
581       if (aResult && aResult->isConcealed()) {
582         if (alreadyThere.find(aResult) == alreadyThere.end()) // issue 1712, avoid duplicates
583           alreadyThere.insert(aResult);
584         else continue;
585         theResults.push_back(aResult);
586       }
587     }
588   }
589 }
590
591 } // namespace ModelAPI_Tools