0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / TNaming / TNaming_NamedShape.cxx
old mode 100755 (executable)
new mode 100644 (file)
index d5db2a2..d09714f
@@ -1,51 +1,64 @@
-// File:       TNaming_NamedShape.cxx
-// Created:    Wed Dec 18 10:41:48 1996
-// Author:     Yves FRICAUD
-//             <yfr@claquox.paris1.matra-dtv.fr>
+// Created on: 1996-12-18
+// Created by: Yves FRICAUD
+// Copyright (c) 1996-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 
-
-#include <TNaming_NamedShape.ixx>
-#include <TNaming_Builder.ixx>
-
-#include <TDF_Label.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <gp_Pnt.hxx>
+#include <Standard.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_GUID.hxx>
+#include <Standard_NoMoreObject.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <Standard_NullObject.hxx>
+#include <Standard_Type.hxx>
+#include <TDF_Attribute.hxx>
+#include <TDF_AttributeDelta.hxx>
+#include <TDF_AttributeIterator.hxx>
 #include <TDF_Data.hxx>
+#include <TDF_DataSet.hxx>
 #include <TDF_DeltaOnAddition.hxx>
-#include <TDF_AttributeIterator.hxx>
-#include <TNaming_PtrNode.hxx>
-#include <TNaming_PtrRefShape.hxx>
-#include <TNaming_RefShape.hxx>
-#include <TNaming_PtrDataMapOfShapePtrRefShape.hxx>
-#include <TNaming_UsedShapes.hxx>
-#include <TNaming_Tool.hxx>
+#include <TDF_DeltaOnModification.hxx>
+#include <TDF_DeltaOnRemoval.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_RelocationTable.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_CopyShape.hxx>
+#include <TNaming_DeltaOnModification.hxx>
+#include <TNaming_DeltaOnRemoval.hxx>
 #include <TNaming_Iterator.hxx>
+#include <TNaming_NamedShape.hxx>
 #include <TNaming_NewShapeIterator.hxx>
 #include <TNaming_OldShapeIterator.hxx>
+#include <TNaming_PtrNode.hxx>
+#include <TNaming_PtrRefShape.hxx>
+#include <TNaming_RefShape.hxx>
 #include <TNaming_SameShapeIterator.hxx>
-
-#include <TNaming_DeltaOnModification.hxx>
-#include <TNaming_DeltaOnRemoval.hxx>
-#include <Standard_NoMoreObject.hxx>
-#include <Standard_NoSuchObject.hxx>
-#include <Standard_ConstructionError.hxx>
-#include <Standard_NullObject.hxx>
-
-#include <gp_Pnt.hxx>
-#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <TNaming_Tool.hxx>
+#include <TNaming_UsedShapes.hxx>
+#include <TopoDS_Shape.hxx>
 #include <TopoDS_Vertex.hxx>
 
-// Defines the nodes classes
-
-#include <Standard.hxx>
-#include <TNaming_CopyShape.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(TNaming_NamedShape,TDF_Attribute)
 
-#define BUC60921   //SRN 15/05/01 : Fixes the memory leak due to pointer to RefShape is not deleted
+// Defines the nodes classes
 //#define MDTV_DEB_HASL
 //=======================================================================
 //function : GetID
 //purpose  : 
 //=======================================================================
-
 const Standard_GUID& TNaming_NamedShape::GetID() 
 {
   static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
@@ -77,23 +90,7 @@ public:
   Standard_Boolean IsValidInTrans(Standard_Integer Trans);
 
   // Memory management
-  void* operator new(size_t aSize) {
-    return Standard::Allocate(aSize);
-  }
-
-/* attempt to eliminate compiler warning  
-  void* operator new(size_t, void* aNode) {
-    return aNode;
-  }
-  
-  void  operator delete(void* aNode) {
-    Standard::Free(aNode);
-  }
-*/
-  
-  void  operator delete(void* aNode, size_t aSize) {
-    Standard::Free(aNode);
-  }
+  DEFINE_STANDARD_ALLOC
   
   TNaming_PtrRefShape  myOld;
   TNaming_PtrRefShape  myNew;
@@ -192,27 +189,29 @@ static void RemoveNode(Standard_Boolean                   MapExist ,
     if (pos->FirstUse() == N) {
       TNaming_Node*  nextOld = N->nextSameOld;
       if (nextOld != 0L) 
-       pos->FirstUse(nextOld);
-      else 
-       // le shape disparait
-       if (MapExist){
-         M.UnBind(pos->Shape());
-#ifdef BUC60921
-         N->myOld = 0L;
-         if(pos != N->myNew)
-           delete pos;
-#endif 
-       }
+        pos->FirstUse(nextOld);
+      else {
+        // le shape disparait
+        if (MapExist)
+          M.UnBind(pos->Shape());
+        N->myOld = 0L;
+        if(pos != N->myNew)
+        {
+          delete pos;
+          pos = 0L;
+        }
+      }
     }
     else {
       TNaming_Node* pdn = pos->FirstUse();
       while (pdn != 0L) {
-       if (pdn->NextSameShape(pos) == N) {
-         if (pdn->myOld == pos) pdn->nextSameOld =  N->nextSameOld;
-         else                   pdn->nextSameNew =  N->nextSameOld;
-         break;
-       }
-       pdn = pdn->NextSameShape(pos);
+        
+        if (pdn->NextSameShape(pos) == N) {
+          if (pdn->myOld == pos) pdn->nextSameOld =  N->nextSameOld;
+          else                   pdn->nextSameNew =  N->nextSameOld;
+          break;
+        }
+        pdn = pdn->NextSameShape(pos);
       }
     }
   }
@@ -222,26 +221,30 @@ static void RemoveNode(Standard_Boolean                   MapExist ,
     if (pns->FirstUse() == N) {
       TNaming_Node*  nextNew = N->nextSameNew;
       if (nextNew != 0L) 
-       pns->FirstUse(nextNew);
+        pns->FirstUse(nextNew);
       else 
-       // le shape disparait
-       if (MapExist) {
-         M.UnBind(pns->Shape());
-#ifdef BUC60921
-         N->myNew = 0L;
-         delete pns;
-#endif 
-       }
+      {
+        // le shape disparait
+        if (MapExist) 
+          M.UnBind(pns->Shape());
+      
+        pns->FirstUse(0L);
+        delete pns;
+        pns = 0L;
+
+        N->myNew = 0L;
+      
+      }
     }
     else {
       TNaming_Node* pdn = pns->FirstUse();
       while (pdn != 0L) {
-       if (pdn->NextSameShape(pns) == N) {
-         if (pdn->myOld == pns) pdn->nextSameOld =  N->nextSameNew;
-         else                   pdn->nextSameNew =  N->nextSameNew;
-         break;
-       }
-       pdn = pdn->NextSameShape(pns);
+        if (pdn->NextSameShape(pns) == N) {
+          if (pdn->myOld == pns) pdn->nextSameOld =  N->nextSameNew;
+          else                   pdn->nextSameNew =  N->nextSameNew;
+          break;
+        }
+        pdn = pdn->NextSameShape(pns);
       }
     }
   }
@@ -255,7 +258,7 @@ static void RemoveNode(Standard_Boolean                   MapExist ,
 void TNaming_NamedShape::Clear()
 {
   if (Label().IsNull()) {
-#ifdef DEB
+#ifdef OCCT_DEBUG_BUILDER
     cout << "attention etat fantomatique" << endl;
 #endif
     return;
@@ -282,8 +285,11 @@ void TNaming_NamedShape::Clear()
   while (p != 0L) {
     q = p;
     p = p->nextSameAttribute;
-    delete q;
-    q = 0L;
+    if( q !=0L)
+    {
+      delete q;
+      q = 0L;
+    }
   }
     
   myNode = 0L;
@@ -347,8 +353,11 @@ Standard_Boolean TNaming_NamedShape::AfterUndo
     while (p != 0L) {
       q = p;
       p = p->nextSameAttribute;
-      delete q;
-      q = 0L;
+      if(q != 0L)
+      {
+        delete q;
+        q = 0L;
+      }
     }
 
     myNode = 0L;
@@ -419,7 +428,7 @@ Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
 (const Handle(TDF_Attribute)& anOldAttribute) const
 {
   
-  return new TNaming_DeltaOnModification(*((Handle(TNaming_NamedShape)*)&anOldAttribute));
+  return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute));
 }
 
 //=======================================================================
@@ -452,28 +461,6 @@ Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const
   return new TNaming_NamedShape();
 }
 
-//=======================================================================
-//function : static GetLocation 23.06.99 (szy)
-//purpose  : service: returns copy of Location if exist Relocation 
-//=======================================================================
-
-static TopLoc_Location GetLocation(const TopLoc_Location& L,
-                                  const Handle(TDF_RelocationTable)& RT)
-{
-  TopLoc_Location result;
-  
-  if (!L.IsIdentity()) {
-    Handle(TopLoc_Datum3D) TD;
-    if(!RT->HasTransientRelocation(L.FirstDatum(), TD))
-#ifdef DEB
-      cout <<"TNaming_Named_Shape::Paste : Relocation for TopLocation don't exist" << endl;
-#endif
-    result = GetLocation(L.NextLocation(), RT) * 
-      TopLoc_Location(TD).Powered(L.FirstPower());
-  }
-  return result;
-}
-
 //=======================================================================
 //function : Paste
 //purpose  : 
@@ -572,7 +559,7 @@ void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
 void TNaming_NamedShape::Add(TNaming_Node*& pdn )
 { 
   pdn->myAtt             = this;
-  if (!myNode == 0L){
+  if (myNode != 0L){
     pdn->nextSameAttribute = myNode;
   }
   myNode = pdn;
@@ -604,28 +591,23 @@ Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
 
 TNaming_Builder::TNaming_Builder (const TDF_Label& L)
 {
-  Handle(TNaming_UsedShapes) Shapes;
-
   // Find or Build Map;
   const TDF_Label& root = L.Root();
-  if (!root.FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Shapes = new TNaming_UsedShapes();
-    root.AddAttribute (Shapes);
+  if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
+    myShapes = new TNaming_UsedShapes();
+    root.AddAttribute (myShapes);
   }
-  myMap = &(Shapes->myMap);
   
   //Find Or Build Attribute in LIns.
-  Handle(TNaming_NamedShape) Att;
-  if (!L.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
-    Att = new TNaming_NamedShape();  
-    L.AddAttribute(Att);
+  if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
+    myAtt = new TNaming_NamedShape();  
+    L.AddAttribute(myAtt);
   }
   else {
-    Att->Backup();
-    Att->Clear();  
-    Att->myVersion++;
+    myAtt->Backup();
+    myAtt->Clear();  
+    myAtt->myVersion++;
   }
-  myAtt = Att.operator->();
 }
 
 //=======================================================================
@@ -684,12 +666,12 @@ void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
   TNaming_RefShape* pos = 0L;
   TNaming_RefShape* pns;
   
-  if (myMap->IsBound(newShape)) {
-#ifdef DEB
+  if (myShapes->myMap.IsBound(newShape)) {
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
 #endif
-    pns = myMap->ChangeFind(newShape);
-    if (pns->FirstUse()->myAtt  == myAtt) {
+    pns = myShapes->myMap.ChangeFind(newShape);
+    if (pns->FirstUse()->myAtt  == myAtt.operator->()) {
       Standard_ConstructionError::Raise("TNaming_Builder::Generate");
     }
     TNaming_Node* pdn = new TNaming_Node(pos,pns);
@@ -700,7 +682,7 @@ void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
     pns = new TNaming_RefShape(newShape);    
     TNaming_Node*     pdn = new TNaming_Node(pos,pns); 
     pns  ->FirstUse(pdn);
-    myMap->Bind    (newShape , pns);
+    myShapes->myMap.Bind (newShape , pns);
     myAtt->Add(pdn);
   }
 }
@@ -723,14 +705,14 @@ void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
   TNaming_RefShape* pns = 0L;
   TNaming_RefShape* pos;
 
-  if (myMap->IsBound(oldShape)) 
-    pos = myMap->ChangeFind(oldShape); 
+  if (myShapes->myMap.IsBound(oldShape)) 
+    pos = myShapes->myMap.ChangeFind(oldShape); 
   else {
-#ifdef DEB
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
 #endif
     pos = new TNaming_RefShape(oldShape);  
-    myMap->Bind(oldShape, pos);
+    myShapes->myMap.Bind(oldShape, pos);
   }
   TNaming_Node*     pdn = new TNaming_Node(pos,pns);   
   myAtt->Add(pdn);
@@ -752,26 +734,26 @@ void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
   }
 
   if (oldShape.IsSame(newShape)) {
-#ifdef DEB
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
 #endif
     return;
   }
   TNaming_RefShape* pos;
-  if (!myMap->IsBound(oldShape)) {
+  if (!myShapes->myMap.IsBound(oldShape)) {
     pos = new TNaming_RefShape(oldShape);
-    myMap->Bind(oldShape,pos);
+    myShapes->myMap.Bind(oldShape,pos);
   }
   else
-    pos = myMap->ChangeFind(oldShape);
+    pos = myShapes->myMap.ChangeFind(oldShape);
   
   TNaming_RefShape* pns;
-  if (!myMap->IsBound(newShape)) {
+  if (!myShapes->myMap.IsBound(newShape)) {
     pns = new TNaming_RefShape(newShape);
-    myMap->Bind(newShape,pns);
+    myShapes->myMap.Bind(newShape,pns);
   }
   else
-    pns = myMap->ChangeFind(newShape);
+    pns = myShapes->myMap.ChangeFind(newShape);
   
   TNaming_Node* pdn = new TNaming_Node(pos,pns);
   myAtt->Add(pdn);
@@ -795,69 +777,26 @@ void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
   }
 
   if (oldShape.IsSame(newShape)) {
-#ifdef DEB
-    cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
-#endif
-    return;
-  }
-  TNaming_RefShape* pos;
-  if (!myMap->IsBound(oldShape)) {
-    pos = new TNaming_RefShape(oldShape);
-    myMap->Bind(oldShape,pos);
-  }
-  else
-    pos = myMap->ChangeFind(oldShape);
-  
-  TNaming_RefShape* pns;
-  if (!myMap->IsBound(newShape)) {
-    pns = new TNaming_RefShape(newShape);
-    myMap->Bind(newShape,pns);
-  }
-  else
-    pns = myMap->ChangeFind(newShape);
-  
-  TNaming_Node* pdn = new TNaming_Node(pos,pns);
-  myAtt->Add(pdn);
-  UpdateFirstUseOrNextSameShape (pos,pdn);
-  UpdateFirstUseOrNextSameShape (pns,pdn);
-  
-}
-
-//=======================================================================
-//function : Modify
-//purpose  : 
-//=======================================================================
-
-void TNaming_Builder::Replace(const TopoDS_Shape& oldShape,
-                             const TopoDS_Shape& newShape) 
-{ 
-  if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_REPLACE;
-  else {
-    if (myAtt->myEvolution != TNaming_REPLACE)
-      Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
-  }
-
-  if (oldShape.IsSame(newShape)) {
-#ifdef DEB
+#ifdef OCCT_DEBUG_BUILDER
     cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
 #endif
     return;
   }
   TNaming_RefShape* pos;
-  if (!myMap->IsBound(oldShape)) {
+  if (!myShapes->myMap.IsBound(oldShape)) {
     pos = new TNaming_RefShape(oldShape);
-    myMap->Bind(oldShape,pos);
+    myShapes->myMap.Bind(oldShape,pos);
   }
   else
-    pos = myMap->ChangeFind(oldShape);
+    pos = myShapes->myMap.ChangeFind(oldShape);
   
   TNaming_RefShape* pns;
-  if (!myMap->IsBound(newShape)) {
+  if (!myShapes->myMap.IsBound(newShape)) {
     pns = new TNaming_RefShape(newShape);
-    myMap->Bind(newShape,pns);
+    myShapes->myMap.Bind(newShape,pns);
   }
   else
-    pns = myMap->ChangeFind(newShape);
+    pns = myShapes->myMap.ChangeFind(newShape);
   
   TNaming_Node* pdn = new TNaming_Node(pos,pns);
   myAtt->Add(pdn);
@@ -866,47 +805,6 @@ void TNaming_Builder::Replace(const TopoDS_Shape& oldShape,
   
 }
 
-//=======================================================================
-static const TopoDS_Shape& DummyShapeToStoreOrientation (const TopAbs_Orientation Or)
-{
-  static TopoDS_Vertex aVForward, aVRev, aVInt, aVExt;
-  switch(Or) {
-  case TopAbs_FORWARD:
-    if(aVForward.IsNull()) {
-      gp_Pnt aPnt(0,0,0);
-      BRepBuilderAPI_MakeVertex aMake(aPnt);
-      aVForward = aMake.Vertex();
-      aVForward.Orientation(TopAbs_FORWARD);
-    }
-    return aVForward;
-  case TopAbs_REVERSED:
-    if(aVRev.IsNull()) {
-      gp_Pnt aPnt(0,0,0);
-      BRepBuilderAPI_MakeVertex aMake(aPnt);
-      aVRev = aMake.Vertex();
-      aVRev.Orientation(TopAbs_REVERSED);
-    }
-    return aVRev;
-  case TopAbs_INTERNAL:
-    if(aVInt.IsNull()) {
-      gp_Pnt aPnt(0,0,0);
-      BRepBuilderAPI_MakeVertex aMake(aPnt);
-      aVInt = aMake.Vertex();
-      aVInt.Orientation(TopAbs_INTERNAL);
-    }
-    return aVInt;
-  case TopAbs_EXTERNAL:
-    if(aVExt.IsNull()) {
-      gp_Pnt aPnt(0,0,0);
-      BRepBuilderAPI_MakeVertex aMake(aPnt);
-      aVExt = aMake.Vertex();
-      aVExt.Orientation(TopAbs_EXTERNAL);
-    }
-    return aVExt;
-  }
-  return aVForward;
-}
-
 //=======================================================================
 //function : Select
 //purpose  : 
@@ -920,31 +818,21 @@ void TNaming_Builder::Select (const TopoDS_Shape& S,
       Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
   }
 
-  TNaming_RefShape* pos;
-  if(S.ShapeType() != TopAbs_VERTEX) {
-    const TopoDS_Shape& aV = DummyShapeToStoreOrientation (S.Orientation());
-    if (!myMap->IsBound(aV)) {
-      pos = new TNaming_RefShape(aV);
-      myMap->Bind(aV,pos);
-    }
-    else
-      pos = myMap->ChangeFind(aV);    
-  } else {
-    if (!myMap->IsBound(InS)) {
-      pos = new TNaming_RefShape(InS);
-      myMap->Bind(InS,pos);
-    }
-    else
-      pos = myMap->ChangeFind(InS);
+  TNaming_RefShape* pos;  
+  if (!myShapes->myMap.IsBound(InS)) {
+    pos = new TNaming_RefShape(InS);
+    myShapes->myMap.Bind(InS,pos);
   }
+  else
+    pos = myShapes->myMap.ChangeFind(InS);
 
   TNaming_RefShape* pns;
-  if (!myMap->IsBound(S)) {
+  if (!myShapes->myMap.IsBound(S)) {
     pns = new TNaming_RefShape(S);
-    myMap->Bind(S,pns);
+    myShapes->myMap.Bind(S,pns);
   }
   else
-    pns = myMap->ChangeFind(S);  
+    pns = myShapes->myMap.ChangeFind(S);  
 
   TNaming_Node* pdn = new TNaming_Node(pos,pns);
   myAtt->Add(pdn);
@@ -993,13 +881,13 @@ TNaming_Iterator::TNaming_Iterator(const TDF_Label&       Lab,
                                   const Standard_Integer Trans)
 :myTrans(Trans)
 {
-  Handle(TNaming_NamedShape) Att;
+  Handle(TDF_Attribute) Att;
   if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
-    myNode = Att->myNode;
+    myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode;
   }
   else {
     myNode = 0L;
-#ifdef DEB
+#ifdef OCCT_DEBUG
     cout <<"TNaming_Iterator : No Shape for this label"<<endl;
 #endif
   }
@@ -1102,16 +990,18 @@ static void SelectSameShape (TNaming_Node*&          myNode,
     else Valid = pdn->IsValidInTrans(Trans);
 
     if (Valid)
+    {
       if (Old) {
-       if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
-         break;
-       }  
+        if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
+          break;
+        }  
       }
       else {
-       if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
-         break;
-       }
+        if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
+          break;
+        }
       }
+    }
     pdn = pdn->NextSameShape(RS);
   }
   myNode = pdn;
@@ -1127,10 +1017,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Standard_Integer            Trans,
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
-{
-  Standard_Boolean  Old = Standard_True;  
-  TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+{ 
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                    "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");  
+  TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);  
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_True); 
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1146,10 +1038,12 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 :myTrans(Trans)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {    
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1162,14 +1056,16 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1184,9 +1080,11 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {
-  Standard_Boolean  Old = Standard_True;  
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+   Standard_Boolean  Old(Standard_True);  
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1202,8 +1100,10 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_True;  
-    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
+    Standard_Boolean  Old(Standard_True);  
+    TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);  
     myNode = RS->FirstUse();
     SelectSameShape(myNode,Old,RS,myTrans);
   }
@@ -1217,7 +1117,8 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator
 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_True;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
   myNode = anIterator.myNode;
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
@@ -1225,6 +1126,7 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_True);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1236,9 +1138,9 @@ TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterato
 
 void TNaming_NewShapeIterator::Next() 
 {
-  Standard_Boolean  Old = Standard_True;
   TNaming_RefShape* RS  = myNode->myOld;
   myNode = myNode->NextSameShape(RS);
+  Standard_Boolean  Old(Standard_True);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1306,9 +1208,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(Trans)
 {
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1325,9 +1229,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 {
   Handle(TNaming_UsedShapes) Shapes;
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
-    Standard_Boolean  Old = Standard_False;
+       Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");    
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1341,9 +1247,11 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
  const Handle(TNaming_UsedShapes)& Shapes)
 :myTrans(-1)
 {  
-  Standard_Boolean  Old = Standard_False;
+  Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                        "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
   TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
   myNode = RS->FirstUse();
+  Standard_Boolean  Old(Standard_False);
   SelectSameShape(myNode,Old,RS,myTrans);
 }
 
@@ -1358,10 +1266,12 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 :myTrans(-1)
 {  
   Handle(TNaming_UsedShapes) Shapes;
-  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {  
-    Standard_Boolean  Old = Standard_False;
+  if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
+    Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape), 
+                                          "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape"); 
     TNaming_RefShape* RS  = Shapes->Map().ChangeFind(aShape);
     myNode = RS->FirstUse();
+       Standard_Boolean  Old(Standard_False);
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1374,14 +1284,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator
 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode; 
   TNaming_RefShape* RS = myNode->myNew;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else {    
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1394,14 +1306,16 @@ TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIt
 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
 :myTrans(anIterator.myTrans)
 {
-  Standard_Boolean Old = Standard_False;  
-  myNode = anIterator.myNode;
+  Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
+                                                "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
+  myNode = anIterator.myNode;  
   TNaming_RefShape* RS = myNode->myOld;
   if (RS == 0L) 
     myNode = 0L;  // No descendant
   else  {
     // il faut repartir de la premiere utilisation.
     myNode = RS->FirstUse();
+       Standard_Boolean Old(Standard_False);  
     SelectSameShape(myNode,Old,RS,myTrans);
   }
 }
@@ -1569,7 +1483,7 @@ Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label&    access,
   if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
     return (US->Map().IsBound(S));
   }
-#ifdef MDTV_DEB_HASL
+#ifdef OCCT_DEBUG_HASL
   cout << "##==> Sub-Shape has no Label!" <<endl;
 #endif
   return Standard_False;
@@ -1706,59 +1620,3 @@ Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape&               S,
   }
   return Until;
 }
-
-//=======================================================================
-//function : OldPaste
-//purpose  : 
-//=======================================================================
-
-void TNaming_NamedShape::OldPaste(const Handle(TDF_Attribute)&       into,
-                                  const Handle(TDF_RelocationTable)& /*Tab*/)
-const
-{ 
-  TDF_Label        Lab = into->Label();
-  if (Lab.IsNull()) {
-    Standard_NullObject::Raise("TNaming_NamedShape::Paste");
-  }
-  //TDF_Insertor Ins(Lab);
-  //TNaming_Builder B(Ins);
-  TNaming_Builder B(Lab);
-
-  TNaming_Iterator It (this);
-  for ( ;It.More() ; It.Next()) {
-    const TopoDS_Shape& OS     = It.OldShape();
-    const TopoDS_Shape& NS     = It.NewShape();
-    TNaming_Evolution   Status = It.Evolution();
-    switch (Status) {
-    case TNaming_PRIMITIVE :
-      {
-       B.Generated(NS);
-       break;
-      }
-    case TNaming_GENERATED :
-      {
-       B.Generated(OS,NS);
-       break;
-      }
-    case TNaming_MODIFY : 
-      {
-       B.Modify(OS,NS);
-       break;
-      }
-    case TNaming_DELETE : 
-      {
-       B.Delete (OS);
-       break;
-      }
-    case TNaming_SELECTED :
-      {
-       B.Select(NS,OS);
-       break;
-      }
-    case TNaming_REPLACE :
-      B.Replace(OS,NS);
-    }
-  }
-}
-