- for ( int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i ) {
- std::shared_ptr<ModelAPI_AttributeSelection> anSelectionAttr = aSelectionListAttr->value(i);
- aShapes.push_back(anSelectionAttr->value());
+ for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i) {
+ AttributeSelectionPtr anAttrSelection = aSelectionListAttr->value(i);
+ std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
+ if (aCurShape.get() == NULL)
+ aCurShape = anAttrSelection->context()->shape();
+ if (aCurShape.get() != NULL)
+ aShapes.push_back(aCurShape);
+ }
+
+ // Store compound if we have more than one shape.
+ std::shared_ptr<GeomAPI_Shape> aShape;
+ if(aShapes.size() == 1) {
+ aShape = aShapes.front();
+ } else {
+ aShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes);