-//================= Auxiliary functions ===================================================
-
-static CompsolidSubs::iterator findOrAdd(CompsolidSubs& theList, const GeomShapePtr& theCompsolid)
-{
- CompsolidSubs::iterator aFound = theList.begin();
- for (; aFound != theList.end(); ++aFound)
- if (aFound->first == theCompsolid)
- break;
- if (aFound == theList.end()) {
- theList.push_back(std::pair<GeomShapePtr, ListOfShape>(theCompsolid, ListOfShape()));
- aFound = --theList.end();
- }
- return aFound;
-}
-
-void pullObjectsAndPlanes(const AttributeSelectionListPtr& theSelectedList,
- CompsolidSubs& theObjects, ListOfShape& thePlanes)
-{
- std::map<ResultBodyPtr, GeomShapePtr> aMapCompsolidShape;
-
- int aSize = theSelectedList->size();
- for (int anIndex = 0; anIndex < aSize; ++anIndex) {
- AttributeSelectionPtr anObjectAttr = theSelectedList->value(anIndex);
- ResultPtr aContext = anObjectAttr->context();
- GeomShapePtr anObject = anObjectAttr->value();
- if (anObject) {
- GeomShapePtr anOwnerShape = anObject;
- // check the result is a compsolid and store all used subs in a single list
- ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
- if (aResCompSolidPtr && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
- std::map<ResultBodyPtr, GeomShapePtr>::const_iterator
- aFound = aMapCompsolidShape.find(aResCompSolidPtr);
- if (aFound != aMapCompsolidShape.end())
- anOwnerShape = aFound->second;
- else {
- anOwnerShape = aResCompSolidPtr->shape();
- aMapCompsolidShape[aResCompSolidPtr] = anOwnerShape;
- }
- }
-
- CompsolidSubs::iterator aFound = findOrAdd(theObjects, anOwnerShape);
- aFound->second.push_back(anObject);
- }
- else {
- // It could be a construction plane.
- thePlanes.push_back(anObjectAttr->context()->shape());
- }
- }
-}
-
-void resizePlanes(const CompsolidSubs& theObjects, ListOfShape& thePlanes,
- std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList)
-{
- ListOfShape aSolidsInOperation;
- for (CompsolidSubs::const_iterator anIt = theObjects.begin(); anIt != theObjects.end(); ++anIt)
- aSolidsInOperation.insert(aSolidsInOperation.end(), anIt->second.begin(), anIt->second.end());
-
- std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints =
- GeomAlgoAPI_ShapeTools::getBoundingBox(aSolidsInOperation, 1.0);
-
- ListOfShape aPlanesCopy = thePlanes;
- thePlanes.clear();
-
- // Resize planes to fit in bounding box
- for (ListOfShape::const_iterator anIt = aPlanesCopy.begin(); anIt != aPlanesCopy.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);
- theMakeShapeList->appendAlgo(aMkShCustom);
- thePlanes.push_back(aTool);
- }
-}
-
-void unusedSubsOfComposolid(const CompsolidSubs& theObjects, CompsolidSubs& theNotUsed)
-{
- for (CompsolidSubs::const_iterator aCSIt = theObjects.begin();
- aCSIt != theObjects.end(); ++aCSIt) {
- if (aCSIt->first->shapeType() != GeomAPI_Shape::COMPSOLID)
- continue;
-
- // check the compsolid is selected
- if (aCSIt->second.size() == 1 && aCSIt->first->isEqual(aCSIt->second.front()))
- continue;
-
- // process all sub-solids of compsolid
- ListOfShape aNotUsedSolids;
- for (GeomAPI_ShapeExplorer anExp(aCSIt->first, GeomAPI_Shape::SOLID);
- anExp.more(); anExp.next()) {
- GeomShapePtr aSolidInCompSolid = anExp.current();
- ListOfShape::const_iterator anIt = aCSIt->second.begin();
- for (; anIt != aCSIt->second.end(); ++anIt)
- if (aSolidInCompSolid->isEqual(*anIt))
- break;
-
- if (anIt == aCSIt->second.end())
- aNotUsedSolids.push_back(aSolidInCompSolid);
- }
-
- if (!aNotUsedSolids.empty())
- theNotUsed.push_back(std::pair<GeomShapePtr, ListOfShape>(aCSIt->first, aNotUsedSolids));
- }
-}