+ // Compsolids handling
+ for(std::map<GeomShapePtr, ListOfShape>::const_iterator anIt = aCompSolidsObjects.cbegin();
+ anIt != aCompSolidsObjects.cend(); ++anIt) {
+ GeomShapePtr aCompSolid = anIt->first;
+ const ListOfShape& aUsedShapes = anIt->second;
+
+ // Collecting solids from compsolids which will not be modified in boolean operation.
+ ListOfShape aShapesToAdd;
+ for (GeomAPI_ShapeIterator aCompSolidIt(aCompSolid);
+ aCompSolidIt.more();
+ aCompSolidIt.next())
+ {
+ GeomShapePtr aSolidInCompSolid = aCompSolidIt.current();
+ ListOfShape::const_iterator aUsedShapesIt = aUsedShapes.cbegin();
+ for(; aUsedShapesIt != aUsedShapes.cend(); ++aUsedShapesIt) {
+ if(aSolidInCompSolid->isEqual(*aUsedShapesIt)) {
+ break;
+ }
+ }
+ if(aUsedShapesIt == aUsedShapes.end()) {
+ aShapesToAdd.push_back(aSolidInCompSolid);
+ }
+ }
+
+ std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aUsedShapes,
+ theTools,
+ GeomAlgoAPI_Tools::BOOL_CUT));
+
+ // Checking that the algorithm worked properly.
+ if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
+ myFeature->setError("Error: Boolean algorithm failed.");
+ return false;
+ }
+
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
+ aMakeShapeList->appendAlgo(aBoolAlgo);
+
+ // Add result to not used solids from compsolid.
+ GeomShapePtr aBoolRes = aBoolAlgo->shape();
+ if (!aShapesToAdd.empty()) {
+ aShapesToAdd.push_back(aBoolRes);
+ if (aCompoundsOnly)
+ { // 23885: if there are no compsolids in input, do not use filler to make compsolids
+ aBoolRes = GeomAlgoAPI_CompoundBuilder::compound(aShapesToAdd);
+ std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aCompMkr(new GeomAlgoAPI_MakeShapeCustom);
+ aCompMkr->setResult(aBoolRes);
+ for(ListOfShape::iterator aCS = aCompSolids.begin(); aCS != aCompSolids.end(); aCS++)
+ aCompMkr->addModified(*aCS, aBoolRes);
+ aMakeShapeList->appendAlgo(aCompMkr);
+ }
+ else
+ {
+ std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
+ new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
+ if (!aFillerAlgo->isDone() || aFillerAlgo->shape()->isNull() || !aFillerAlgo->isValid())
+ {
+ myFeature->setError("Error: PaveFiller algorithm failed.");
+ return false;
+ }
+ aBoolRes = aFillerAlgo->shape();
+ aMakeShapeList->appendAlgo(aFillerAlgo);
+ }
+ }
+
+ if(GeomAlgoAPI_ShapeTools::area(aBoolRes) > 1.e-27) {
+ theObjects.push_back(aCompSolid);
+ theMakeShapes.push_back(aMakeShapeList);
+ }
+ }
+
+ // Complex (recursive) compounds handling
+ for(ListOfShape::const_iterator anIt = aCompounds.cbegin();
+ anIt != aCompounds.cend(); ++anIt) {
+ GeomShapePtr aCompound = (*anIt);
+ GeomShapePtr aRes;
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList (new GeomAlgoAPI_MakeShapeList());
+ cutRecursiveCompound(aCompound, theTools, aMakeShapeList, aRes);
+ theObjects.push_back(aCompound);
+ theMakeShapes.push_back(aMakeShapeList);