+ // Get base objects list.
+ AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
+ if (!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+ if (aSelectionList->size() == 0) {
+ theError = "Empty selection list.";
+ return false;
+ }
+
+ // Collect base shapes.
+ ListOfShape anOriginalShapes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ if (!aSelection->context().get()) {
+ theError = "Invalid selection.";
+ return false;
+ }
+ GeomShapePtr aShape = aSelection->value();
+ if (!aShape.get())
+ aShape = aSelection->context()->shape();
+ anOriginalShapes.push_back(aShape);
+ }
+
+ std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgorithm(
+ new GeomAlgoAPI_MakeVolume(anOriginalShapes, false));
+
+ if (!anAlgorithm->isDone()) {
+ theError = "MakeVolume algorithm failed.";
+ return false;
+ }
+ if (anAlgorithm->shape()->isNull()) {
+ theError = "Resulting shape of MakeVolume is Null.";
+ return false;
+ }
+ if (!anAlgorithm->isValid()) {
+ theError = "Resulting shape of MakeVolume is not valid.";
+ return false;
+ }
+
+ // set of allowed types of results
+ std::set<GeomAPI_Shape::ShapeType> aResultType;
+ std::string aType = theArguments.back();
+ if (aType == "solid")
+ aResultType.insert(GeomAPI_Shape::SOLID);
+ else if (aType == "compsolid") {
+ aResultType.insert(GeomAPI_Shape::COMPSOLID);
+ aResultType.insert(GeomAPI_Shape::SOLID);
+ }
+
+ GeomShapePtr aCompound = anAlgorithm->shape();
+ if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
+ GeomAPI_ShapeIterator anIt(aCompound);
+ GeomShapePtr aFoundSub;
+ for (; anIt.more() && !aFoundSub; anIt.next()) {
+ aFoundSub = anIt.current();
+ if (aResultType.count(aFoundSub->shapeType()) == 0) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ }
+ if (anIt.more() || !aFoundSub.get()) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ } else if (aResultType.count(aCompound->shapeType()) == 0) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ // check the internal faces presence
+ for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) {
+ if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) {
+ theError = "Internal faces are not allowed in the resulting solid";
+ return false;
+ }
+ }
+
+ return true;