- 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,
- const ListOfShape& theTools,
- int& theResultIndex,
- std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
- ListOfShape& theResultShapesList)
-{
- ListOfShape aUsedInOperationShapes;
- ListOfShape aNotUsedShapes;
- theCompoundHierarchy.SplitCompound(theCompound, aUsedInOperationShapes, aNotUsedShapes);
-
- std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
- std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(
- new GeomAlgoAPI_Boolean(aUsedInOperationShapes,
- theTools,
- 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 shape from compound.
- if (!aNotUsedShapes.empty()) {
- ListOfShape aShapesForResult = aNotUsedShapes;
- if (aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) {
- for (GeomAPI_ShapeIterator aResultIt(aResultShape); aResultIt.more(); aResultIt.next()) {
- aShapesForResult.push_back(aResultIt.current());
- }
- }
- else {
- aShapesForResult.push_back(aResultShape);
- }
-
- if (aShapesForResult.size() == 1) {
- aResultShape = aShapesForResult.front();
- }
- else {
- aResultShape = GeomAlgoAPI_CompoundBuilder::compound(aShapesForResult);
- }
- }
-
- GeomAPI_ShapeIterator aShapeIt(aResultShape);
- if (aShapeIt.more() || aResultShape->shapeType() == GeomAPI_Shape::VERTEX) {
- std::shared_ptr<ModelAPI_ResultBody> aResultBody =
- document()->createBody(data(), theResultIndex);
-
- ListOfShape aCompoundList;
- aCompoundList.push_back(theCompound);
- FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
- aCompoundList,
- theTools,
- aMakeShapeList,
- aResultShape);
- setResult(aResultBody, theResultIndex);
- ++theResultIndex;
-
- FeaturesPlugin_Tools::ResultBaseAlgo aRBA;
- aRBA.resultBody = aResultBody;
- aRBA.baseShape = theCompound;
- aRBA.makeShape = aMakeShapeList;
- theResultBaseAlgoList.push_back(aRBA);
- theResultShapesList.push_back(aResultShape);
- }
- return true;
-}
-
-//=================================================================================================
-
-void FeaturesPlugin_Boolean::ObjectHierarchy::AddObject(const GeomShapePtr& theObject)
-{
- myObjects.push_back(theObject);
-}
-
-void FeaturesPlugin_Boolean::ObjectHierarchy::AddParent(const GeomShapePtr& theShape,
- const GeomShapePtr& theParent)
-{
- myParent[theShape] = theParent;
-
- MapShapeToIndex::iterator aFound = myParentIndices.find(theParent);
- size_t anIndex = myParentIndices.size();
- if (aFound == myParentIndices.end()) {
- myParentIndices[theParent] = anIndex;
- mySubshapes.push_back(ShapeAndSubshapes(theParent, ListOfShape()));
- } else
- anIndex = aFound->second;
-
- mySubshapes[anIndex].second.push_back(theShape);
-}
-
-GeomShapePtr FeaturesPlugin_Boolean::ObjectHierarchy::Parent(const GeomShapePtr& theShape,
- bool theMarkProcessed)