+
+ return false;
+}
+
+//=================================================================================================
+void getHistorySupportedType(const TopoDS_Shape& theShape, TopTools_ListOfShape& theResult) {
+ if (BRepTools_History::IsSupportedType(theShape)) {
+ theResult.Append(theShape);
+ } else {
+ for (TopoDS_Iterator aSubIter(theShape); aSubIter.More(); aSubIter.Next()) {
+ getHistorySupportedType(aSubIter.Value(), theResult);
+ }
+ }
+}
+
+//=================================================================================================
+// Operation is used for production of ordered sorting: generated/modified from the first argument
+// must be located in hte result first, etc. THis is for the issue #2517
+static void sortCompound(TopoDS_Shape& theCompound, GEOMAlgo_Splitter* theOperation)
+{
+ TopoDS_Compound aResCompound;
+ TopoDS_Builder aBuilder;
+ aBuilder.MakeCompound(aResCompound);
+
+ TopTools_MapOfShape anAlreadyThere; // to avoid duplications if it was produced by two arguments
+
+ // flag to add to result also results which were not produced by any argument
+ bool aNotProduced = true;
+ TopTools_ListOfShape::Iterator anArgs(theOperation->Arguments());
+ while(aNotProduced || anArgs.More()) {
+ // collect shapes that were produced from the current argument
+ TopTools_MapOfShape aProducedByArg;
+ if (anArgs.More()) {
+ TopTools_ListOfShape allArgs;
+ getHistorySupportedType(anArgs.Value(), allArgs);
+ for (TopTools_ListOfShape::Iterator argsIter(allArgs); argsIter.More(); argsIter.Next()) {
+ // if argument was not modified, it is fully in the result
+ aProducedByArg.Add(argsIter.Value());
+ const TopTools_ListOfShape& aModified = theOperation->Modified(argsIter.Value());
+ for (TopTools_ListOfShape::Iterator aModIter(aModified); aModIter.More(); aModIter.Next()) {
+ aProducedByArg.Add(aModIter.Value());
+ }
+ const TopTools_ListOfShape& aGenerated = theOperation->Generated(argsIter.Value());
+ for (TopTools_ListOfShape::Iterator aGenIter(aGenerated); aGenIter.More(); aGenIter.Next())
+ {
+ aProducedByArg.Add(aGenIter.Value());
+ }
+ }
+ anArgs.Next();
+ }
+ else {
+ aNotProduced = false;
+ }
+
+ ListOfShape aCombiningShapes;
+ for (TopoDS_Iterator anIt(theCompound); anIt.More(); anIt.Next()) {
+ bool aProducedContains = false;
+ if (aNotProduced) { // collect all supported type-shapes of result
+ TopTools_ListOfShape allRes;
+ getHistorySupportedType(anIt.Value(), allRes);
+ for (TopTools_ListOfShape::Iterator aResIter(allRes); aResIter.More(); aResIter.Next()) {
+ if (aProducedByArg.Contains(aResIter.Value())) {
+ aProducedContains = true;
+ break;
+ }
+ }
+ }
+ if ((!aNotProduced || aProducedContains) && anAlreadyThere.Add(anIt.Value())) {
+ GeomShapePtr aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(anIt.Value()));
+ aCombiningShapes.push_back(aSub);
+ }
+ }
+
+ // sort sub-shapes of compound to stabilize the sequence of the Partition's results
+ GeomAlgoAPI_SortListOfShapes::sort(aCombiningShapes);
+
+ for (ListOfShape::iterator anIt = aCombiningShapes.begin();
+ anIt != aCombiningShapes.end(); ++anIt)
+ aBuilder.Add(aResCompound, (*anIt)->impl<TopoDS_Shape>());
+ }
+
+ theCompound = aResCompound;