+//**************************************************************
+// Returns the list of all features for theDocument and all features of
+// all nested parts.
+std::list<FeaturePtr> allFeatures(const DocumentPtr& theDocument)
+{
+ std::list<FeaturePtr> aResultList;
+ std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
+ foreach (const FeaturePtr& aFeature, anAllFeatures) {
+ // The order of appending features of the part and the part itself is important
+
+ // Append features from a part feature
+ foreach (const ResultPtr& aResult, aFeature->results()) {
+ ResultPartPtr aResultPart =
+ std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
+ if (aResultPart.get() && aResultPart->partDoc().get()) {
+ // Recursion
+ std::list<FeaturePtr> anAllFeatures = allFeatures(aResultPart->partDoc());
+ aResultList.insert(aResultList.end(), anAllFeatures.begin(), anAllFeatures.end());
+ }
+ }
+
+ aResultList.push_back(aFeature);
+ }
+ return aResultList;
+}
+