- boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
- if (!aFaceRef)
- return;
-
- boost::shared_ptr<GeomAPI_Shape> aFace =
- boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aFace)
- return;
-
- boost::shared_ptr<GeomAPI_Shape> aContext;
- ResultPtr aContextRes = aFaceRef->context();
- if (aContextRes) {
- if (aContextRes->groupName() == ModelAPI_ResultBody::group())
- aContext = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
- else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
- aContext = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
- }
- if (!aContext) {
- std::string aContextError = "The selection context is bad";
- Events_Error::send(aContextError, this);
- return;
+ // Getting faces.
+ ListOfShape aFacesList;
+ AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
+ for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
+ AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex);
+ std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
+ if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face.
+ aFacesList.push_back(aFaceShape);
+ } else { // This may be the whole sketch result selected, check and get faces.
+ ResultPtr aContext = aFaceSel->context();
+ std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+ if(!aContextShape.get()) {
+ static const std::string aContextError = "The selection context is bad";
+ setError(aContextError);
+ return;
+ }
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(!aConstruction.get()) {
+ static const std::string aFaceError = "Can not find basis for extrusion";
+ setError(aFaceError);
+ return;
+ }
+ int aFacesNum = aConstruction->facesNum();
+ for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
+ aFaceShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+ aFacesList.push_back(aFaceShape);
+ }
+ }