-bool FeaturesPlugin_Boolean::processObject(
- const GeomAlgoAPI_Tools::BOPType theBooleanType,
- const GeomShapePtr& theObject,
- const ListOfShape& theTools,
- const ListOfShape& thePlanes,
- int& theResultIndex,
- std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
- ListOfShape& theResultShapesList)
-{
- ListOfShape aListWithObject;
- aListWithObject.push_back(theObject);
- 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 = theTools;
- for (ListOfShape::const_iterator anIt = thePlanes.begin(); anIt != thePlanes.end(); ++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);
- }
-
- if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
- aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
- else
- aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
- aToolsWithPlanes,
- theBooleanType));
-
- // Checking that the algorithm worked properly.
- std::string anError;
- if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
- setError(anError);
- return false;
- }
-
- aResShape = aBoolAlgo->shape();
- if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
- int aSubResultsNb = 0;
- GeomAPI_ShapeIterator anIt(aResShape);
- for (; anIt.more(); anIt.next())
- ++aSubResultsNb;
-
- if (aSubResultsNb == 1) {
- anIt.init(aResShape);
- if (anIt.more())
- aResShape = anIt.current();
- }
- }
-
- aMakeShapeList->appendAlgo(aBoolAlgo);
-
- GeomAPI_ShapeIterator aShapeIt(aResShape);
- if (aShapeIt.more() || aResShape->shapeType() == GeomAPI_Shape::VERTEX) {
- std::shared_ptr<ModelAPI_ResultBody> aResultBody =
- document()->createBody(data(), theResultIndex);
-
- // tools should be added to the list to fulfill the correct history of modification
- aListWithObject.insert(aListWithObject.end(), theTools.begin(), theTools.end());
-
- ListOfShape aUsedTools = theTools;
- aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
-
- FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
- aListWithObject,
- aUsedTools,
- aMakeShapeList,
- aResShape);
- setResult(aResultBody, theResultIndex);
- ++theResultIndex;
-
- FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
- aRBA.resultBody = aResultBody;
- aRBA.baseShape = theObject;
- aRBA.makeShape = aMakeShapeList;
- theResultBaseAlgoList.push_back(aRBA);
- theResultShapesList.push_back(aResShape);
- }
- return true;
-}
-
-//=================================================================================================
-bool FeaturesPlugin_Boolean::processCompsolid(
- const GeomAlgoAPI_Tools::BOPType theBooleanType,
- const ObjectHierarchy& theCompsolidHierarchy,
- const GeomShapePtr& theCompsolid,
- const ListOfShape& theTools,
- const ListOfShape& thePlanes,
- int& theResultIndex,
- std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
- ListOfShape& theResultShapesList)
-{
- ListOfShape aUsedInOperationSolids;
- ListOfShape aNotUsedSolids;
- theCompsolidHierarchy.SplitCompound(theCompsolid, aUsedInOperationSolids, aNotUsedSolids);
-
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
-
- std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
- GeomAlgoAPI_ShapeTools::getBoundingBox(aUsedInOperationSolids, 1.0);
-
- // Resize planes.
- ListOfShape aToolsWithPlanes = theTools;
- for (ListOfShape::const_iterator anIt = thePlanes.begin(); anIt != thePlanes.end(); ++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);
- }
-
- std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
- if (theBooleanType == GeomAlgoAPI_Tools::BOOL_PARTITION)
- aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aToolsWithPlanes));
- else
- aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
- aToolsWithPlanes,
- theBooleanType));
-
- // Checking that the algorithm worked properly.
- std::string anError;
- if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError)) {
- setError(anError);
- return false;
- }
-
- aMakeShapeList->appendAlgo(aBoolAlgo);
- GeomShapePtr aResultShape = aBoolAlgo->shape();
-
- // Add result to not used solids from compsolid.
- if (!aNotUsedSolids.empty()) {
- ListOfShape aShapesToAdd = aNotUsedSolids;
- aShapesToAdd.push_back(aBoolAlgo->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 false;
- }
-
- 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(), theResultIndex);
-
- ListOfShape aCompSolidList;
- aCompSolidList.push_back(theCompsolid);
- // tools should be added to the list to fulfill the correct history of modification
- aCompSolidList.insert(aCompSolidList.end(), theTools.begin(), theTools.end());
-
- ListOfShape aUsedTools = theTools;
- aUsedTools.insert(aUsedTools.end(), thePlanes.begin(), thePlanes.end());
-
- FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
- aCompSolidList,
- aUsedTools,
- aMakeShapeList,
- aResultShape);
- setResult(aResultBody, theResultIndex);
- ++theResultIndex;
-
- FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
- aRBA.resultBody = aResultBody;
- aRBA.baseShape = theCompsolid;
- aRBA.makeShape = aMakeShapeList;
- theResultBaseAlgoList.push_back(aRBA);
- theResultShapesList.push_back(aResultShape);
- }
- return true;
-}
-
-//=================================================================================================
-bool FeaturesPlugin_Boolean::processCompound(
- const GeomAlgoAPI_Tools::BOPType theBooleanType,
- const ObjectHierarchy& theCompoundHierarchy,
- const GeomShapePtr& theCompound,