+// LCOV_EXCL_START
+/// Makes all modification and generation naming shapes that have old shapes corresponding to
+/// shapes in a root document be equal to this root document
+static void updateShapesFromRoot(const TDF_Label theThisAccess, const TDF_Label theRootAccess)
+{
+ TopTools_DataMapOfShapeShape aCurrentToRoot; // shapes that must be updated: from this to root
+ TDF_ChildIDIterator aThisIter(theThisAccess.Root(), kEXTERNAL_SHAPE_REF, true);
+ for(; aThisIter.More(); aThisIter.Next()) {
+ aCurrentToRoot.Clear();
+ Handle(TNaming_NamedShape) aNS;
+ if (!aThisIter.Value()->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS))
+ continue;
+ if (aNS->Evolution() != TNaming_GENERATED && aNS->Evolution() != TNaming_MODIFY)
+ continue;
+ for (TNaming_Iterator aNSIter(aNS); aNSIter.More(); aNSIter.Next()) {
+ const TopoDS_Shape& anOld = aNSIter.OldShape();
+ if (anOld.IsNull())
+ continue;
+ TNaming_OldShapeIterator aNewIter(anOld, theThisAccess);
+ for (; aNewIter.More(); aNewIter.Next()) {
+ TNaming_Evolution anEvolution = aNewIter.NamedShape()->Evolution();
+ if (anEvolution != TNaming_SELECTED && anEvolution != TNaming_DELETE)
+ break;
+ }
+ if (aNewIter.More())
+ continue;
+ GeomShapePtr anOldShape(new GeomAPI_Shape), aRootShape(new GeomAPI_Shape);
+ anOldShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(anOld));
+ anOldShape = GeomAPI_Tools::getTypedShape(anOldShape);
+
+ // search the same shape in the root document
+ Handle(TDataStd_ExtStringList) anEntries =
+ Handle(TDataStd_ExtStringList)::DownCast(aThisIter.Value());
+ TDataStd_ListOfExtendedString::Iterator anIter(anEntries->List());
+ for (; anIter.More(); anIter.Next()) {
+ TDF_Label aRootLab;
+ TDF_Tool::Label(theRootAccess.Data(), anIter.Value(), aRootLab);
+ if (aRootLab.IsNull())
+ continue;
+ Handle(TNaming_NamedShape) aRootNS;
+ if (!aRootLab.FindAttribute(TNaming_NamedShape::GetID(), aRootNS))
+ continue;
+ TNaming_Iterator aRootShapes(aRootNS);
+ for (; aRootShapes.More(); aRootShapes.Next()) {
+ if (aRootShapes.NewShape().IsNull())
+ continue;
+ aRootShape->setImpl(new TopoDS_Shape(aRootShapes.NewShape()));
+ aRootShape = GeomAPI_Tools::getTypedShape(aRootShape);
+ if (!anOldShape->isEqual(aRootShape)) // special checking by geometry
+ continue;
+ // found a good corresponded shape
+ if (!anOld.IsEqual(aRootShapes.NewShape()))
+ aCurrentToRoot.Bind(anOld, aRootShapes.NewShape());
+ }
+ }
+ }
+ if (!aCurrentToRoot.IsEmpty()) { // update the whole named shape content
+ TopTools_ListOfShape anOld, aNew;
+ TNaming_Evolution anEvol = aNS->Evolution();
+ for(TNaming_Iterator aNSIter(aNS); aNSIter.More(); aNSIter.Next()) {
+ anOld.Prepend(aCurrentToRoot.IsBound(aNSIter.OldShape()) ?
+ aCurrentToRoot.Find(aNSIter.OldShape()) : aNSIter.OldShape());
+ aNew.Prepend(aNSIter.NewShape());
+ }
+ TNaming_Builder aBuilder(aNS->Label());
+ TopTools_ListOfShape::Iterator anOldIter(anOld), aNewIter(aNew);
+ for(; anOldIter.More(); anOldIter.Next(), aNewIter.Next()) {
+ if (anEvol == TNaming_GENERATED) {
+ aBuilder.Generated(anOldIter.Value(), aNewIter.Value());
+ } else if (anEvol == TNaming_MODIFY) {
+ aBuilder.Modify(anOldIter.Value(), aNewIter.Value());
+ }
+ }
+ }
+ }
+}
+// LCOV_EXCL_STOP
+