Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
[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   if (theSearcher.get() && theDocument->isLater(theDocument->feature(theParam), theSearcher))
171     return false;
172   AttributeDoublePtr aValueAttribute = theParam->data()->real(ModelAPI_ResultParameter::VALUE());
173   outValue = aValueAttribute->value();
174   return true;
175 }
176
177 bool findVariable(FeaturePtr theSearcher, const std::string& theName, double& outValue,
178                   ResultParameterPtr& theParam, const DocumentPtr& theDocument)
179 {
180   SessionPtr aSession = ModelAPI_Session::get();
181   std::list<DocumentPtr> aDocList;
182   DocumentPtr aDocument = theDocument.get() ? theDocument : aSession->activeDocument();
183   if (findVariable(aDocument, theSearcher, theName, outValue, theParam))
184     return true;
185   DocumentPtr aRootDocument = aSession->moduleDocument();
186   if (aDocument != aRootDocument) {
187     // any parameters in PartSet is okindependently on the Part position (issu #1504)
188     if (findVariable(aRootDocument, FeaturePtr(), theName, outValue, theParam))
189       return true;
190   }
191   return false;
192 }
193
194 ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub)
195 {
196   // to optimize and avoid of crash on partset document close
197   // (don't touch the sub-document structure)
198   if (theMain != theSub) {
199     for (int a = theMain->size(ModelAPI_ResultPart::group()) - 1; a >= 0; a--) {
200       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
201           theMain->object(ModelAPI_ResultPart::group(), a));
202       if (aPart && aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value() == theSub) {
203         return aPart;
204       }
205     }
206   }
207   return ResultPtr();
208 }
209
210 FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub)
211 {
212   // to optimize and avoid of crash on partset document close
213   // (don't touch the sub-document structure)
214   if (theMain != theSub) {
215     // iteration from top to bottom to avoid finding the movement documents before the original
216     int aSize = theMain->size(ModelAPI_Feature::group());
217     for (int a = 0; a < aSize; a++) {
218       FeaturePtr aPartFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(
219           theMain->object(ModelAPI_Feature::group(), a));
220       if (aPartFeat.get()) {
221         const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aPartFeat->results();
222         std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
223         for(; aRes != aResList.end(); aRes++) {
224           ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
225           if (aPart.get()) {
226             if (aPart->isActivated() && aPart->partDoc() == theSub)
227               return aPartFeat;
228           } else break; // if the first is not Part, others are also not
229         }
230       }
231     }
232   }
233   return FeaturePtr();
234 }
235
236 CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
237 {
238   if (theFeature.get() && theFeature->data()->isValid()) {
239     const std::set<std::shared_ptr<ModelAPI_Attribute> >& aRefs = theFeature->data()->refsToMe();
240     std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aRefIter = aRefs.begin();
241     for(; aRefIter != aRefs.end(); aRefIter++) {
242       CompositeFeaturePtr aComp = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
243         ((*aRefIter)->owner());
244       if (aComp.get() && aComp->data()->isValid() && aComp->isSub(theFeature))
245         return aComp;
246     }
247   }
248   return CompositeFeaturePtr(); // not found
249 }
250
251 ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
252 {
253   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
254   if (aBody.get()) {
255     FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
256     if (aFeatureOwner.get()) {
257       std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
258         aFeatureOwner->results().cbegin();
259       for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
260         ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
261         if (aComp && aComp->isSub(aBody))
262           return aComp;
263       }
264     }
265   }
266   return ResultCompSolidPtr(); // not found
267 }
268
269 bool hasSubResults(const ResultPtr& theResult)
270 {
271   ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
272   return aCompSolid.get() && aCompSolid->numberOfSubs() > 0;
273 }
274
275 void allResults(const FeaturePtr& theFeature, std::list<ResultPtr>& theResults)
276 {
277   if (!theFeature.get()) // safety: for empty feature no results
278     return;
279   const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
280   std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
281   for (; aRIter != aResults.cend(); aRIter++) {
282     theResults.push_back(*aRIter);
283     // iterate sub-bodies of compsolid
284     ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRIter);
285     if (aComp.get()) {
286       int aNumSub = aComp->numberOfSubs();
287       for(int a = 0; a < aNumSub; a++) {
288         theResults.push_back(aComp->subResult(a));
289       }
290     }
291   }
292 }
293
294 //******************************************************************
295 bool allDocumentsActivated(std::string& theNotActivatedNames)
296 {
297   theNotActivatedNames = "";
298   bool anAllPartActivated = true;
299
300   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
301   int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
302   for (int i = 0; i < aSize; i++) {
303     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
304     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
305     if (!aPart->isActivated()) {
306       anAllPartActivated = false;
307       if (!theNotActivatedNames.empty())
308         theNotActivatedNames += ", ";
309       theNotActivatedNames += aObject->data()->name().c_str();
310     }
311   }
312   return anAllPartActivated;
313 }
314
315 bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
316                                  const bool theFlushRedisplay,
317                                  const bool theUseComposite,
318                                  const bool theUseRecursion)
319 {
320 #ifdef DEBUG_REMOVE_FEATURES
321   printListInfo(theFeatures, "selection: ");
322 #endif
323
324   std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
325   ModelAPI_Tools::findAllReferences(theFeatures, aReferences, theUseComposite, theUseRecursion);
326 #ifdef DEBUG_REMOVE_FEATURES
327   printMapInfo(aReferences, "allDependencies: ");
328 #endif
329
330   std::set<FeaturePtr> aFeaturesRefsTo;
331   ModelAPI_Tools::findRefsToFeatures(theFeatures, aReferences, aFeaturesRefsTo);
332 #ifdef DEBUG_REMOVE_FEATURES
333   printListInfo(aFeaturesRefsTo, "references: ");
334 #endif
335
336   std::set<FeaturePtr> aFeatures = theFeatures;
337   if (!aFeaturesRefsTo.empty())
338     aFeatures.insert(aFeaturesRefsTo.begin(), aFeaturesRefsTo.end());
339 #ifdef DEBUG_REMOVE_FEATURES
340   printListInfo(aFeatures, "removeFeatures: ");
341 #endif
342
343   return ModelAPI_Tools::removeFeatures(aFeatures, false);
344 }
345
346 bool removeFeatures(const std::set<FeaturePtr>& theFeatures,
347                     const bool theFlushRedisplay)
348 {
349   bool isDone = false;
350   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
351                                        aLast = theFeatures.end();
352   for (; anIt != aLast; anIt++) {
353     FeaturePtr aFeature = *anIt;
354     if (aFeature.get()) {
355       DocumentPtr aDoc = aFeature->document();
356       // flush REDISPLAY signal after remove feature
357       aDoc->removeFeature(aFeature);
358       isDone = true;
359     }
360   }
361   if (isDone && theFlushRedisplay) {
362     // the redisplay signal should be flushed in order to erase
363     // the feature presentation in the viewer
364     // if should be done after removeFeature() of document
365     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
366   }
367   return true;
368 }
369
370 // Fills the references list by all references of the feature from the references map.
371 // This is a recusive method to find references by next found feature in the map of references.
372 // \param theFeature a feature to find references
373 // \param theReferencesMap a map of references
374 // \param theReferences an out container of references
375 void addRefsToFeature(const FeaturePtr& theFeature,
376                       const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferencesMap,
377                       std::map<FeaturePtr, std::set<FeaturePtr> >& theProcessedReferences,
378                       int theRecLevel,
379                       std::set<FeaturePtr>& theReferences)
380 {
381   if (theRecLevel > RECURSE_TOP_LEVEL)
382     return;
383   theRecLevel++;
384
385   // if the feature is already processed, get the ready references from the map
386   if (theProcessedReferences.find(theFeature) != theProcessedReferences.end()) {
387     std::set<FeaturePtr> aReferences = theProcessedReferences.at(theFeature);
388     theReferences.insert(aReferences.begin(), aReferences.end());
389     return;
390   }
391
392   if (theReferencesMap.find(theFeature) == theReferencesMap.end())
393     return; // this feature is not in the selection list, so exists without references to it
394   std::set<FeaturePtr> aMainReferences = theReferencesMap.at(theFeature);
395
396   std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
397                                        aLast = aMainReferences.end();
398 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
399   std::string aSpacing;
400   for (int i = 0; i < theRecLevel; i++)
401     aSpacing.append(" ");
402 #endif
403
404   for (; anIt != aLast; anIt++) {
405     FeaturePtr aRefFeature = *anIt;
406 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
407   std::cout << aSpacing << " Ref: " << getFeatureInfo(aRefFeature) << std::endl;
408 #endif
409     if (theReferences.find(aRefFeature) == theReferences.end())
410       theReferences.insert(aRefFeature);
411     addRefsToFeature(aRefFeature, theReferencesMap, theProcessedReferences,
412                      theRecLevel, theReferences);
413   }
414 }
415
416 // For each feature from the feature list it searches references to the feature and append them
417 // to the references map. This is a recusive method.
418 // \param theFeature a feature to find references
419 // \param theReferencesMap a map of references
420 // \param theReferences an out container of references
421 void findReferences(const std::set<FeaturePtr>& theFeatures,
422                     std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
423                     const bool theUseComposite, const bool theUseRecursion, int theRecLevel)
424 {
425   if (theRecLevel > RECURSE_TOP_LEVEL)
426     return;
427   theRecLevel++;
428   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
429                                         aLast = theFeatures.end();
430   for (; anIt != aLast; anIt++) {
431     FeaturePtr aFeature = *anIt;
432     if (aFeature.get() && theReferences.find(aFeature) == theReferences.end()) {
433       DocumentPtr aSelFeatureDoc = aFeature->document();
434       std::set<FeaturePtr> aSelRefFeatures;
435       aSelFeatureDoc->refsToFeature(aFeature, aSelRefFeatures, false/*do not emit signals*/);
436       if (theUseComposite) { // do not filter selection
437         theReferences[aFeature] = aSelRefFeatures;
438       }
439       else { // filter references to skip composition features of the current feature
440         std::set<FeaturePtr> aFilteredFeatures;
441         std::set<FeaturePtr>::const_iterator anIt = aSelRefFeatures.begin(),
442                                              aLast = aSelRefFeatures.end();
443         for (; anIt != aLast; anIt++) {
444           FeaturePtr aCFeature = *anIt;
445           CompositeFeaturePtr aComposite =
446             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCFeature);
447           if (aComposite.get() && aComposite->isSub(aFeature))
448             continue; /// composite of the current feature should be skipped
449           aFilteredFeatures.insert(aCFeature);
450         }
451         theReferences[aFeature] = aFilteredFeatures;
452       }
453       if (theUseRecursion) {
454 #ifdef DEBUG_CYCLING_1550
455         findReferences(aSelRefFeatures, theReferences, theUseComposite,
456                        theUseRecursion, theRecLevel);
457 #else
458         findReferences(theReferences[aFeature], theReferences, theUseComposite, theUseRecursion,
459                        theRecLevel);
460 #endif
461       }
462     }
463   }
464 }
465
466 void findAllReferences(const std::set<FeaturePtr>& theFeatures,
467                        std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
468                        const bool theUseComposite,
469                        const bool theUseRecursion)
470 {
471   // For dependencies, find main_list:
472   // sk_1(ext_1, vertex_1)
473   // ext_1(bool_1, sk_3)
474   // vertex_1()
475   // sk_2(ext_2)
476   // ext_2(bool_2)
477   // sk_3()
478   // Information: bool_1 is not selected, ext_2(bool_2) exists
479   // find all referenced features
480   std::map<FeaturePtr, std::set<FeaturePtr> > aMainList;
481   int aRecLevel = 0;
482   findReferences(theFeatures, aMainList, theUseComposite, theUseRecursion, aRecLevel);
483
484 #ifdef DEBUG_REMOVE_FEATURES
485   printMapInfo(aMainList, "firstDependencies");
486 #endif
487   // find all dependencies for each object:
488   // sk_1(ext_1, vertex_1) + (sk_3, bool_1)
489   // ext_1(bool_1, sk_3)
490   // vertex_1()
491   // sk_2(ext_2) + (bool_1)
492   // ext_2(bool_1)
493   // sk_3()
494   std::map<FeaturePtr, std::set<FeaturePtr> >::const_iterator aMainIt = aMainList.begin(),
495                                                               aMainLast = aMainList.end();
496   for (; aMainIt != aMainLast; aMainIt++) {
497     FeaturePtr aMainListFeature = aMainIt->first;
498
499     //std::string aName = aMainListFeature->name();
500     std::set<FeaturePtr> aMainRefList = aMainIt->second;
501
502 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
503     char aBuf[50];
504     int n = sprintf(aBuf, "%d", aMainRefList.size());
505     std::string aSize(aBuf);
506     std::cout << "_findAllReferences for the Feature: " << getFeatureInfo(aMainListFeature)
507               << ", references size = " << aSize << std::endl;
508 #endif
509     std::set<FeaturePtr>::const_iterator anIt = aMainRefList.begin(),
510                                          aLast = aMainRefList.end();
511     std::set<FeaturePtr> aResultRefList;
512     aResultRefList.insert(aMainRefList.begin(), aMainRefList.end());
513     for (; anIt != aLast; anIt++) {
514       FeaturePtr aFeature = *anIt;
515       int aRecLevel = 0;
516 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
517       std::cout << " Ref: " << getFeatureInfo(aFeature) << std::endl;
518 #endif
519       aRecLevel++;
520       addRefsToFeature(aFeature, aMainList, theReferences,
521                        aRecLevel, aResultRefList/*aMainRefList*/);
522     }
523     theReferences[aMainListFeature] = aResultRefList;
524   }
525 #ifdef DEBUG_REMOVE_FEATURES_RECURSE
526     std::cout << std::endl;
527 #endif
528
529 #ifdef DEBUG_REMOVE_FEATURES
530   printMapInfo(theReferences, "allDependencies");
531 #endif
532 }
533
534 void findRefsToFeatures(const std::set<FeaturePtr>& theFeatures,
535                         const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
536                         std::set<FeaturePtr>& theFeaturesRefsTo)
537 {
538   std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
539                                        aLast = theFeatures.end();
540   for (; anIt != aLast; anIt++) {
541     FeaturePtr aFeature = *anIt;
542     if (theReferences.find(aFeature) == theReferences.end())
543       continue;
544     std::set<FeaturePtr> aRefList = theReferences.at(aFeature);
545     std::set<FeaturePtr>::const_iterator aRefIt = aRefList.begin(), aRefLast = aRefList.end();
546     for (; aRefIt != aRefLast; aRefIt++) {
547       FeaturePtr aRefFeature = *aRefIt;
548       CompositeFeaturePtr aComposite =
549         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aRefFeature);
550       if (aComposite.get() && aComposite->isSub(aFeature))
551         continue; /// composite of the current feature should not be removed
552
553       if (theFeatures.find(aRefFeature) == theFeatures.end() && // it is not selected
554           theFeaturesRefsTo.find(aRefFeature) == theFeaturesRefsTo.end()) // it is not added
555         theFeaturesRefsTo.insert(aRefFeature);
556     }
557   }
558 }
559
560 void getConcealedResults(const FeaturePtr& theFeature,
561                          std::list<std::shared_ptr<ModelAPI_Result> >& theResults)
562 {
563   SessionPtr aSession = ModelAPI_Session::get();
564
565   std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > > aRefs;
566   theFeature->data()->referencesToObjects(aRefs);
567   std::list<std::pair<std::string, std::list<ObjectPtr> > >::const_iterator
568                                                   anIt = aRefs.begin(), aLast = aRefs.end();
569   std::set<ResultPtr> alreadyThere; // to avoid duplications
570   for (; anIt != aLast; anIt++) {
571     if (!aSession->validators()->isConcealed(theFeature->getKind(), anIt->first))
572       continue; // use only concealed attributes
573     std::list<ObjectPtr> anObjects = (*anIt).second;
574     std::list<ObjectPtr>::const_iterator anOIt = anObjects.begin(), anOLast = anObjects.end();
575     for (; anOIt != anOLast; anOIt++) {
576       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(*anOIt);
577       if (aResult && aResult->isConcealed()) {
578         if (alreadyThere.find(aResult) == alreadyThere.end()) // issue 1712, avoid duplicates
579           alreadyThere.insert(aResult);
580         else continue;
581         theResults.push_back(aResult);
582       }
583     }
584   }
585 }
586
587 } // namespace ModelAPI_Tools