0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / TNaming / TNaming_Name.cxx
index 7caca2e..697a8f0 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <TNaming_Name.ixx>
-#include <TNaming.hxx>
-#include <TNaming_NamingTool.hxx>
-#include <TNaming_Naming.hxx>
-#include <TNaming_ShapesSet.hxx>
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
-#include <TNaming_Iterator.hxx>
-#include <TNaming_NewShapeIterator.hxx>
-#include <TNaming_ListOfNamedShape.hxx>
-#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
-#include <TopExp.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Compound.hxx>
+
 #include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeSolid.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepTools.hxx>
-
-#include <TopTools_MapOfShape.hxx>
-#include <TopTools_MapIteratorOfMapOfShape.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_NotImplemented.hxx>
+#include <TColStd_Array1OfInteger.hxx>
 #include <TDF_Label.hxx>
 #include <TDF_LabelList.hxx>
 #include <TDF_LabelMap.hxx>
+#include <TDF_RelocationTable.hxx>
+#include <TNaming.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_Iterator.hxx>
+#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
+#include <TNaming_ListOfNamedShape.hxx>
+#include <TNaming_Name.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Naming.hxx>
+#include <TNaming_NamingTool.hxx>
+#include <TNaming_NCollections.hxx>
+#include <TNaming_NewShapeIterator.hxx>
+#include <TNaming_ShapesSet.hxx>
 #include <TNaming_Tool.hxx>
-
-#include <Standard_NotImplemented.hxx>
-#include <Standard_ConstructionError.hxx>
-#include <TopTools_Array1OfShape.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <TopoDS_Wire.hxx>
-#include <TopoDS_Shell.hxx>
-
-// mpv modifications 08.04.2002
-#include <BRepBuilderAPI_MakeWire.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Shape.hxx>
-#include <TopoDS_Solid.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS_CompSolid.hxx>
 #include <TopoDS_Compound.hxx>
+#include <TopoDS_CompSolid.hxx>
+#include <TopoDS_Face.hxx>
 #include <TopoDS_Iterator.hxx>
-#include <TopTools_ListOfShape.hxx>
-#include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <BRepBuilderAPI_MakeSolid.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Solid.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopTools_Array1OfShape.hxx>
+#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
+#include <TopTools_DataMapOfShapeListOfShape.hxx>
 #include <TopTools_HArray2OfShape.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
-#include <TopTools_DataMapOfShapeListOfShape.hxx>
-#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
-// end of mpv modifications 08.04.2002
-
-#include <TNaming_NCollections.hxx>
-
-#define BUC60925
-#define OCC352
+#include <TopTools_MapIteratorOfMapOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
 
-#ifdef DEB_DBGTOOLS_WRITE
-//#define OCC355
+// mpv modifications 08.04.2002
+// end of mpv modifications 08.04.2002
+#ifdef OCCT_DEBUG_DBGTOOLS_WRITE
 #define MDTV_DEB
 #define MDTV_DEB_OR
 #define MDTV_DEB_UNN
 #define MDTV_DEB_ARG
 #define MDTV_DEB_SHELL
 #endif
-#ifdef MDTV_DEB
+#ifdef OCCT_DEBUG
 #include <TCollection_AsciiString.hxx>
 #include <TDF_Tool.hxx>
 #include <BRepTools.hxx>
 #endif
-#ifdef DEB
+#ifdef OCCT_DEBUG
 #include <TCollection_AsciiString.hxx>
 #include <TDF_Tool.hxx>
 #include <TDF_ChildIterator.hxx>
@@ -110,7 +104,7 @@ void PrintEntries(const TDF_LabelMap& map)
       cout << "LabelEntry = "<< entry << endl;
     }
 }
-#ifdef DEB_DBGTOOLS_WRITE
+#ifdef OCCT_DEBUG_DBGTOOLS_WRITE
 //=======================================================================
 static void DbgTools_Write(const TopoDS_Shape& shape,
                      const Standard_CString filename) 
@@ -132,15 +126,13 @@ static void DbgTools_Write(const TopoDS_Shape& shape,
   save.close();
 }
 //=======================================================================
-static void DbgTools_Write(const TopTools_MapOfShape& MS,  const Standard_CString filename) 
+static void DbgTools_Write(const TopTools_IndexedMapOfShape& MS,  const Standard_CString filename) 
 {
   if (!MS.IsEmpty ()) {
     TCollection_AsciiString aNam (filename);
-    Standard_Integer i(0);
-    TopTools_MapIteratorOfMapOfShape it(MS);
-    for(;it.More();it.Next(),i++) {
-      TCollection_AsciiString aName = aNam + "_" + i + ".brep";
-      DbgTools_Write ( it.Key(), aName.ToCString());
+    for (Standard_Integer anIt = 1; anIt <= MS.Extent(); ++anIt) {
+      TCollection_AsciiString aName = aNam + "_" + (anIt - 1) + ".brep";
+      DbgTools_Write (MS (anIt), aName.ToCString());
     }
   }
 }
@@ -176,14 +168,14 @@ static Standard_Boolean ValidArgs(const TNaming_ListOfNamedShape& Args)
   for (;it.More();it.Next()) {
     const Handle(TNaming_NamedShape)& aNS = it.Value();
     if(aNS.IsNull()) {
-#ifdef MDTV_DEB_ARG 
+#ifdef OCCT_DEBUG_ARG 
       cout << "ValidArgs:: NS (Naming argument) is NULL" <<endl;
 #endif 
       return Standard_False;
     }
     else 
       if(aNS->IsEmpty()) {
-#ifdef MDTV_DEB_ARG
+#ifdef OCCT_DEBUG_ARG
        TCollection_AsciiString entry;
        TDF_Tool::Entry(aNS->Label(), entry);
        cout << "ValidArgs:: Empty NS, Label = " << entry <<endl;
@@ -192,7 +184,7 @@ static Standard_Boolean ValidArgs(const TNaming_ListOfNamedShape& Args)
     }
       else  
        if(!aNS->IsValid()) {
-#ifdef MDTV_DEB_ARG 
+#ifdef OCCT_DEBUG_ARG 
          TCollection_AsciiString entry;
          TDF_Tool::Entry(aNS->Label(), entry);
          cout << "ValidArgs::Not valid NS Label = " << entry <<endl;
@@ -371,28 +363,24 @@ Standard_Integer TNaming_Name::Index() const
 //purpose  : 
 //=======================================================================
 
-static TopoDS_Shape MakeShape (const TopTools_MapOfShape& MS) 
+static TopoDS_Shape MakeShape (const TopTools_IndexedMapOfShape& MS) 
 {  
   if (!MS.IsEmpty ()) {
-    TopTools_MapIteratorOfMapOfShape it(MS);
     if (MS.Extent() == 1) {
-      return it.Key();
+      return MS (1);
     }
     else {
       TopoDS_Compound C;
       BRep_Builder B;
       B.MakeCompound(C);
-      for (; it.More(); it.Next()){ 
-       B.Add(C,it.Key());
-      }
+      for (Standard_Integer anIt = 1; anIt <= MS.Extent(); ++anIt)
+        B.Add (C, MS (anIt));
       return C;
     }
   }
   return TopoDS_Shape();  
 }
 
-#ifdef OCC352
-
 //=======================================================================
 //function : ShapeWithType
 //purpose  : Tries to make shape with given type from the given shape
@@ -465,6 +453,7 @@ static TopoDS_Shape ShapeWithType(const TopoDS_Shape     theShape,
       TopoDS_Shell aShell;
       aShellBuilder.MakeShell(aShell);
       for(;aListIter.More();aListIter.Next()) aShellBuilder.Add(aShell,TopoDS::Face(aListIter.Value()));
+      aShell.Closed (BRep_Tool::IsClosed (aShell));
       if (theType == TopAbs_SHELL) return aShell;
       aShapes.Clear(); // don't break: we can do something more of it
       aShapes.Append(aShell);
@@ -495,26 +484,24 @@ static TopoDS_Shape ShapeWithType(const TopoDS_Shape     theShape,
   return theShape;
 }
 
-#endif
-
 //=======================================================================
 //function : FindModifUntil
 //purpose  : 
 //=======================================================================
 
 static Standard_Boolean FindModifUntil (TNaming_NewShapeIterator&         it,
-                                       TopTools_MapOfShape&              MS,
+                                       TopTools_IndexedMapOfShape& MS,
                                        const TopoDS_Shape&               S,
                                        const Handle(TNaming_NamedShape)& Context)
 { 
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
   if(!Context.IsNull())
     PrintEntry(Context->Label());
 #endif
   Standard_Boolean found = Standard_False;
   for (; it.More(); it.Next()) {
     if (!it.Shape().IsNull()) {
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
       if(!it.NamedShape().IsNull())
         PrintEntry(it.NamedShape()->Label());
 #endif
@@ -539,10 +526,10 @@ static Standard_Boolean FindModifUntil (TNaming_NewShapeIterator&         it,
 static void SearchModifUntil (const TDF_LabelMap&               /*Valid*/,
                              const Handle(TNaming_NamedShape)& Target,
                              const TNaming_ListOfNamedShape& theListOfGenerators,
-                             TopTools_MapOfShape&              theMS)
+                             TopTools_IndexedMapOfShape& theMS)
 {
 
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
    DbgTools_WriteNSOnLabel(Target, "SMUntil_"); // Target <== generated
   Standard_Integer i = 0;
   TCollection_AsciiString aGen1("Gens_New_"), aGen2("Gented_Old_"), Und("_");
@@ -551,7 +538,7 @@ static void SearchModifUntil (const TDF_LabelMap&               /*Valid*/,
   Standard_Boolean found = Standard_False;
   for (TNaming_ListIteratorOfListOfNamedShape it(theListOfGenerators); it.More(); it.Next()) {
     const Handle(TNaming_NamedShape)& aNS = it.Value();
-#ifdef MDTV_DEB_MODUN  
+#ifdef OCCT_DEBUG_MODUN  
     i++;
     Standard_Integer j = 0;
 #endif
@@ -559,7 +546,7 @@ static void SearchModifUntil (const TDF_LabelMap&               /*Valid*/,
       const TopoDS_Shape& S = itL.NewShape();
       found = Standard_False;
       
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
       j++;
       Standard_Integer k = 0;
       TCollection_AsciiString aNam1 = aGen1 + i + Und + j + ".brep";
@@ -569,7 +556,7 @@ static void SearchModifUntil (const TDF_LabelMap&               /*Valid*/,
       TNaming_Iterator itC (Target);
       for  (; itC.More(); itC.Next()) {  // <- generated
        const TopoDS_Shape& OS = itC.OldShape();
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
        k++;
        TCollection_AsciiString aNam2 = aGen2 + i + Und + j + Und + k + ".brep";
        DbgTools_Write(OS, aNam2.ToCString());
@@ -578,7 +565,7 @@ static void SearchModifUntil (const TDF_LabelMap&               /*Valid*/,
        if (OS.IsSame(S)) {
          theMS.Add(S);
          found = Standard_True;
-#ifdef MDTV_DEB_MODUN
+#ifdef OCCT_DEBUG_MODUN
          cout << aNam2 << " is Same with " << aNam1 <<endl;
 #endif
          break;
@@ -609,14 +596,12 @@ static Standard_Boolean ModifUntil (const TDF_Label&                  L,
                                    const TNaming_ListOfNamedShape&   Args,
                                    const Handle(TNaming_NamedShape)& Stop)
 {
-  TopTools_MapOfShape MS; 
+  TopTools_IndexedMapOfShape MS; 
   TDF_LabelMap Forbiden;
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden); // fills Forbidden from Stop
 
-#ifdef MDTV_DEB_GEN  
+#ifdef OCCT_DEBUG_GEN  
   cout <<"Regenerating ModifUntil => ";
   PrintEntry(L);
   DbgTools_WriteNSOnLabel(Args.Last(), "ModifUntil-");
@@ -624,17 +609,16 @@ static Standard_Boolean ModifUntil (const TDF_Label&                  L,
 #endif
   // all last modifications of the last argument
   TNaming_NamingTool::CurrentShape  (Valid, Forbiden,Args.Last(),MS); 
-#ifdef MDTV_DEB_GEN  
+#ifdef OCCT_DEBUG_GEN  
   Standard_Integer i(0);
-  TopTools_MapIteratorOfMapOfShape it(MS);
   TCollection_AsciiString aNam("ModifUnti_MS_");
   TCollection_AsciiString ext(".brep"); 
 #endif
   TNaming_Builder B(L);
-  for (TopTools_MapIteratorOfMapOfShape itM(MS); itM.More(); itM.Next()) {
-    const TopoDS_Shape& S = itM.Key();
+  for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
+    const TopoDS_Shape& S = MS (anItMS);
     B.Select(S,S);
-#ifdef MDTV_DEB_GEN  
+#ifdef OCCT_DEBUG_GEN  
     TCollection_AsciiString aName = aNam + ++i + ext;
     DbgTools_Write(S, aName.ToCString()) ;
     cout << aName.ToCString() << " TS = " << S.TShape()->This() <<endl;
@@ -658,11 +642,9 @@ static Standard_Boolean ConstShape (const TDF_Label&                  L,
                                    const Handle(TNaming_NamedShape)& Stop,
                                    const Standard_Integer            Index)
 {
-  TopTools_MapOfShape MS; 
+  TopTools_IndexedMapOfShape MS; 
   TDF_LabelMap Forbiden;
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden);
 
   TopoDS_Shape S;
@@ -679,8 +661,8 @@ static Standard_Boolean ConstShape (const TDF_Label&                  L,
 
  
   TNaming_Builder B(L);
-  for (TopTools_MapIteratorOfMapOfShape itM(MS); itM.More(); itM.Next()) {
-    const TopoDS_Shape& SS = itM.Key();
+  for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
+    const TopoDS_Shape& SS = MS (anItMS);
     B.Select(SS,SS);
   }
   return Standard_True;
@@ -709,14 +691,12 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
                                      const Standard_Integer            Index)
 {
   if (Args.IsEmpty()) return Standard_False;
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   TNaming_ListIteratorOfListOfNamedShape it(Args); 
-  TopTools_MapOfShape MS; 
+  TopTools_IndexedMapOfShape MS; 
   TDF_LabelMap        Forbiden;
 
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
   if(!Stop.IsNull() && !Stop->Get().IsNull()) {
     DbgTools_Write(Stop->Get(), "Ints_Stop.brep");
     PrintEntry(Stop->Label());
@@ -728,7 +708,7 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
 
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden); // <==<1>
 
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
   cout << "Intersection:: Valid Map: "<<endl;
   PrintEntries(Valid);
   cout << "Intersection:: Forbidden Map: "<<endl;
@@ -739,7 +719,7 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
   TopoDS_Shape  CS = MakeShape(MS);
   TNaming_ShapesSet S(CS,ShapeType); // <==<2>
   aListOfAnc.Append(CS);
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
   if(!CS.IsNull())
     DbgTools_Write(CS, "Int_CS_1.brep");
   Standard_Integer i=2;
@@ -753,7 +733,7 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
     TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MS);
     CS = MakeShape(MS);
     aListOfAnc.Append(CS);
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
     TCollection_AsciiString aName = aNam + i++ + ext;      
     DbgTools_Write(CS, aName.ToCString()) ;
     cout <<"Argument " << i << " at ";
@@ -762,7 +742,7 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
 
     TNaming_ShapesSet OS(CS,ShapeType);
     S.Filter(OS); //<<===<3.2>
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
     Standard_Integer j = 1;
     TCollection_AsciiString aNam2("SSMap_"), aName3;
     TopTools_MapIteratorOfMapOfShape itm(S.Map());
@@ -773,7 +753,7 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
 #endif 
   }
 
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
   aNam = "Int_S_";
   i =1;
 #endif
@@ -787,16 +767,16 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
     indxW = (Index & 0x000F0000) >> 16;
     nbW   = (Index & 0x00F00000) >> 20;
     indxF = (Index & 0x0F000000) >> 24;
-    Standard_Integer i(1);
+    Standard_Integer k(1);
     TopoDS_Shape aS;
     TopTools_ListIteratorOfListOfShape itl(aListOfAnc);
-    for(;itl.More();itl.Next(),i++) {
-      if(indxF == i) {
+    for(;itl.More();itl.Next(),k++) {
+      if(indxF == k) {
        aS = itl.Value();
        break;
       }      
     }
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
     cout <<"Kept: indxE = " << indxE  <<" maxENum = " << nbE << " indxW = " <<indxW << " nbW = " <<nbW<<endl;
 #endif      
     Standard_Integer aNbW(0), aCaseW(0);
@@ -837,14 +817,14 @@ static Standard_Boolean Intersection (const TDF_Label&                  L,
     }   
   } 
   if(!isOK)
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
     for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next(),i++) {
 #else
       
     for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next()) {
 #endif
       const TopoDS_Shape& S1 = itM.Key();
-#ifdef MDTV_DEB_INT
+#ifdef OCCT_DEBUG_INT
       TCollection_AsciiString aName = aNam + i + ext;      
       DbgTools_Write(S1, aName.ToCString()) ;
 #endif  
@@ -899,9 +879,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
                               const TDF_Label&                  ContextLabel)
 {  
   if (Args.IsEmpty()) return Standard_False;
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   // temporary solution for Orientation name
   Standard_Boolean isOr(Standard_True);
 /* not completed
@@ -931,7 +909,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
   // end of temp. sol.
 
   TNaming_ListIteratorOfListOfNamedShape it(Args);
-  TopTools_MapOfShape MS; 
+  TopTools_IndexedMapOfShape MS; 
   TDF_LabelMap        Forbiden;
   
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
@@ -942,7 +920,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
   if(isOr)
     KeepInList(CS,ShapeType,aListS);
   TNaming_ShapesSet S(CS,ShapeType);//fill internal map of shapeset by shapes of the specified type
-#ifdef MDTV_DEB_UNN
+#ifdef OCCT_DEBUG_UNN
   TCollection_AsciiString entry; 
   TDF_Tool::Entry(it.Value()->Label(), entry);
   TCollection_AsciiString Nam("Arg_");
@@ -952,7 +930,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
 #endif
   it.Next();
   for (; it.More(); it.Next()) {
-#ifdef MDTV_DEB_UNN  
+#ifdef OCCT_DEBUG_UNN  
     TDF_Tool::Entry(it.Value()->Label(), entry);
 #endif
       MS.Clear();
@@ -963,7 +941,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
       TNaming_ShapesSet OS(CS,ShapeType);
       S.Add(OS); //concatenate both shapesets
  
-#ifdef MDTV_DEB_UNN 
+#ifdef OCCT_DEBUG_UNN 
     ii++;
     TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
     DbgTools_Write(CS, aNm.ToCString());
@@ -982,7 +960,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
       MS.Clear();
       TNaming_NamingTool::CurrentShape (Valid, Forbiden, CNS, MS);
       aContext = MakeShape(MS);
-#ifdef MDTV_DEB_UNN 
+#ifdef OCCT_DEBUG_UNN 
       TCollection_AsciiString anEntry;
       TDF_Tool::Entry(ContextLabel, anEntry);
       cout << "UNION: Context Label = " <<  anEntry << endl;
@@ -999,7 +977,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
     TopExp_Explorer anExpl(aContext, ShapeType);
     for(;anExpl.More(); anExpl.Next()) 
       aList.Append(anExpl.Current());
-#ifdef MDTV_DEB_UNN
+#ifdef OCCT_DEBUG_UNN
     cout <<"UNION: ShapeType = " << ShapeType << " List ext = " << aList.Extent()<<endl;
     TopAbs_ShapeEnum aTyp = TopAbs_SHAPE;
     TopTools_MapIteratorOfMapOfShape it1 (S.Map());
@@ -1017,7 +995,7 @@ static Standard_Boolean Union (const TDF_Label&                  L,
     TopTools_ListIteratorOfListOfShape itl(aList);
     for(;itl.More();itl.Next()) {
       aCand = itl.Value(); 
-#ifdef MDTV_DEB_UNN 
+#ifdef OCCT_DEBUG_UNN 
       DbgTools_Write(aCand, "Cand.brep");
 #endif
       Standard_Integer num = S.Map().Extent();
@@ -1035,13 +1013,12 @@ static Standard_Boolean Union (const TDF_Label&                  L,
   }
 
   TNaming_Builder B(L);
-#ifdef MDTV_DEB_UNN
+#ifdef OCCT_DEBUG_UNN
   if(!ContextLabel.IsNull()) {
     if(found) cout << "UNION: Shape is found in Context" <<endl;
     else cout << "UNION: Shape is NOT found in Context" <<endl;
   }
 #endif
-#ifdef OCC352
   if(found) 
     B.Select(aCand, aCand);
   else {
@@ -1057,21 +1034,12 @@ static Standard_Boolean Union (const TDF_Label&                  L,
        aCompoundBuilder.Add(aCompound,itL.Value());
       }
     TopoDS_Shape aShape = ShapeWithType(aCompound,ShapeType);
-#ifdef MDTV_DEB_UNN 
+#ifdef OCCT_DEBUG_UNN 
     DbgTools_Write(aShape, "Union_Selected.brep");
     DbgTools_Write(aCompound, "Union_Compound.brep");
 #endif
     B.Select(aShape,aShape);
   }
-#else
-
-  for (TopTools_MapIteratorOfMapOfShape itM(S.Map()); itM.More(); itM.Next()) {
-    const TopoDS_Shape& S = itM.Key();
-    B.Select(S,S);
-  }
-
-#endif
-
   return Standard_True;
 }
 
@@ -1133,20 +1101,18 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
   // First argument : label of generation
   // Next arguments : generators.
 
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
 
   TDF_Label   LabelOfGeneration = Args.First()->Label();
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       DbgTools_Write(Args.First()->Get(),  "Generated.brep") ;
 #endif
   // Nouvell valeurs des generateurs dans l attribut de generation
-  TopTools_MapOfShape aMS;
+  TopTools_IndexedMapOfShape aMS;
   TNaming_ListOfNamedShape aGenerators; 
   aGenerators.Assign(Args); 
   aGenerators.RemoveFirst(); 
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       DbgTools_Write(aGenerators.First()->Get(),  "Generators.brep") ;
 #endif
   SearchModifUntil (Valid, Args.First(), aGenerators, aMS);
@@ -1155,7 +1121,7 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
   L.FindAttribute(TNaming_Naming::GetID(),aNaming);
   if(!aNaming.IsNull()) 
     aSelection = aNaming->GetName().Shape();
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
   DbgTools_Write(aSelection,  "G_Selection.brep") ;
   cout << "Generated::SearchModifUntil aMS.Extent() = " << aMS.Extent() <<endl;
   DbgTools_Write(aMS, "SearchModifUntil_Result");
@@ -1166,7 +1132,7 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
    if(!anOldNS.IsNull()) 
      aVer = anOldNS->Version();
 
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
   Standard_Integer i = 0, j=1;
   TCollection_AsciiString aNam2("Gen_New_");
   TCollection_AsciiString aNam1("Gen_Old_");
@@ -1175,9 +1141,9 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
   TNaming_Builder B(L); // NS
   TopTools_ListOfShape aList;
   TNaming_DataMapOfShapeMapOfShape aDM; 
-  for (TopTools_MapIteratorOfMapOfShape itMS(aMS); itMS.More(); itMS.Next()) {
-    const TopoDS_Shape& OS = itMS.Key();
-#ifdef MDTV_DEB_GEN
+  for (Standard_Integer anItMS = 1; anItMS <= aMS.Extent(); ++anItMS) {
+    const TopoDS_Shape& OS = aMS (anItMS);
+#ifdef OCCT_DEBUG_GEN
     TCollection_AsciiString aName = aNam1 + ++i + ext;      
     DbgTools_Write(OS, aName.ToCString()) ;
     Standard_Integer j=0;
@@ -1187,7 +1153,7 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
       if (itNew.Label() == LabelOfGeneration) {
        aMapDM.Add(itNew.Shape());
        aList.Append(itNew.Shape());//szy 21.10.03
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
        TCollection_AsciiString aName = aNam2 + i +  "_" + ++j + ext;      
        DbgTools_Write(itNew.Shape(), aName.ToCString()) ;
 #endif
@@ -1231,16 +1197,16 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
 
       Standard_Boolean found = Standard_False;
       TopoDS_Shape aShape = FindShape(aDM);
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       if(!aShape.IsNull())
        DbgTools_Write(aShape,  "G_FindShape.brep") ;
 #endif
       if(!aShape.IsNull()) found = Standard_True;
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       cout << "Generated ==>aGenerators.Extent() = " <<aGenerators.Extent() <<" aMS.Extent()= " <<aMS.Extent()<<endl;
 #endif
       if(found) {
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       cout << "Generated ==> Shape is found!" <<endl;
 #endif
        TopTools_ListOfShape aLM;
@@ -1248,7 +1214,7 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
        Standard_Boolean a1NB = Standard_False;
        if(aGenerators.Extent() != aMS.Extent()) { //missed generators
          aHas = Standard_True;//has lost generatos
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
       cout << "Generated ==> has lost generatos!" <<endl;
 #endif
          for (TNaming_ListIteratorOfListOfNamedShape itg(aGenerators); itg.More(); itg.Next()) {
@@ -1258,8 +1224,8 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
          if(aLM.Extent() == 1) {//lost 1
            TopTools_ListIteratorOfListOfShape itm(aLM);
            TopoDS_Shape aSM = itm.Value(); // Missed
-           for (TopTools_MapIteratorOfMapOfShape itMS1(aMS); itMS1.More(); itMS1.Next()) {
-             const TopoDS_Shape& aS = itMS1.Key();
+      for (Standard_Integer anItMS1 = 1; anItMS1 <= aMS.Extent(); ++anItMS1) {
+             const TopoDS_Shape& aS = aMS (anItMS1);
              if(aSM.ShapeType() == aS.ShapeType()) {
                if(aS.ShapeType() == TopAbs_EDGE) {
                  TopoDS_Vertex aVCom;
@@ -1308,7 +1274,7 @@ static Standard_Boolean  Generated (const TDF_Label&                L,
        }
     } else 
       {        //not found
-#ifdef MDTV_DEB_GEN
+#ifdef OCCT_DEBUG_GEN
        cout << "Generated ==> Shape is NOT found! Probably Compound will be built" <<endl;
 #endif
 
@@ -1339,26 +1305,20 @@ static Standard_Boolean Identity (const TDF_Label&                L,
   if (Args.Extent() > 2) {
     Standard_ConstructionError::Raise("TNaming_Name::Solve");
     }
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   const Handle(TNaming_NamedShape)& A = Args.First();
-  TopTools_MapOfShape MS;
+  TopTools_IndexedMapOfShape MS;
   TDF_LabelMap        Forbiden;
   TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
-#ifdef MDTV_DEB_SOL2
+#ifdef OCCT_DEBUG_SOL2
   //TCollection_AsciiString entry;
   //TDF_Tool::Entry(L, entry);
   //TDF_Tool::Entry(A->Label(), entry);
 #endif  
   TNaming_Builder B(L);
-  for (TopTools_MapIteratorOfMapOfShape itM(MS); itM.More(); itM.Next()) {
-#ifdef OCC352
-    const TopoDS_Shape& S = ShapeWithType(itM.Key(),ShapeType);
-#else
-    const TopoDS_Shape& S = itM.Key();
-#endif
-#ifdef MDTV_DEB_SOL2
+  for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) {
+    const TopoDS_Shape& S = ShapeWithType (MS (anItMS), ShapeType);
+#ifdef OCCT_DEBUG_SOL2
     //TopAbs_Orientation Or = S.Orientation();
 #endif
     B.Select(S,S);
@@ -1384,9 +1344,7 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
   TNaming_Builder B(L); 
 
   TDF_LabelMap        Forbiden;
-#ifdef BUC60925
   if(!ValidArgs(Args)) return Standard_False;
-#endif
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden); //all descendants of Stop (New shapes) are forbidden
   if (!Stop.IsNull())    Forbiden.Remove(Stop->Label());
   //----------------------------------------
@@ -1394,7 +1352,7 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
   //----------------------------------------
   Handle(TNaming_NamedShape) Cand  = Args.First(); //collection of candidates
    
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
   Standard_Integer i = 1;
   TCollection_AsciiString aNam("Cand_");
   TCollection_AsciiString ext(".brep");
@@ -1405,10 +1363,10 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
   PrintEntries(Valid);
 #endif
 
-  TopTools_MapOfShape    SCand;
+  TopTools_IndexedMapOfShape SCand;
   TNaming_NamingTool::CurrentShape  (Valid, Forbiden,Cand,SCand);//fills SCand with last modifications of Cand. CandNS should be at the same level (before) as NS of FilterByNBS
 
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
   TCollection_AsciiString aNam2("SCand");
   DbgTools_Write(SCand, aNam2.ToCString());  
   cout <<"SCand Extent = " << SCand.Extent() << " Expected ShapeType = " << ShapeType << endl;
@@ -1422,31 +1380,30 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
   if (ShapeType == TopAbs_EDGE) TC = TopAbs_VERTEX;
   if (ShapeType == TopAbs_VERTEX) TC = TopAbs_VERTEX; // szy 31.03.10 - to process case when Candidate is of type Vertex
  
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
   i=1;
   aNam = "Boundaries";
 #endif
   Standard_Boolean isDone = Standard_False;
   if(SCand.Extent() == 1) { // check if a collection is inside
-    TopTools_MapIteratorOfMapOfShape it(SCand);
-    const TopoDS_Shape& aS = it.Key();
+    TopoDS_Shape aS = SCand (1);
     if(!aS.IsNull()) 
       if(aS.ShapeType() == TopAbs_COMPOUND && aS.ShapeType() != ShapeType) {
+        SCand.Clear();
        TopoDS_Iterator itt(aS);
        for(;itt.More();itt.Next()) 
          SCand.Add(itt.Value());      
-       SCand.Remove(aS);
       }
   }
-  for (TopTools_MapIteratorOfMapOfShape itCand(SCand); itCand.More(); itCand.Next()) { //1
-    const TopoDS_Shape& S    = itCand.Key();
+  for (Standard_Integer anItSCand = 1; anItSCand <= SCand.Extent(); ++anItSCand) { //1
+    const TopoDS_Shape& S = SCand (anItSCand);
     TopTools_MapOfShape Boundaries;
     if(S.ShapeType() == TopAbs_VERTEX) //# szy 31.03.10
       Boundaries.Add (S); //#
     else  //#
       for (TopExp_Explorer exp(S,TC); exp.More(); exp.Next()) { //put boundaries of each candidate (from SCand) to the Boundaries map
        Boundaries.Add (exp.Current());
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
        TCollection_AsciiString aName = aNam + i++ + ext;      
        DbgTools_Write(exp.Current(),  aName.ToCString()) ;
 #endif
@@ -1455,7 +1412,7 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
     TNaming_ListIteratorOfListOfNamedShape it(Args); 
     it.Next(); 
     Standard_Boolean Keep = 1;
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
     cout <<"Args number = " << Args.Extent() <<endl;
     i=1;
     aNam = "Boundaries";
@@ -1468,24 +1425,24 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
       // of each neighbor.
       const Handle(TNaming_NamedShape)& NSVois = it.Value();  //neighbor 
 
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
       DbgTools_WriteNSOnLabel(NSVois, "Next_Neighbor_") ;
 #endif
       
-      TopTools_MapOfShape    SVois;
+      TopTools_IndexedMapOfShape SVois;
       TNaming_NamingTool::CurrentShape  (Valid, Forbiden,NSVois,SVois); // fills SVois with last modifications of NSVois
 
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
       TCollection_AsciiString aNam2("SVois");
       DbgTools_Write(SVois, aNam2.ToCString());
 #endif 
 
-      for (TopTools_MapIteratorOfMapOfShape itVois(SVois); itVois.More(); itVois.Next()) { //6
-       const TopoDS_Shape& Vois = itVois.Key();
+      for (Standard_Integer anItSVois = 1; anItSVois <= SVois.Extent(); ++anItSVois) { //6
+        const TopoDS_Shape& Vois = SVois (anItSVois);
        for (TopExp_Explorer exp1(Vois,TC); exp1.More(); exp1.Next()) { //7
          if (Boundaries.Contains(exp1.Current())) {
            Connected = Standard_True; // has common boundaries with candidate shape
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
            DbgTools_Write(Vois, "Neighbor_Connected.brep");
 #endif
            break;
@@ -1501,7 +1458,7 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
     if (Keep) {
       B.Select (S,S);
          isDone = Standard_True;
-#ifdef MDTV_DEB_FNB
+#ifdef OCCT_DEBUG_FNB
       DbgTools_Write(S,  "FilterByNbs_Sel.brep") ;
 #endif
     }
@@ -1512,7 +1469,7 @@ static Standard_Boolean  FilterByNeighbourgs (const TDF_Label&                L,
 //=======================================================================
 static const TopoDS_Shape FindSubShapeInAncestor(const TopoDS_Shape& Selection, const TopoDS_Shape& Context )
 {
-#ifdef MDTV_DEB_OR_AG
+#ifdef OCCT_DEBUG_OR_AG
   DbgTools_Write(Selection, "Orientation_Selection.brep");
   DbgTools_Write(Context, "Orientation_Context.brep");
   TopExp_Explorer expl1(Context, Selection.ShapeType());
@@ -1530,7 +1487,7 @@ static const TopoDS_Shape FindSubShapeInAncestor(const TopoDS_Shape& Selection,
   if(Selection.ShapeType() != TopAbs_COMPOUND) {
     TopExp_Explorer anExpl(Context, Selection.ShapeType());
     for(;anExpl.More(); anExpl.Next()) {
-#ifdef MDTV_DEB_OR_AG
+#ifdef OCCT_DEBUG_OR_AG
       cout <<"FindSubShape:  = " <<anExpl.Current().ShapeType() << " TS = " <<anExpl.Current().TShape()->This() << endl;
       DbgTools_Write(anExpl.Current(), "Orientation_Current.brep");
 #endif    
@@ -1592,58 +1549,57 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
   if(!ValidArgs(Args)) return Standard_False;
 
   const Handle(TNaming_NamedShape)& A = Args.First();
-  TopTools_MapOfShape MS; 
+  TopTools_IndexedMapOfShape MS; 
   TDF_LabelMap        Forbiden;
   TNaming_NamingTool::BuildDescendants (Stop, Forbiden);
   TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
 
-  TopoDS_Shape S; 
+  TopoDS_Shape aShape;
   Standard_Boolean isSplit(Standard_False);
   if (!MS.IsEmpty ()) {
-    TopTools_MapIteratorOfMapOfShape it(MS);
     if (MS.Extent() == 1) {
-      S = it.Key(); 
+      aShape = MS (1);
     } 
     else {
       isSplit = Standard_True;
-      S = MakeShape(MS);
-#ifdef MDTV_DEB_OR
-      for(Standard_Integer i=1;it.More();it.Next(), i++) {
+      aShape = MakeShape(MS);
+#ifdef OCCT_DEBUG_OR
+      for(Standard_Integer anItMS = 1; anItMS <= MS.Extent(); anItMS++) {
        TCollection_AsciiString aNam("OR_Selection_");
-       TCollection_AsciiString aName = aNam + i + ".brep";
-       DbgTools_Write(it.Key(), aName.ToCString());
+       TCollection_AsciiString aName = aNam + anItMS + ".brep";
+       DbgTools_Write(MS (anItMS), aName.ToCString());
       }
 #endif
     }
   }
 
   TNaming_Builder B(L);
-  if(S.IsNull()) 
+  if(aShape.IsNull())
     return Standard_False;
-#ifdef MDTV_DEB_OR
+#ifdef OCCT_DEBUG_OR
   DbgTools_Write(S, "Orientation_S.brep");
 #endif
 
   TopTools_ListOfShape aSList;
   // tmp. solution
-  if(S.ShapeType() == TopAbs_COMPOUND && !isSplit) {
-    TopoDS_Iterator it(S);
+  if(aShape.ShapeType() == TopAbs_COMPOUND && !isSplit) {
+    TopoDS_Iterator it(aShape);
     for(;it.More();it.Next())
       aSList.Append(it.Value());
   } //
  
-  TopTools_MapOfShape MSC; 
+  TopTools_IndexedMapOfShape MSC; 
   if(aSList.Extent() == 0) {
     const Handle(TNaming_NamedShape)& Anc = Args.Last();
-#ifdef MDTV_DEB_OR
+#ifdef OCCT_DEBUG_OR
     cout << "### ORIENTATION: Ancestor ";
     PrintEntry(Anc->Label());
 #endif
     MSC.Clear();
     TNaming_NamingTool::CurrentShape (Valid,Forbiden,Anc,MSC);
     if(MSC.Extent() == 1) {
-      for (TopTools_MapIteratorOfMapOfShape itM(MSC); itM.More(); itM.Next()) {
-       const TopoDS_Shape& AS = itM.Key(); 
+      for (Standard_Integer anItMSC = 1; anItMSC <= MSC.Extent(); ++anItMSC) {
+        const TopoDS_Shape& AS = MSC (anItMSC);
 // <=== start 21.10.2009
        TopoDS_Shape CS;
        if(Index > 0) { //only for seam edge
@@ -1652,10 +1608,10 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
            Standard_Boolean found(Standard_False);
            TopoDS_Iterator it(itw.Value());
            for(int i=1;it.More();it.Next(),i++) {
-             if(i == Index && it.Value().IsSame(S)) {
+             if(i == Index && it.Value().IsSame(aShape)) {
                CS = it.Value();
                found = Standard_True;
-#ifdef MDTV_DEB_OR
+#ifdef OCCT_DEBUG_OR
                cout << "ORIENTATION => ORDER = " << i <<endl;
 #endif
                break;
@@ -1664,27 +1620,27 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
            if(found) break;
          }
        } else
-         CS =  FindSubShapeInAncestor(S, AS);
+         CS =  FindSubShapeInAncestor(aShape, AS);
 // <=== end 21.10.2009
-#ifdef MDTV_DEB_OR
-       cout << "ORIENTATION: Selection" <<" TShape = " <<CS.TShape() <<" Orientation = " << CS.Orientation() <<endl;
-       cout << "ORIENTATION: Context " << "ShapeType = "<<AS.ShapeType() << " TShape = " <<AS.TShape() <<endl;
+#ifdef OCCT_DEBUG_OR
+       cout << "ORIENTATION: Selection TShape = " <<CS.TShape() <<" Orientation = " << CS.Orientation() <<endl;
+       cout << "ORIENTATION: Context ShapeType = "<<AS.ShapeType() << " TShape = " <<AS.TShape() <<endl;
        DbgTools_Write(AS, "Orientation_Cnt.brep");
 #endif
        if(!CS.IsNull()) {
          B.Select(CS, CS);
        } else {
-         if(!Aggregation(S, AS, B)) 
+         if(!Aggregation(aShape, AS, B))
            return Standard_False;        
        }
       }  
     } else {
       const TopoDS_Shape  AS = MakeShape(MSC);
-      const TopoDS_Shape& CS =  FindSubShapeInAncestor(S, AS);
+      const TopoDS_Shape& CS =  FindSubShapeInAncestor(aShape, AS);
       if(!CS.IsNull()) {
        B.Select(CS, CS);
       }  else {
-       if(!Aggregation(S, AS, B)) 
+       if(!Aggregation(aShape, AS, B)) 
          return Standard_False;        
       }
     }
@@ -1702,10 +1658,7 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
       MSC.Clear();
       TNaming_NamingTool::CurrentShape (Valid,Forbiden,it.Value(),MSC);
       if(MSC.Extent() == 1) {
-       for (TopTools_MapIteratorOfMapOfShape itM(MSC); itM.More(); itM.Next()) {
-         const TopoDS_Shape& AS = itM.Key(); 
-         Arr->SetValue(i, 2, AS);
-       }
+        Arr->SetValue(i, 2, MSC (1));
       } else {
        const TopoDS_Shape  AS = MakeShape(MSC);
        Arr->SetValue(i, 2, AS);
@@ -1722,7 +1675,7 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
          return Standard_False;
       } 
       else {
-#ifdef MDTV_DEB_OR
+#ifdef OCCT_DEBUG_OR
        DbgTools_Write(Arr->Value(1,2), "Ancestor.brep");
 #endif
        if(!Aggregation(S, Arr->Value(1,2), B)) { 
@@ -1731,9 +1684,9 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
       }
     }
     else { // > 1   
-      for(Standard_Integer i = Arr->LowerRow();i <= Arr->UpperRow();i++) {
-       const TopoDS_Shape& S = Arr->Value(i,1);
-       const TopoDS_Shape& AC = Arr->Value(i,2);
+      for(Standard_Integer k = Arr->LowerRow();k <= Arr->UpperRow();k++) {
+       const TopoDS_Shape& S = Arr->Value(k,1);
+       const TopoDS_Shape& AC = Arr->Value(k,2);
        if(S.ShapeType() != TopAbs_COMPOUND) {      
          const TopoDS_Shape& CS =  FindSubShapeInAncestor(S, AC);
          if(!CS.IsNull()) {
@@ -1742,7 +1695,7 @@ static Standard_Boolean ORientation (const TDF_Label&                L,
            return Standard_False;
        }
        else {
-#ifdef MDTV_DEB_OR
+#ifdef OCCT_DEBUG_OR
          DbgTools_Write(AC, "Aggregation.brep");
 #endif
          if(!Aggregation(S, AC, B)) { 
@@ -1768,16 +1721,15 @@ static Standard_Boolean WireIN(const TDF_Label&                L,
 {
   Standard_Boolean aResult(Standard_False);
   if(!ValidArgs(Args)) return aResult;
-  TopTools_MapOfShape MS; 
-  TDF_LabelMap        Forbiden;
+  TopTools_IndexedMapOfShape aMapOfSh;
+  TDF_LabelMap        aForbiden;
   if (Args.Extent() < 1 ) 
     Standard_ConstructionError::Raise("TNaming_Name::Solve"); 
   const Handle(TNaming_NamedShape)& A = Args.First();
-  TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
-  if (MS.Extent() != 1) return aResult;
-  TopTools_MapIteratorOfMapOfShape itM(MS); 
-  const TopoDS_Shape& aCF = itM.Key()   ;
-#ifdef MDTV_DEB_WIN
+  TNaming_NamingTool::CurrentShape (Valid,aForbiden,A, aMapOfSh);
+  if (aMapOfSh.Extent() != 1) return aResult;
+  const TopoDS_Shape& aCF = aMapOfSh(1);
+#ifdef OCCT_DEBUG_WIN
   cout <<"MS Extent = " <<MS.Extent() <<endl;
   DbgTools_Write(aCF, "Context_Face.brep");
 #endif
@@ -1794,16 +1746,16 @@ static Standard_Boolean WireIN(const TDF_Label&                L,
     ArgsE.Assign(Args);
     ArgsE.RemoveFirst();
        // fill Map with edges 
-    TNaming_ListIteratorOfListOfNamedShape it(ArgsE);
-    TopTools_MapOfShape MS; 
+    TNaming_ListIteratorOfListOfNamedShape anIter(ArgsE);
+    TopTools_IndexedMapOfShape MS; 
     TDF_LabelMap        Forbiden;
   
     TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
-    TNaming_NamingTool::CurrentShape  (Valid, Forbiden,it.Value(),MS); // fill MS with last modifications of the first additional argument
+    TNaming_NamingTool::CurrentShape  (Valid, Forbiden, anIter.Value(),MS); // fill MS with last modifications of the first additional argument
     TopoDS_Shape  CS = MakeShape(MS);
 
     TNaming_ShapesSet aSet(CS,TopAbs_EDGE);//fill internal map of shapeset by shapes of the specified type
-#ifdef MDTV_DEB_WIN
+#ifdef OCCT_DEBUG_WIN
     TCollection_AsciiString entry; 
     TDF_Tool::Entry(it.Value()->Label(), entry);
     TCollection_AsciiString Nam("Arg_");
@@ -1811,18 +1763,18 @@ static Standard_Boolean WireIN(const TDF_Label&                L,
     DbgTools_Write(CS, aNam.ToCString());
     Standard_Integer ii = 2;
 #endif
-    it.Next();
-    for (; it.More(); it.Next()) {
-#ifdef MDTV_DEB_WIN 
+    anIter.Next();
+    for (; anIter.More(); anIter.Next()) {
+#ifdef OCCT_DEBUG_WIN 
       TDF_Tool::Entry(it.Value()->Label(), entry);
 #endif
       MS.Clear();
-      TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value()
+      TNaming_NamingTool::CurrentShape (Valid, Forbiden,anIter.Value(),MS);// fill MS with last modifications of the it.Value()
       CS = MakeShape(MS); 
       TNaming_ShapesSet OS(CS,TopAbs_EDGE);
       aSet.Add(OS); //concatenate both shapesets
  
-#ifdef MDTV_DEB_WIN
+#ifdef OCCT_DEBUG_WIN
       ii++;
       TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
       DbgTools_Write(CS, aNm.ToCString());
@@ -1830,8 +1782,8 @@ static Standard_Boolean WireIN(const TDF_Label&                L,
 #endif
        }
 
-#ifdef MDTV_DEB_WIN
-    cout <<"WIREIN: " << " Internal Map ext = " << aSet.Map().Extent()<<endl;
+#ifdef OCCT_DEBUG_WIN
+    cout <<"WIREIN:  Internal Map ext = " << aSet.Map().Extent()<<endl;
     TopTools_MapIteratorOfMapOfShape it1 (aSet.Map());
     for (int i=1;it1.More();it1.Next(),i++) {
       cout << "Map("<<i<<"): TShape = " << it1.Key().TShape() << " Orient = " << it1.Key().Orientation() <<" Type = " <<
@@ -1848,7 +1800,7 @@ static Standard_Boolean WireIN(const TDF_Label&                L,
   for (TopoDS_Iterator itF(aCF); itF.More(); itF.Next()) {// find the expected wire in the face
     const TopoDS_Shape& S = itF.Value();//wire
        if(!S.IsNull()) {
-#ifdef MDTV_DEB_WIN    
+#ifdef OCCT_DEBUG_WIN    
       DbgTools_Write(S, "WireIN_S.brep");
       cout <<"WIREIN: ShapeType = " << S.ShapeType() << " TS = " << S.TShape()->This() <<endl;
 #endif       
@@ -1905,16 +1857,15 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
   Standard_Boolean aResult(Standard_False);
   if(!ValidArgs(Args)) 
          return aResult;
-  TopTools_MapOfShape MS
-  TDF_LabelMap        Forbiden;
+  TopTools_IndexedMapOfShape aMapOfSh
+  TDF_LabelMap        aForbiden;
   if (Args.Extent() < 1 ) 
     Standard_ConstructionError::Raise("TNaming_Name::Solve"); 
   const Handle(TNaming_NamedShape)& A = Args.First();
-  TNaming_NamingTool::CurrentShape (Valid,Forbiden,A,MS);
-  if (MS.Extent() != 1) return aResult;
-  TopTools_MapIteratorOfMapOfShape itM(MS); 
-  const TopoDS_Shape& aCSO = itM.Key()   ;
-#ifdef MDTV_DEB_SHELL
+  TNaming_NamingTool::CurrentShape (Valid,aForbiden,A, aMapOfSh);
+  if (aMapOfSh.Extent() != 1) return aResult;
+  const TopoDS_Shape& aCSO = aMapOfSh(1);
+#ifdef OCCT_DEBUG_SHELL
   cout <<"MS Extent = " <<MS.Extent() <<endl;
   DbgTools_Write(aCSO, "Context_Solid.brep");
 #endif
@@ -1925,11 +1876,11 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
        if(!anOuterShell.IsNull()) {
       B.Select(anOuterShell, anOuterShell);
          aResult = Standard_True;
-#ifdef MDTV_DEB_SHELL      
+#ifdef OCCT_DEBUG_SHELL      
          cout << "Outer Shell case" <<endl;
       PrintEntry(L);
          DbgTools_Write(anOuterShell, "ShellOut_S.brep");
-         it.Initialize(aCSO);
+         TopoDS_Iterator it (aCSO);
                for(;it.More();it.Next()){ 
           DbgTools_Write(it.Value(), "ShOut_S.brep");
                }
@@ -1940,35 +1891,35 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
     ArgsF.Assign(Args);
     ArgsF.RemoveFirst();
        // fill Map with faces 
-    TNaming_ListIteratorOfListOfNamedShape it(ArgsF);
-    TopTools_MapOfShape MS; 
+    TNaming_ListIteratorOfListOfNamedShape anIter(ArgsF);
+    TopTools_IndexedMapOfShape MS; 
     TDF_LabelMap        Forbiden;
   
     TNaming_NamingTool::BuildDescendants (Stop, Forbiden);//fill Forbidden
-    TNaming_NamingTool::CurrentShape  (Valid, Forbiden,it.Value(),MS); // fill MS with last modifications of the first additional argument
+    TNaming_NamingTool::CurrentShape  (Valid, Forbiden, anIter.Value(),MS); // fill MS with last modifications of the first additional argument
     TopoDS_Shape  CS = MakeShape(MS);
 
     TNaming_ShapesSet aSet(CS,TopAbs_FACE);//fill internal map of shapeset by shapes of the specified type
-#ifdef MDTV_DEB_SHELL
+#ifdef OCCT_DEBUG_SHELL
     TCollection_AsciiString entry; 
-    TDF_Tool::Entry(it.Value()->Label(), entry);
+    TDF_Tool::Entry(anIter.Value()->Label(), entry);
     TCollection_AsciiString Nam("Arg_");
     TCollection_AsciiString aNam = Nam + entry + "_" + "2.brep";
     DbgTools_Write(CS, aNam.ToCString());
     Standard_Integer ii = 2;
 #endif
-    it.Next();
-    for (; it.More(); it.Next()) {
-#ifdef MDTV_DEB_SHELL 
-      TDF_Tool::Entry(it.Value()->Label(), entry);
+    anIter.Next();
+    for (; anIter.More(); anIter.Next()) {
+#ifdef OCCT_DEBUG_SHELL 
+      TDF_Tool::Entry(anIter.Value()->Label(), entry);
 #endif
       MS.Clear();
-      TNaming_NamingTool::CurrentShape (Valid, Forbiden,it.Value(),MS);// fill MS with last modifications of the it.Value()
+      TNaming_NamingTool::CurrentShape (Valid, Forbiden,anIter.Value(),MS);// fill MS with last modifications of the it.Value()
       CS = MakeShape(MS); 
       TNaming_ShapesSet OS(CS,TopAbs_FACE);
       aSet.Add(OS); //concatenate both shapesets
  
-#ifdef MDTV_DEB_SHELL
+#ifdef OCCT_DEBUG_SHELL
       ii++;
       TCollection_AsciiString aNm = Nam + entry + "_" + ii + ".brep";
       DbgTools_Write(CS, aNm.ToCString());
@@ -1976,8 +1927,8 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
 #endif
        }
 
-#ifdef MDTV_DEB_SHELL
-    cout <<"SHELLIN: " << " Internal Map ext = " << aSet.Map().Extent()<<endl;
+#ifdef OCCT_DEBUG_SHELL
+    cout <<"SHELLIN:  Internal Map ext = " << aSet.Map().Extent()<<endl;
     TopTools_MapIteratorOfMapOfShape it1 (aSet.Map());
     for (int i=1;it1.More();it1.Next(),i++) {
       cout << "Map("<<i<<"): TShape = " << it1.Key().TShape() << " Orient = " << it1.Key().Orientation() <<" Type = " <<
@@ -1994,7 +1945,7 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
   for (TopoDS_Iterator itS(aCSO); itS.More(); itS.Next()) {// find the expected shell in the solid
     const TopoDS_Shape& S = itS.Value();//shell
        if(!S.IsNull()) {
-#ifdef MDTV_DEB_SHELL    
+#ifdef OCCT_DEBUG_SHELL    
       DbgTools_Write(S, "ShellIN_S.brep");
       cout <<"SHELLIN: ShapeType = " << S.ShapeType() << " TS = " << S.TShape()->This() <<endl;
 #endif       
@@ -2038,7 +1989,7 @@ static Standard_Boolean ShellIN(const TDF_Label&                L,
   }
   return aResult;
 }
-#ifdef DEB
+#ifdef OCCT_DEBUG
 //=======================================================================
 static  Standard_CString NameTypeToString (const TNaming_NameType Type)
 {
@@ -2070,10 +2021,11 @@ Standard_Boolean TNaming_Name::Solve(const TDF_Label&    aLab,
                                     const TDF_LabelMap& Valid) const
 {
   Standard_Boolean Done = 0;
-#ifdef MDTV_DEB_WIN
+#ifdef OCCT_DEBUG_WIN
   PrintEntry(aLab);
 #endif
   try {
+  OCC_CATCH_SIGNALS
   switch (myType) {
   case TNaming_UNKNOWN :
     {
@@ -2127,7 +2079,7 @@ Standard_Boolean TNaming_Name::Solve(const TDF_Label&    aLab,
     }
   case TNaming_WIREIN: 
     {
-#ifdef MDTV_DEB_WIN  
+#ifdef OCCT_DEBUG_WIN  
       cout << "Name::Solve: NameType = " << myType << "  ";
   PrintEntry(aLab);
 #endif
@@ -2136,7 +2088,7 @@ Standard_Boolean TNaming_Name::Solve(const TDF_Label&    aLab,
     }
 case TNaming_SHELLIN: 
     {
-#ifdef MDTV_DEB_SHELL
+#ifdef OCCT_DEBUG_SHELL
       cout << "Name::Solve: NameType = " << myType << "  ";
       PrintEntry(aLab);
 #endif
@@ -2144,8 +2096,8 @@ case TNaming_SHELLIN:
       break;
     }
   }
-} catch (...) {
-#ifdef DEB  
+} catch (Standard_Failure) {
+#ifdef OCCT_DEBUG
   cout << "Name::Solve: EXCEPTION==> NameType = " << NameTypeToString(myType) << "  ";
   PrintEntry(aLab);
 #endif