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