+ int aResultIndex = 0;
+ ListOfMakeShape aListOfMakeShape;
+ std::shared_ptr<GeomAPI_Shape> aResShape;
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMapOfShapes;
+
+ switch(aType) {
+ case GeomAlgoAPI_Boolean::BOOL_CUT: {
+ // Cut each object with all tools
+ for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+ std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
+ aResShape = anObject;
+ ListOfShape aSingleObjectList; aSingleObjectList.push_back(anObject);
+ for(ListOfShape::iterator aToolsIt = aTools.begin(); aToolsIt != aTools.end(); aToolsIt++) {
+ std::shared_ptr<GeomAPI_Shape> aTool = *aToolsIt;
+ GeomAlgoAPI_Boolean* aBoolAlgo = new GeomAlgoAPI_Boolean(aResShape, aTool, aType);
+ if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
+ static const std::string aBoolAlgoError = "Boolean feature: algorithm failed";
+ setError(aBoolAlgoError);
+ return;
+ }
+ aListOfMakeShape.push_back(aBoolAlgo->makeShape());
+ aResShape = aBoolAlgo->shape();
+ aBoolAlgo->mapOfShapes(aDataMapOfShapes);
+ }
+
+ if(GeomAlgoAPI_ShapeProps::volume(aResShape) > 10.e-5) {
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
+ new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
+
+ LoadNamingDS(aMakeShapeList, aResultBody, aResShape, aDataMapOfShapes, aSingleObjectList, aTools);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
+ }
+ }
+ break;
+ }
+ case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+ // Fuse all objects.
+ std::shared_ptr<GeomAPI_Shape> aTempRes = anObjects.front();
+ for(ListOfShape::iterator anObjectsIt = ++anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+ std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
+ GeomAlgoAPI_Boolean* aBoolAlgo = new GeomAlgoAPI_Boolean(aTempRes, anObject, aType);
+ if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
+ static const std::string aBoolAlgoError = "Boolean feature: algorithm failed";
+ setError(aBoolAlgoError);
+ return;
+ }
+ aListOfMakeShape.push_back(aBoolAlgo->makeShape());
+ aTempRes = aBoolAlgo->shape();
+ }
+
+ // Fuse all tools with result of objects fuse.
+ for(ListOfShape::iterator aToolsIt = aTools.begin(); aToolsIt != aTools.end(); aToolsIt++) {
+ std::shared_ptr<GeomAPI_Shape> aTool = *aToolsIt;
+ GeomAlgoAPI_Boolean* aBoolAlgo = new GeomAlgoAPI_Boolean(aTempRes, aTool, aType);
+ if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
+ static const std::string aBoolAlgoError = "Boolean feature: algorithm failed";
+ setError(aBoolAlgoError);
+ return;
+ }
+ aListOfMakeShape.push_back(aBoolAlgo->makeShape());
+ aTempRes = aBoolAlgo->shape();
+ aBoolAlgo->mapOfShapes(aDataMapOfShapes);
+ }
+ aResShape = aTempRes;
+
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
+ new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
+
+ LoadNamingDS(aMakeShapeList, aResultBody, aResShape, aDataMapOfShapes, anObjects, aTools);
+ setResult(aResultBody);
+ aResultIndex++;
+ break;
+ }
+ case GeomAlgoAPI_Boolean::BOOL_COMMON: {
+ // Search common between object and tool and fuse them.
+ for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+ std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
+ std::shared_ptr<GeomAPI_Shape> aTempRes;
+ ListOfShape aSingleObjectList; aSingleObjectList.push_back(anObject);
+ for(ListOfShape::iterator aToolsIt = aTools.begin(); aToolsIt != aTools.end(); aToolsIt++) {
+ std::shared_ptr<GeomAPI_Shape> aTool = *aToolsIt;
+ GeomAlgoAPI_Boolean* aBoolAlgo1 = new GeomAlgoAPI_Boolean(anObject, aTool, aType);
+ if(!aBoolAlgo1->isDone() || aBoolAlgo1->shape()->isNull() || !aBoolAlgo1->isValid()) {
+ static const std::string aBoolAlgoError = "Boolean feature: algorithm failed";
+ setError(aBoolAlgoError);
+ return;
+ }
+ aListOfMakeShape.push_back(aBoolAlgo1->makeShape());
+
+ if(!aTempRes) {
+ aTempRes = aBoolAlgo1->shape();
+ aBoolAlgo1->mapOfShapes(aDataMapOfShapes);
+ } else {
+ // Fuse common result with previous common results.
+ GeomAlgoAPI_Boolean* aBoolAlgo2 = new GeomAlgoAPI_Boolean(aTempRes,
+ aBoolAlgo1->shape(),
+ GeomAlgoAPI_Boolean::BOOL_FUSE);
+ if(!aBoolAlgo1->isDone() || aBoolAlgo1->shape()->isNull() || !aBoolAlgo1->isValid()) {
+ static const std::string aBoolAlgoError = "Boolean feature: algorithm failed";
+ setError(aBoolAlgoError);
+ return;
+ }
+ aListOfMakeShape.push_back(aBoolAlgo2->makeShape());
+ aTempRes = aBoolAlgo2->shape();
+ aBoolAlgo2->mapOfShapes(aDataMapOfShapes);
+ }
+ }
+ aResShape = aTempRes;
+
+ if(GeomAlgoAPI_ShapeProps::volume(aResShape) > 10.e-5) {
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList = std::shared_ptr<GeomAlgoAPI_MakeShapeList>(
+ new GeomAlgoAPI_MakeShapeList(aListOfMakeShape));
+
+ LoadNamingDS(aMakeShapeList, aResultBody, aResShape, aDataMapOfShapes, aSingleObjectList, aTools);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
+ }
+ }
+ break;
+ }
+ }
+ // remove the rest results if there were produced in the previous pass
+ removeResults(aResultIndex);