- for (ListOfShape::iterator anObjectsIt = anObjects.begin();
- anObjectsIt != anObjects.end();
- ++anObjectsIt)
- {
- std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
- ListOfShape aListWithObject;
- aListWithObject.push_back(anObject);
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
- std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
- GeomShapePtr aResShape;
-
- std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
- GeomAlgoAPI_ShapeTools::getBoundingBox(aListWithObject, 1.0);
-
- // Resize planes.
- ListOfShape aToolsWithPlanes = aTools;
- for (ListOfShape::const_iterator anIt = aPlanes.cbegin();
- anIt != aPlanes.cend();
- ++anIt) {
- GeomShapePtr aPlane = *anIt;
- GeomShapePtr aTool = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aPlane, aBoundingPoints);
- std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
- new GeomAlgoAPI_MakeShapeCustom);
- aMkShCustom->addModified(aPlane, aTool);
- aMakeShapeList->appendAlgo(aMkShCustom);
- aToolsWithPlanes.push_back(aTool);
- }
-
- aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
- aToolsWithPlanes,
- GeomAlgoAPI_Boolean::BOOL_COMMON));
- aResShape = aBoolAlgo->shape();
-
- // Checking that the algorithm worked properly.
- if (!aBoolAlgo->isDone()) {
- static const std::string aFeatureError = "Error: Boolean algorithm failed.";
- setError(aFeatureError);
- return;
- }
- if (aResShape->isNull()) {
- static const std::string aShapeError = "Error: Resulting shape is Null.";
- setError(aShapeError);
- return;
- }
- if (!aBoolAlgo->isValid()) {
- std::string aFeatureError = "Error: Resulting shape is not valid.";
- setError(aFeatureError);
- return;
- }
-
- aMakeShapeList->appendAlgo(aBoolAlgo);
-
- GeomAPI_ShapeIterator aShapeIt(aResShape);
- if (aShapeIt.more() || aResShape->shapeType() == GeomAPI_Shape::VERTEX) {
- std::shared_ptr<ModelAPI_ResultBody> aResultBody =
- document()->createBody(data(), aResultIndex);
-
- FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
- anObject,
- aTools,
- aMakeShapeList,
- aResShape);
- setResult(aResultBody, aResultIndex);
- aResultIndex++;
-
- FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
- aRBA.resultBody = aResultBody;
- aRBA.baseShape = anObject;
- aRBA.makeShape = aMakeShapeList;
- aResultBaseAlgoList.push_back(aRBA);
- aResultShapesList.push_back(aResShape);
- }
- }
-
- // Compsolids handling
- for (std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape>::iterator
- anIt = aCompSolidsObjects.begin();
- anIt != aCompSolidsObjects.end();
- ++anIt)
- {
- std::shared_ptr<GeomAPI_Shape> aCompSolid = anIt->first;
- ListOfShape& aUsedInOperationSolids = anIt->second;
-
- // Collecting solids from compsolids which will not be modified in boolean operation.
- ListOfShape aNotUsedSolids;
- for (GeomAPI_ShapeExplorer anExp(aCompSolid, GeomAPI_Shape::SOLID);
- anExp.more();
- anExp.next())
- {
- std::shared_ptr<GeomAPI_Shape> aSolidInCompSolid = anExp.current();
- ListOfShape::iterator aUsedIt = aUsedInOperationSolids.begin();
- for (; aUsedIt != aUsedInOperationSolids.end(); aUsedIt++) {
- if (aSolidInCompSolid->isEqual(*aUsedIt)) {
- break;
- }
- }
- if (aUsedIt == aUsedInOperationSolids.end()) {
- aNotUsedSolids.push_back(aSolidInCompSolid);
- }
- }
-
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
- std::shared_ptr<GeomAlgoAPI_Boolean> aCommonAlgo(
- new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
- aTools,
- GeomAlgoAPI_Boolean::BOOL_COMMON));
-
- // Checking that the algorithm worked properly.
- if (!aCommonAlgo->isDone()) {
- static const std::string aFeatureError = "Error: Boolean algorithm failed.";
- setError(aFeatureError);
- return;
- }
- if (aCommonAlgo->shape()->isNull()) {
- static const std::string aShapeError = "Error: Resulting shape is Null.";
- setError(aShapeError);
- return;
- }
- if (!aCommonAlgo->isValid()) {
- std::string aFeatureError = "Error: Resulting shape is not valid.";
- setError(aFeatureError);
- return;
- }
-
- aMakeShapeList->appendAlgo(aCommonAlgo);
- GeomShapePtr aResultShape = aCommonAlgo->shape();
-
- // Add result to not used solids from compsolid.
- if (!aNotUsedSolids.empty()) {
- ListOfShape aShapesToAdd = aNotUsedSolids;
- aShapesToAdd.push_back(aCommonAlgo->shape());
- std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(
- new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
- if (!aFillerAlgo->isDone()) {
- std::string aFeatureError = "Error: PaveFiller algorithm failed.";
- setError(aFeatureError);
- return;
- }
-
- aMakeShapeList->appendAlgo(aFillerAlgo);
- aResultShape = aFillerAlgo->shape();
- }
-
- GeomAPI_ShapeIterator aShapeIt(aResultShape);
- if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX)
- {
- std::shared_ptr<ModelAPI_ResultBody> aResultBody =
- document()->createBody(data(), aResultIndex);
-
- FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
- aCompSolid,
- aTools,
- aMakeShapeList,
- aResultShape);
- setResult(aResultBody, aResultIndex);
- aResultIndex++;
-
- FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
- aRBA.resultBody = aResultBody;
- aRBA.baseShape = aCompSolid;
- aRBA.makeShape = aMakeShapeList;
- aResultBaseAlgoList.push_back(aRBA);
- aResultShapesList.push_back(aResultShape);
- }