+ if (theReferencesMap.find(theFeature) == theReferencesMap.end())
+ return; // this feature is not in the selection list, so exists without references to it
+ std::set<FeaturePtr> aMainReferences = theReferencesMap.at(theFeature);
+
+ std::set<FeaturePtr>::const_iterator anIt = aMainReferences.begin(),
+ aLast = aMainReferences.end();
+#ifdef DEBUG_REMOVE_FEATURES_RECURSE
+ std::string aSpacing;
+ for (int i = 0; i < theRecLevel; i++)
+ aSpacing.append(" ");
+#endif
+
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aRefFeature = *anIt;
+#ifdef DEBUG_REMOVE_FEATURES_RECURSE
+ std::cout << aSpacing << " Ref: " << getFeatureInfo(aRefFeature) << std::endl;
+#endif
+ if (theReferences.find(aRefFeature) == theReferences.end())
+ theReferences.insert(aRefFeature);
+ addRefsToFeature(aRefFeature, theReferencesMap, theProcessedReferences,
+ theRecLevel, theReferences);
+ }
+}
+
+// For each feature from the feature list it searches references to the feature and append them
+// to the references map. This is a recusive method.
+// \param theFeature a feature to find references
+// \param theReferencesMap a map of references
+// \param theReferences an out container of references
+void findReferences(const std::set<FeaturePtr>& theFeatures,
+ std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
+ const bool theUseComposite, const bool theUseRecursion, int theRecLevel)
+{
+ if (theRecLevel > RECURSE_TOP_LEVEL)
+ return;
+ theRecLevel++;
+ std::set<FeaturePtr>::const_iterator anIt = theFeatures.begin(),
+ aLast = theFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = *anIt;
+ if (aFeature.get() && theReferences.find(aFeature) == theReferences.end()) {
+ DocumentPtr aSelFeatureDoc = aFeature->document();
+ std::set<FeaturePtr> aSelRefFeatures;
+ aSelFeatureDoc->refsToFeature(aFeature, aSelRefFeatures, false/*do not emit signals*/);
+ if (theUseComposite) { // do not filter selection
+ theReferences[aFeature] = aSelRefFeatures;
+ }
+ else { // filter references to skip composition features of the current feature
+ std::set<FeaturePtr> aFilteredFeatures;
+ std::set<FeaturePtr>::const_iterator anIt = aSelRefFeatures.begin(),
+ aLast = aSelRefFeatures.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aCFeature = *anIt;
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCFeature);
+ if (aComposite.get() && aComposite->isSub(aFeature))
+ continue; /// composite of the current feature should be skipped
+ aFilteredFeatures.insert(aCFeature);
+ }
+ theReferences[aFeature] = aFilteredFeatures;
+ }
+ if (theUseRecursion) {
+#ifdef DEBUG_CYCLING_1550
+ findReferences(aSelRefFeatures, theReferences, theUseComposite,
+ theUseRecursion, theRecLevel);
+#else
+ findReferences(theReferences[aFeature], theReferences, theUseComposite, theUseRecursion,
+ theRecLevel);
+#endif