+ ListOfShape anObjects, aPlanes;
+
+ // Getting objects.
+ AttributeSelectionListPtr anObjectsSelList = selectionList(BASE_OBJECTS_ID());
+ for(int anIndex = 0; anIndex < anObjectsSelList->size(); ++anIndex) {
+ AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anIndex);
+ GeomShapePtr anObject = anObjectAttr->value();
+ if(!anObject.get()) {
+ // It could be a construction plane.
+ ResultPtr aContext = anObjectAttr->context();
+ aPlanes.push_back(anObjectAttr->context()->shape());
+ } else {
+ anObjects.push_back(anObject);
+ }
+ }
+
+ if(anObjects.empty()) {
+ static const std::string aFeatureError = "Error: No objects for partition.";
+ setError(aFeatureError);
+ return;
+ }
+
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
+
+ // Resize planes.
+ ListOfShape aTools;
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
+ 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);
+ aTools.push_back(aTool);
+ }
+
+ // Create single result.
+ std::shared_ptr<GeomAlgoAPI_Partition> aPartitionAlgo(new GeomAlgoAPI_Partition(anObjects, aTools));
+
+ // Checking that the algorithm worked properly.
+ if (!aPartitionAlgo->isDone()) {
+ static const std::string aFeatureError = "Error: Partition algorithm failed.";
+ setError(aFeatureError);
+ return;
+ }
+ if (aPartitionAlgo->shape()->isNull()) {
+ static const std::string aShapeError = "Error: Resulting shape is Null.";
+ setError(aShapeError);
+ return;
+ }
+ if (!aPartitionAlgo->isValid()) {
+ std::string aFeatureError = "Error: Resulting shape is not valid.";
+ setError(aFeatureError);
+ return;
+ }
+ aMakeShapeList->appendAlgo(aPartitionAlgo);
+ GeomShapePtr aResultShape = aPartitionAlgo->shape();
+
+ int aResultIndex = 0;
+ anObjects.insert(anObjects.end(), aPlanes.begin(), aPlanes.end());
+ if(aResultShape->shapeType() == GeomAPI_Shape::COMPOUND) {
+ for(GeomAPI_ShapeIterator anIt(aResultShape); anIt.more(); anIt.next()) {
+ storeResult(anObjects, anIt.current(), aMakeShapeList, aResultIndex);
+ ++aResultIndex;
+ }
+ } else {
+ storeResult(anObjects, aResultShape, aMakeShapeList, aResultIndex);
+ ++aResultIndex;
+ }
+
+ // Remove the rest results if there were produced in the previous pass.
+ removeResults(aResultIndex);