+
+/// Returns true if theSub is in theContext shape
+static bool isInContext(const TopoDS_Shape& theContext, const TopoDS_Shape& theSub) {
+ for(TopExp_Explorer anExp(theContext, theSub.ShapeType()); anExp.More(); anExp.Next()) {
+ if (anExp.Current().IsSame(theSub))
+ return true;
+ }
+ return false;
+}
+
+bool Selector_Algo::findNewVersion(const TopoDS_Shape& theContext, TopoDS_Shape& theResult) const
+{
+ if (theResult.IsNull())
+ return false;
+ if (!TNaming_Tool::HasLabel(myLab, theResult)) {
+ if (theResult.ShapeType() == TopAbs_COMPOUND) { // do it for all elements of compound
+ BRep_Builder aBuilder;
+ TopoDS_Compound aResultingCompound;
+ aBuilder.MakeCompound(aResultingCompound);
+ bool aWasChanged = false;
+ for (TopoDS_Iterator anIter(theResult); anIter.More(); anIter.Next()) {
+ TopoDS_Shape aSub = anIter.Value();
+ if (findNewVersion(theContext, aSub))
+ aWasChanged = true;
+ aBuilder.Add(aResultingCompound, aSub);
+ }
+ if (aWasChanged)
+ theResult = aResultingCompound;
+ return aWasChanged;
+ }
+ } else {
+ // check theResult is in theContext
+ if (isInContext(theContext, theResult))
+ return false;
+ // searching the next modifications of the result shape in document
+ TopTools_MapOfShape aResultShapes;
+ for(TNaming_NewShapeIterator aBaseIter(theResult, myLab); aBaseIter.More(); aBaseIter.Next())
+ {
+ TNaming_Evolution anEvolution = aBaseIter.NamedShape()->Evolution();
+ if (anEvolution == TNaming_GENERATED || anEvolution == TNaming_MODIFY) {
+ TopoDS_Shape aNextModification = aBaseIter.Shape();
+ if (aNextModification.IsNull())
+ continue;
+ if (isInContext(theContext, aNextModification))
+ // don't add vertices generated from edges
+ if (aNextModification.ShapeType() <= theResult.ShapeType())
+ aResultShapes.Add(aNextModification);
+ else if (findNewVersion(theContext, aNextModification))
+ if (aNextModification.ShapeType() <= theResult.ShapeType())
+ aResultShapes.Add(aNextModification);
+ }
+ }
+ if (aResultShapes.IsEmpty())
+ return false;
+ if (aResultShapes.Size() == 1) {
+ theResult = TopTools_MapIteratorOfMapOfShape(aResultShapes).Value();
+ } else { // make a compound of all results
+ BRep_Builder aBuilder;
+ TopoDS_Compound aResultingCompound;
+ aBuilder.MakeCompound(aResultingCompound);
+ for(TopTools_MapIteratorOfMapOfShape anIter(aResultShapes); anIter.More(); anIter.Next())
+ aBuilder.Add(aResultingCompound, anIter.Value());
+ theResult = aResultingCompound;
+ }
+ return true;
+ }
+ return false;
+}