0023748: Bad monitoring of intermediate results in offset commands
[occt.git] / src / BRepFill / BRepFill_OffsetWire.cxx
index 4a8fca1..7c6c8bf 100755 (executable)
@@ -1,7 +1,23 @@
-// File:       BRepFill_OffsetWire.cxx
-// Created:    Thu Apr 20 10:33:55 1995
-// Author:     Bruno DUMORTIER
-//             <dub@fuegox>
+// Created on: 1995-04-20
+// Created by: Bruno DUMORTIER
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
 
 //  Modified by skv - Fri Jul  8 11:21:38 2005 OCC9145
 
@@ -16,7 +32,6 @@
 #include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
 #include <BRepFill_DataMapOfShapeSequenceOfReal.hxx> 
 #include <BRepFill_DataMapOfOrientedShapeListOfShape.hxx> 
-#include <BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape.hxx>
 #include <BRepFill_TrimEdgeTool.hxx>
 #include <BRepLib.hxx>
 #include <BRepLib_MakeVertex.hxx>
@@ -202,16 +217,36 @@ static void MakeCircle
  const TopoDS_Vertex&                        V, 
  const TopoDS_Face&                          F,
  const Standard_Real                         Offset, 
- BRepFill_DataMapOfOrientedShapeListOfShape& Map,
+ BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
  const Handle(Geom_Plane)&                   RefPlane);
 
 static void MakeOffset 
 (const TopoDS_Edge&                          E,
  const TopoDS_Face&                          F,
  const Standard_Real                         Offset, 
- BRepFill_DataMapOfOrientedShapeListOfShape& Map,
+ BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
  const Handle(Geom_Plane)&                   RefPlane);
 
+
+
+//=======================================================================
+//function : CheckFace
+//purpose  : Check if face contains an edge with C0 continuity
+//=======================================================================
+//
+static void CheckFace(const TopoDS_Face& theFace)
+  {
+  TopExp_Explorer ex(theFace,TopAbs_EDGE);
+  for(; ex.More(); ex.Next())
+    {
+    TopoDS_Edge anEdge=TopoDS::Edge(ex.Current());
+    Standard_Real f,l;
+    const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(anEdge,theFace,f,l);
+    if (C->Continuity() == GeomAbs_C0)
+      Standard_ConstructionError::Raise("Initial shape contains an edge with C0 continuity");
+    }
+  }
+
 //=======================================================================
 //function : KPartCircle
 //purpose  : 
@@ -222,10 +257,10 @@ static Standard_Boolean KPartCircle
  const Standard_Real myOffset,
  const Standard_Real Alt,
  TopoDS_Shape&       myShape, 
- BRepFill_DataMapOfOrientedShapeListOfShape& myMap,
+ BRepFill_IndexedDataMapOfOrientedShapeListOfShape& myMap,
  Standard_Boolean&    myIsDone)
 {
-  // Un seul contour qui est un cercle ferme
+  // The only contour which is a closed circle
   TopExp_Explorer exp(mySpine,TopAbs_EDGE);
   Standard_Integer NbEdges = 0;
   TopoDS_Edge      E;
@@ -271,7 +306,7 @@ static Standard_Boolean KPartCircle
     
     TopTools_ListOfShape LL;
     LL.Append(myShape);
-    myMap.Bind(E,LL);
+    myMap.Add(E,LL);
   }
   myIsDone = Standard_True;
   return Standard_True;
@@ -299,7 +334,6 @@ BRepFill_OffsetWire::BRepFill_OffsetWire(const TopoDS_Face&     Spine,
   Init(Spine,Join);
 }
 
-
 //=======================================================================
 //function : Init
 //purpose  : 
@@ -317,10 +351,12 @@ void BRepFill_OffsetWire::Init(const TopoDS_Face&     Spine,
 //  mySpine    = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
   myJoinType = Join;
 
+  CheckFace(mySpine);
+  
   myMap.Clear();
   myMapSpine.Clear();
   //------------------------------------------------------------------
-  // decoupe du spine pour les lieux bissecteurs.
+  // cut the spine for bissectors.
   //------------------------------------------------------------------
 //  Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
   static BRepMAT2d_Explorer Exp;
@@ -334,14 +370,14 @@ void BRepFill_OffsetWire::Init(const TopoDS_Face&     Spine,
 
 //  Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 End
   TopoDS_Shape aShape;
-  BRepFill_DataMapOfOrientedShapeListOfShape aMap;
+  BRepFill_IndexedDataMapOfOrientedShapeListOfShape aMap;
   Standard_Boolean Done;
   if (KPartCircle(myWorkSpine,1.,0.,aShape,aMap,Done)) return;
   
 
   //-----------------------------------------------------
-  // Calcul de la carte des lieux bissecteurs a gauche.  
-  // et des Liens Topologie -> elements de base de la carte.
+  // Calculate the map of bissectors to the left.  
+  // and Links Topology -> base elements of the map.
   //-----------------------------------------------------
   
 //  Modified by Sergey KHROMOV - Tue Nov 26 17:39:03 2002 Begin
@@ -396,27 +432,39 @@ const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
 {  
   if (!myCallGen) {
     if (!myMapSpine.IsEmpty()) {
-      // myMapSpine peut etre vide si on est passe par PerformWithBilo.
+      // myMapSpine can be empty if passed by PerformWithBilo.
       TopTools_DataMapIteratorOfDataMapOfShapeShape it(myMapSpine);
       for (; it.More(); it.Next()) {
-        if (myMap.IsBound(it.Key())) {
-          if (!myMap.IsBound(it.Value())) {
+        if (myMap.Contains(it.Key())) {
+          if (!myMap.Contains(it.Value())) {
             TopTools_ListOfShape L;
-            myMap.Bind(it.Value(),L);
+            myMap.Add(it.Value(),L);
           }
           if ( !it.Value().IsSame(it.Key())) {
-            myMap(it.Value()).Append(myMap(it.Key()));
-            myMap.UnBind(it.Key());
+            myMap.ChangeFromKey(it.Value()).Append(myMap.ChangeFromKey(it.Key()));
+            //myMap.UnBind(it.Key());
+            TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
+            TopTools_ListOfShape LastList;
+            LastList.Append(myMap(myMap.Extent()));
+            myMap.RemoveLast();
+            if (myMap.FindIndex(it.Key()) != 0)
+              myMap.Substitute(myMap.FindIndex(it.Key()), LastShape, LastList);
           }
         }
-        if (myMap.IsBound(it.Key().Reversed())) {
-          if (!myMap.IsBound(it.Value().Reversed())) {
+        if (myMap.Contains(it.Key().Reversed())) {
+          if (!myMap.Contains(it.Value().Reversed())) {
             TopTools_ListOfShape L;
-            myMap.Bind(it.Value().Reversed(),L);
+            myMap.Add(it.Value().Reversed(),L);
           }
           if ( !it.Value().IsSame(it.Key())) {
-            myMap(it.Value().Reversed()).Append(myMap(it.Key().Reversed()));
-            myMap.UnBind(it.Key().Reversed());
+            myMap.ChangeFromKey(it.Value().Reversed()).Append(myMap.ChangeFromKey(it.Key().Reversed()));
+            //myMap.UnBind(it.Key().Reversed());
+            TopoDS_Shape LastShape = myMap.FindKey(myMap.Extent());
+            TopTools_ListOfShape LastList;
+            LastList.Append(myMap(myMap.Extent()));
+            myMap.RemoveLast();
+            if (myMap.FindIndex(it.Key().Reversed()) != 0)
+              myMap.Substitute(myMap.FindIndex(it.Key().Reversed()), LastShape, LastList);
           }
         }
       }
@@ -424,8 +472,8 @@ const TopTools_ListOfShape& BRepFill_OffsetWire::GeneratedShapes
     myCallGen = Standard_True;
   }
   
-  if (myMap.IsBound(SpineShape)) {
-    return myMap(SpineShape);
+  if (myMap.Contains(SpineShape)) {
+    return myMap.FindFromKey(SpineShape);
   }
   else {
     static TopTools_ListOfShape Empty;
@@ -561,6 +609,14 @@ void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
        BRepMAT2d_BisectingLocus newBilo;
        BRepMAT2d_LinkTopoBilo newLink;
        newBilo.Compute(newExp,1,MAT_Left);
+
+  if(!newBilo.IsDone())
+    {
+    myShape.Nullify();
+    myIsDone = Standard_False;
+    return;
+    }
+
        newLink.Perform(newExp,newBilo);
        PerformWithBiLo(myWorkSpine,Offset,newBilo,newLink,myJoinType,Alt);
 
@@ -575,12 +631,18 @@ void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
       PerformWithBiLo(myWorkSpine,Offset,myBilo,myLink,myJoinType,Alt);
     }
 
-  } catch (Standard_Failure) {
+  }
+  catch (...)//Every exception was caught.
+    {
     myShape.Nullify();
     myIsDone = Standard_False;
-
+    cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
+    Standard_Failure::Caught()->Print(cout);
+    cout<<endl;
+    
     return;
   }
+
 //  Modified by skv - Fri Jul  8 11:21:38 2005 OCC9145 End
 //  Modified by Sergey KHROMOV - Thu Mar 14 10:48:15 2002 Begin
   TopExp_Explorer anExp(myShape, TopAbs_WIRE);
@@ -604,7 +666,7 @@ void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
 
 void Compute (const TopoDS_Face&  Spine,
                    TopoDS_Shape& aShape,
-                   BRepFill_DataMapOfOrientedShapeListOfShape& Map,
+                   BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
              const Standard_Real Alt)
 {
   BRep_Builder B;
@@ -621,13 +683,13 @@ void Compute (const TopoDS_Face&  Spine,
     TopoDS_Wire        NewW = TopoDS::Wire(aLocalShape);
 //    TopoDS_Wire        NewW = TopoDS::Wire(CurW.Moved(L));
     B.Add(aShape,NewW);
-    // mise a jour de la Map.
+    // update Map.
     TopoDS_Iterator it1( CurW);
     TopoDS_Iterator it2( NewW);
     for ( ; it1.More(); it1.Next(), it2.Next()) {
       TopTools_ListOfShape List;
       List.Append(it2.Value());
-      Map.Bind(it1.Value(), List);
+      Map.Add(it1.Value(), List);
     }
   }
 }
@@ -664,32 +726,28 @@ void BRepFill_OffsetWire::PerformWithBiLo
 }
   myMap.Clear();
 
-  //*****************************************
-  // si myOffset = 0, on ne s'emmerde pas !!
-  //*****************************************
   if ( Abs(myOffset) < Precision::Confusion()) {
     Compute(mySpine,myShape,myMap,Alt);
     myIsDone = Standard_True;
     return;
   }
 
-  //******************************
-  // Calcul pour un offset non nul 
-  //******************************
+  //********************************
+  // Calculate for a non null offset 
+  //********************************
   if (KPartCircle(mySpine,Offset,Alt,myShape,myMap,myIsDone)) return;
 
   BRep_Builder myBuilder;
   myBuilder.MakeCompound(TopoDS::Compound(myShape));
   
   //---------------------------------------------------------------------
-  // MapNodeVertex : associe a chaque noeud de la carte (key1) et
-  //                 a chaque element du profil (key2) un vertex (item).
-  // MapBis        : ensemble des edges ou vertex (item) generes par
-  //                 une bisectrice sur une face ou un edge (key)des 
-  //                 tuyaux ou revol.
-  // MapVerPar     : Map des parametres des vertex sur les edges paralleles 
-  //                 la liste contenue dans MapVerPar (E) correspond aux 
-  //                 parametres sur E des vertex contenu dans  MapBis(E);
+  // MapNodeVertex : associate to each node of the map (key1) and to
+  //                 each element of the profile (key2) a vertex (item).
+  // MapBis        : all edges or vertices (item) generated by 
+  //                 a bisectrice on a face or an edge (key) of revolution tubes.
+  // MapVerPar     : Map of parameters of vertices on parallel edges 
+  //                 the list contained in MapVerPar (E) corresponds to 
+  //                 parameters on E of vertices contained in MapBis(E);
   //---------------------------------------------------------------------
 
 
@@ -710,7 +768,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
     (RefPlane->Translated( ALT * gp_Vec(RefPlane->Axis().Direction() )));
 
   //---------------------------------------------------------------
-  // Construction des Cercles et des OffsetCurves
+  // Construction of Circles and OffsetCurves
   //---------------------------------------------------------------
  
   for (Standard_Integer ic = 1; ic <= Locus.NumberOfContours(); ic++) {
@@ -732,13 +790,13 @@ void BRepFill_OffsetWire::PerformWithBiLo
 
 #ifdef DEB
   if (AffichEdge) {
-    cout << " Fin Construction des primitives geometriques"<<endl;
+    cout << " End Construction of geometric primitives "<<endl;
   }
 #endif
 
 
   //---------------------------------------------------
-  // Constructions des vertex de l offset.
+  // Construction of offset vertices.
   //---------------------------------------------------
   BRepFill_DataMapOfOrientedShapeListOfShape Detromp;
   Handle(MAT_Arc)        CurrentArc;
@@ -749,7 +807,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
   TopoDS_Shape           S       [2];
   TopoDS_Edge            E       [2];
   TopLoc_Location        L;
-  Standard_Integer       k;
+  Standard_Integer       j, k;
 
   for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
 
@@ -763,9 +821,9 @@ void BRepFill_OffsetWire::PerformWithBiLo
   }
 #endif
 
-    //-----------------------------------------------------------------------
-    // Recuperation des elements du spine correspondant aux basicElts separes.
-    //-----------------------------------------------------------------------
+    //-------------------------------------------------------------------
+    // Return elements of the spine corresponding to separate basicElts.
+    //-------------------------------------------------------------------
     S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
     S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
 
@@ -776,18 +834,18 @@ void BRepFill_OffsetWire::PerformWithBiLo
     BRepFill_DataMapOfShapeSequenceOfPnt   MapSeqPar;
 
     //-----------------------------------------------------------
-    // Recuperation des edges paralleles sur chaque face.
-    // Si pas d offset generees => saut a la bissectrice suivante. 
+    // Return parallel edges on each face.
+    // If no offset generated => move to the next bissectrice. 
     //--------------------------------------------------------------
-    if (myMap.IsBound(S[0]) && myMap.IsBound(S[1])) {
-      E [0] = TopoDS::Edge(myMap(S[0]).First());
-      E [1] = TopoDS::Edge(myMap(S[1]).First());
+    if (myMap.Contains(S[0]) && myMap.Contains(S[1])) {
+      E [0] = TopoDS::Edge(myMap.FindFromKey(S[0]).First());
+      E [1] = TopoDS::Edge(myMap.FindFromKey(S[1]).First());
     }
     else continue;
 
     //-----------------------------------------------------------
-    // Construction des vertex correspondant au noeud de la carte.
-    // si ils sont sur l offset.
+    // Construction of vertices corresponding to the node of the map.
+    // if they are on the offset.
     //-----------------------------------------------------------
     TopoDS_Vertex VS,VE;
     Handle(MAT_Node) Node1, Node2;
@@ -817,7 +875,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
     }
 
     //---------------------------------------------
-    // Construction des geometries.
+    // Construction of geometries.
     //---------------------------------------------
     BRepFill_TrimEdgeTool Trim (Bisec, 
                                Locus.GeomElt(CurrentArc->FirstElement()),
@@ -825,7 +883,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
                                myOffset);
 
     //-----------------------------------------------------------
-    // Construction des vertex sur les edges paralleles au spine.
+    // Construction of vertices on edges parallel to the spine.
     //-----------------------------------------------------------
 
     Trim.IntersectWith(E [0], E [1], Params);
@@ -846,7 +904,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
         Vertices.SetValue(1,VS);
       
       else
-       // le point n avait pas ete trouve par IntersectWith
+       // the point was not found by IntersectWith
        Vertices.Prepend(VS);
     }
     if (EndOnEdge) {     
@@ -856,17 +914,17 @@ void BRepFill_OffsetWire::PerformWithBiLo
         Vertices.SetValue(Params.Length(),VE);
       
       else
-       // le point n avait pas ete trouve par IntersectWith
+       // the point was not found by IntersectWith
        Vertices.Append(VE);
     }
 
     //------------------------------------------------------------
-    // Mise a jour Detromp.
-    // Detromp permetra  de supprimer les vertex sur l offset 
-    // correspondant a des zones de tangences
-    // dans Detromp sont ranges les vertex qui limitent
-    // les portions de la bissectrices situes entre le spine et 
-    // offset.
+    // Update Detromp.
+    // Detromp allows to remove vertices on the offset 
+    // corresponding to tangency zones
+    // Detromp ranks the vertices that limit
+    // the parts of the bissectrices located between the spine and the 
+    // offset.
     //------------------------------------------------------------
     if (!Detromp.IsBound(S[0])) Detromp.Bind(S[0],EmptyList);
     if (!Detromp.IsBound(S[1])) Detromp.Bind(S[1],EmptyList);
@@ -875,8 +933,8 @@ void BRepFill_OffsetWire::PerformWithBiLo
     UpdateDetromp (Detromp(S[0]), Detromp(S[1]), Vertices, Params, 
                   Bisec, StartOnEdge, EndOnEdge, Trim);
     //----------------------------------------------
-    // Stockage des vertex sur les edges paralleles.
-    // on remplit MapBis et MapVerPar.
+    // Storage of vertices on parallel edges.
+    // fill MapBis and MapVerPar.
     //----------------------------------------------
     if (!Vertices.IsEmpty()) {
       for (k = 0; k <= 1; k++) {
@@ -893,11 +951,10 @@ void BRepFill_OffsetWire::PerformWithBiLo
     }
     else {
       //------------------------------------------------------------
-      //POUR LES CERCLES COMPLETS . la parallele peut etre contenue
-      // dans la zone sans intersection avec la frontiere
-      // pas d intersection 
-      // si myoffset est < distance des noeuds la parallele peut etre
-      // valide.
+      // FOR COMPLETE CIRCLES. the parallel line can be contained
+      // in the zone without intersection with the border
+      // no intersection 
+      // if myoffset is < distance of nodes the parallel can be valid.
       //-------------------------------------------------------------
       for (k = 0; k <= 1; k++) {
        if (!MapBis.IsBound(E[k])) {
@@ -912,24 +969,24 @@ void BRepFill_OffsetWire::PerformWithBiLo
   
 #ifdef DEB 
   if (AffichEdge) {
-    cout << " Fin Construction des vertex sur les offsets"<<endl;
+    cout << " End Construction of vertices on offsets"<<endl;
   }
 #endif
 
   //----------------------------------
-  // Construction des edges paralleles.
+  // Construction of parallel edges.
   //----------------------------------
   TopTools_IndexedDataMapOfShapeShape MapVV;
 
   TopoDS_Shape CurrentSpine;
 
-  BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;  
+  //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite1;  
 
-  for (ite1.Initialize(myMap); ite1.More(); ite1.Next()) {
-    CurrentSpine = ite1.Key();
-    CurrentEdge  = TopoDS::Edge(myMap(CurrentSpine).First());
+  for (j = 1; j <= myMap.Extent(); j++) {
+    CurrentSpine = myMap.FindKey(j);
+    CurrentEdge  = TopoDS::Edge(myMap(j).First());
 
-    myMap(CurrentSpine).Clear();
+    myMap(j).Clear();
     if (MapBis.IsBound(CurrentEdge)) {
       TopTools_SequenceOfShape S;
       if (!MapBis(CurrentEdge).IsEmpty()) {
@@ -939,14 +996,14 @@ void BRepFill_OffsetWire::PerformWithBiLo
                  MapVerPar(CurrentEdge) ,
                  S, MapVV);
        for ( k = 1; k <= S.Length(); k++) {
-         myMap(CurrentSpine).Append(S.Value(k));
+         myMap(j).Append(S.Value(k));
        }
       }
       else {
        //-----------------
-       // Cercles complets
+       // Complete circles
        //-----------------
-       myMap(CurrentSpine).Append(CurrentEdge);
+       myMap(j).Append(CurrentEdge);
       }
     }
   }
@@ -963,27 +1020,29 @@ void BRepFill_OffsetWire::PerformWithBiLo
       LV.Append( NewV.Oriented(TopAbs_FORWARD) );
       BRepTools_Substitution aSubst;
       aSubst.Substitute( OldV, LV );
-      for (ite1.Initialize(myMap); ite1.More(); ite1.Next())
+      for (j = 1; j <= myMap.Extent(); j++)
        {
-         TopTools_ListIteratorOfListOfShape itl(ite1.Value());
+         TopTools_ListIteratorOfListOfShape itl(myMap(j));
          for (; itl.More(); itl.Next())
            {
              aSubst.Build(itl.Value());
              if (aSubst.IsCopied(itl.Value()))
                {
                  const TopTools_ListOfShape& listSh = aSubst.Copy(itl.Value());
+                  TopAbs_Orientation SaveOr = itl.Value().Orientation();
                  itl.Value() = listSh.First();
+                  itl.Value().Orientation(SaveOr);
                }
            }
        }
     }
       
   //----------------------------------
-  // Constructions des wires offset.
+  // Construction of offset wires.
   //----------------------------------
   MakeWires ();
 
-  // Mise a jour des vertex ( Construits dans le plan Z = 0) !!!
+  // Update vertices ( Constructed in the plane Z = 0) !!!
   TopTools_MapOfShape MapVertex;
   for ( TopExp_Explorer exp(myShape,TopAbs_VERTEX); exp.More(); exp.Next()) {
     TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
@@ -994,7 +1053,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
     }
   }
 
-  // Constructions des courbes 3d.
+  // Construction of curves 3d.
   BRepLib::BuildCurves3d(myShape);
   MapVertex.Clear();
   TopExp_Explorer Explo( myShape, TopAbs_EDGE );
@@ -1044,7 +1103,7 @@ void BRepFill_OffsetWire::PerformWithBiLo
 //purpose  : 
 //=======================================================================
 
-BRepFill_DataMapOfOrientedShapeListOfShape& 
+BRepFill_IndexedDataMapOfOrientedShapeListOfShape& 
 BRepFill_OffsetWire::Generated() 
 {
   return myMap;
@@ -1096,7 +1155,7 @@ void BRepFill_OffsetWire::PrepareSpine()
       myMapSpine.Bind(V2,V2);
       Cuts.Clear();
 
-      // Decoupe
+      // Cut
       TopoDS_Shape aLocalShape = E.Oriented(TopAbs_FORWARD);
 //  Modified by Sergey KHROMOV - Thu Nov 16 17:29:29 2000 Begin
       if (nbEdges == 2 && nbResEdges == 0)
@@ -1148,37 +1207,38 @@ void BRepFill_OffsetWire::PrepareSpine()
 void BRepFill_OffsetWire::MakeWires()
 {
   //--------------------------------------------------------
-  // creation d une liste unique des edges paralelles crees.
+  // creation of a single list of created parallel edges.
   //--------------------------------------------------------
   TopTools_SequenceOfShape TheEdges;
   TopTools_ListOfShape     TheWires;
   TopTools_ListIteratorOfListOfShape                          itl;
-  BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;  
-  TopTools_DataMapOfShapeListOfShape                          MVE;
-  TopTools_DataMapIteratorOfDataMapOfShapeListOfShape         MVEit;
+  //BRepFill_DataMapIteratorOfDataMapOfOrientedShapeListOfShape ite;  
+  TopTools_IndexedDataMapOfShapeListOfShape                   MVE;
+  //TopTools_DataMapIteratorOfDataMapOfShapeListOfShape         MVEit;
   TopoDS_Vertex V1,V2,VF,CV;
+  Standard_Integer i;
 
-  for (ite.Initialize(myMap); ite.More(); ite.Next()) {    
-    for (itl.Initialize(ite.Value()); itl.More(); itl.Next()) {
+  for (i = 1; i <= myMap.Extent(); i++) {    
+    for (itl.Initialize(myMap(i)); itl.More(); itl.Next()) {
       const TopoDS_Edge& E = TopoDS::Edge(itl.Value());
       TopExp::Vertices (E,V1,V2);
       if (V1.IsSame(V2) && IsSmallClosedEdge(E, V1))
        continue; //remove small closed edges
-      if (!MVE.IsBound(V1)) {
+      if (!MVE.Contains(V1)) {
        TopTools_ListOfShape empty;
-       MVE.Bind(V1,empty);
+       MVE.Add(V1,empty);
       }
-      MVE(V1).Append(E);
-      if (!MVE.IsBound(V2)) {
+      MVE.ChangeFromKey(V1).Append(E);
+      if (!MVE.Contains(V2)) {
        TopTools_ListOfShape empty;
-       MVE.Bind(V2,empty);
+       MVE.Add(V2,empty);
       }
-      MVE(V2).Append(E);
+      MVE.ChangeFromKey(V2).Append(E);
     }
   }
 
   //--------------------------------------
-  // Creation des wires paralleles.
+  // Creation of parallel wires.
   //--------------------------------------
   BRep_Builder B;
 
@@ -1193,17 +1253,19 @@ void BRepFill_OffsetWire::MakeWires()
   while (!MVE.IsEmpty()) {
     B.MakeWire(NW);
 
-    MVEit.Initialize(MVE);
-    for(; MVEit.More(); MVEit.Next()) {
-      if(MVEit.Value().Extent() == 1) break;
-    }
+    //MVEit.Initialize(MVE);
+    for (i = 1; i <= MVE.Extent(); i++)
+      if(MVE(i).Extent() == 1)
+        break;
 
-    if(!MVEit.More()) MVEit.Initialize(MVE);
+    //if(!MVEit.More()) MVEit.Initialize(MVE);
+    if (i > MVE.Extent())
+      i = 1;
     
-    CV  = VF = TopoDS::Vertex(MVEit.Key());
-    CE  = TopoDS::Edge(MVEit.Value().First());
+    CV  = VF = TopoDS::Vertex(MVE.FindKey(i));
+    CE  = TopoDS::Edge(MVE(i).First());
     End = Standard_False;
-    MVE(CV).RemoveFirst(); 
+    MVE.ChangeFromKey(CV).RemoveFirst(); 
 
 //  Modified by Sergey KHROMOV - Thu Mar 14 11:29:59 2002 Begin
     Standard_Boolean isClosed = Standard_False;
@@ -1211,36 +1273,51 @@ void BRepFill_OffsetWire::MakeWires()
 
     while(!End) {      
       //-------------------------------
-      // Construction d un wire.
+      // Construction of a wire.
       //-------------------------------
       TopExp::Vertices(CE,V1,V2);
       if (!CV.IsSame(V1)) CV = V1; else CV = V2;
 
       B.Add (NW,CE);
 
-      if (VF.IsSame(CV) || !MVE.IsBound(CV)) {
+      if (VF.IsSame(CV) || !MVE.Contains(CV)) {
 //  Modified by Sergey KHROMOV - Thu Mar 14 11:30:14 2002 Begin
        isClosed = VF.IsSame(CV);
 //  Modified by Sergey KHROMOV - Thu Mar 14 11:30:15 2002 End
        End = Standard_True;
-       MVE.UnBind(VF);
+       //MVE.UnBind(VF);
+        TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
+        TopTools_ListOfShape LastList;
+        LastList.Append(MVE(MVE.Extent()));
+        MVE.RemoveLast();
+        if (MVE.FindIndex(VF) != 0)
+          MVE.Substitute(MVE.FindIndex(VF), LastShape, LastList);
       }
 
       if (!End) {
-       if (MVE(CV).Extent() > 2) {
-         //cout <<"vertex sur plus de 2 edges dans une face."<<endl;
+       if (MVE.FindFromKey(CV).Extent() > 2) {
+         //cout <<"vertex on more that 2 edges in a face."<<endl;
        }
-       for ( itl.Initialize(MVE(CV)); itl.More(); itl.Next()) {
+       for ( itl.Initialize(MVE.FindFromKey(CV)); itl.More(); itl.Next()) {
          if (itl.Value().IsSame(CE)) {
-           MVE(CV).Remove(itl);
+           MVE.ChangeFromKey(CV).Remove(itl);
            break;
          }
        }
-       if (!MVE(CV).IsEmpty()) {
-         CE = TopoDS::Edge(MVE(CV).First());
-         MVE(CV).RemoveFirst();
+       if (!MVE.FindFromKey(CV).IsEmpty()) {
+         CE = TopoDS::Edge(MVE.FindFromKey(CV).First());
+         MVE.ChangeFromKey(CV).RemoveFirst();
        }
-       if (MVE(CV).IsEmpty()) MVE.UnBind(CV);
+       if (MVE.FindFromKey(CV).IsEmpty())
+        {
+          //MVE.UnBind(CV);
+          TopoDS_Shape LastShape = MVE.FindKey(MVE.Extent());
+          TopTools_ListOfShape LastList;
+          LastList.Append(MVE(MVE.Extent()));
+          MVE.RemoveLast();
+          if (MVE.FindIndex(CV) != 0)
+            MVE.Substitute(MVE.FindIndex(CV), LastShape, LastList);
+        }
       }
     }
 //  Modified by Sergey KHROMOV - Thu Mar 14 11:29:31 2002 Begin
@@ -1250,9 +1327,9 @@ void BRepFill_OffsetWire::MakeWires()
     TheWires.Append(NW);
   }
 
-  // mise a jour de myShape :
-  //      -- si un seul wire    : myShape est un Wire
-  //      -- si plusieurs wires : myShape est un Compound.
+  // update myShape :
+  //      -- if only one wire : myShape is a Wire
+  //      -- if several wires : myShape is a Compound.
   if ( TheWires.Extent() == 1) {
     myShape = TheWires.First();
   }
@@ -1330,6 +1407,8 @@ void BRepFill_OffsetWire::FixHoles()
       TopoDS_Wire& Base = TopoDS::Wire( UnclosedWires(1) );
       TopoDS_Vertex Vf, Vl;
       TopExp::Vertices( Base, Vf, Vl );
+      if(Vf.IsNull() || Vl.IsNull())
+        Standard_Failure::Raise("BRepFill_OffsetWire::FixHoles(): Wrong wire.");
       gp_Pnt Pf, Pl;
       Pf = BRep_Tool::Pnt(Vf);
       Pl = BRep_Tool::Pnt(Vl);
@@ -1541,13 +1620,11 @@ void BRepFill_OffsetWire::FixHoles()
 
 //=======================================================================
 //function : CutEdge
-//purpose  : Decoupe d une edge aux extrema de courbures et aux points
-//           d inflexion.
-//           Les cercles fermes sont aussi decoupes en deux.
-//           Si <Cuts> est vide l edge n est pas modifie.
-//           Le premier et le dernier vertex de l edge originale
-//           appartiennent respectivement a la premiere et derniere
-//           portions.
+//purpose  : Cut edge at the extrema of curvatures and points of inflexion.
+//           So, closed circles are cut in two.
+//           If <Cuts> is empty, the edge is not modified.
+//           The first and the last vertex of the initial edge 
+//           belong to the first and the last parts respectively.
 //=======================================================================
 Standard_Integer CutEdge (const TopoDS_Edge& E, 
                          const TopoDS_Face& F,
@@ -1577,41 +1654,12 @@ Standard_Integer CutEdge (const TopoDS_Edge& E,
   //if (E.Orientation() == TopAbs_REVERSED) CT2d->Reverse();
 
   if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
-      ( Abs(f-l) >= PI) ) {
+      ( Abs(f-l) >= M_PI) ) {
     return 0;
-    //---------------------------
-    // Decoupe cercle ferme.
-    //---------------------------
-    Standard_Real m = (f + l)*0.5;
-//  Modified by Sergey KHROMOV - Wed Mar  6 17:37:28 2002 Begin
-    gp_Pnt        P = aC->Value(m);
-
-    VL = BRepLib_MakeVertex(P);
-    B.UpdateVertex(VL, aTol);
-//  Modified by Sergey KHROMOV - Wed Mar  6 17:37:30 2002 End
-    TopoDS_Shape aLocalShape = E.EmptyCopied();
-    TopoDS_Edge FE = TopoDS::Edge(aLocalShape);  
-    TopoDS_Edge LE = TopoDS::Edge(aLocalShape);  
-//    TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied());    
-//    TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied());
-    FE.Orientation(TopAbs_FORWARD);
-    LE.Orientation(TopAbs_FORWARD);
-    B.Add  (FE,V1);
-    B.Add  (FE,VL.Oriented(TopAbs_REVERSED));
-    B.Range(FE, f, m);    
-    B.Add  (LE,V2);
-    B.Add  (LE,VL.Oriented(TopAbs_FORWARD));
-    B.Range(LE, m, l);
-    Cuts.Append(FE.Oriented(E.Orientation()));
-    Cuts.Append(LE.Oriented(E.Orientation()));
-    //--------
-    // Retour.
-    //--------
-    return 2;
   }
 
   //-------------------------
-  // Decoupe de la courbe.
+  // Cut curve.
   //-------------------------
   Cuter.Perform(CT2d);
 
@@ -1619,7 +1667,7 @@ Standard_Integer CutEdge (const TopoDS_Edge& E,
   if (ForceCut == 0) {
     if (Cuter.UnModified()) {
     //-----------------------------
-    // edge non modifiee => retour.
+    // edge not modified => return.
     //-----------------------------
       return 0;
     } else {
@@ -1656,7 +1704,7 @@ Standard_Integer CutEdge (const TopoDS_Edge& E,
 //  Modified by Sergey KHROMOV - Thu Nov 16 17:28:37 2000 End
 
   //--------------------------------------
-  // Creation des edges decoupees.
+  // Creation of cut edges.
   //--------------------------------------
   VF = V1;
 
@@ -1745,10 +1793,10 @@ void MakeCircle (const TopoDS_Edge&          E,
                 const TopoDS_Vertex&        V,
                 const TopoDS_Face&          F,
                 const Standard_Real         Offset, 
-                      BRepFill_DataMapOfOrientedShapeListOfShape& Map,
+                      BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
                 const Handle(Geom_Plane)&   RefPlane)
 {
-  // eval the Axis of the Circle.
+  // evaluate the Axis of the Circle.
   Standard_Real f,l;
   Handle(Geom2d_Curve) GC = BRep_Tool::CurveOnSurface(E,F,f,l);
   gp_Vec2d DX;
@@ -1769,7 +1817,7 @@ void MakeCircle (const TopoDS_Edge&          E,
   TopTools_ListOfShape LL;
 
   LL.Append(OE);
-  Map.Bind(V,LL);
+  Map.Add(V,LL);
 
 #ifdef DRAW
   if ( AffichGeom && !OE.IsNull()) {
@@ -1787,7 +1835,7 @@ void MakeCircle (const TopoDS_Edge&          E,
 void MakeOffset (const TopoDS_Edge&        E, 
                 const TopoDS_Face&        F,
                 const Standard_Real       Offset, 
-                      BRepFill_DataMapOfOrientedShapeListOfShape& Map,
+                      BRepFill_IndexedDataMapOfOrientedShapeListOfShape& Map,
                 const Handle(Geom_Plane)& RefPlane)
 {
   Standard_Real f,l;
@@ -1800,13 +1848,9 @@ void MakeOffset (const TopoDS_Edge&        E,
 
   Geom2dAdaptor_Curve  AC(G2d,f,l);
   if ( AC.GetType() == GeomAbs_Circle) {
-    // si l offset est superieur ou egal au rayon et du cote de la 
-    // concavite du cercle => edge null.
+    // if the offset is greater otr equal to the radius and the side of the  
+    // concavity of the circle => edge null.
     gp_Circ2d C1(AC.Circle());
-#ifdef DEB
-    Standard_Real radius = 
-#endif
-                           C1.Radius();
     gp_Ax22d axes( C1.Axis());
     gp_Dir2d Xd = axes.XDirection();
     gp_Dir2d Yd = axes.YDirection();
@@ -1814,13 +1858,13 @@ void MakeOffset (const TopoDS_Edge&        E,
     Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
 
     if (anOffset*Signe < AC.Circle().Radius()) {
-      // -anOffset vient d une Etrangete adaptoresque!
+
       Handle(Geom2dAdaptor_HCurve) AHC = 
        new Geom2dAdaptor_HCurve(G2d);
       Adaptor3d_OffsetCurve   Off(AHC,-anOffset);
       Handle(Geom2d_Circle) CC = new Geom2d_Circle(Off.Circle());      
 
-      Standard_Real Delta = 2*PI - l + f;
+      Standard_Real Delta = 2*M_PI - l + f;
       f -= 0.2*Delta; l += 0.2*Delta;
 
       G2dOC = new Geom2d_TrimmedCurve(CC,f,l);
@@ -1849,7 +1893,7 @@ void MakeOffset (const TopoDS_Edge&        E,
     OE.Orientation(E.Orientation());
     TopTools_ListOfShape LL;
     LL.Append(OE);
-    Map.Bind(E,LL);
+    Map.Add(E,LL);
 
 #ifdef DRAW  
     if (AffichGeom && !OE.IsNull()) {
@@ -1864,12 +1908,12 @@ void MakeOffset (const TopoDS_Edge&        E,
 
 //=======================================================================
 //function : UpdateDetromp
-//purpose  : Pour chaque interval sur la bissectrice defini par params
-//           test si le point milieu est a une distance > offset       
-//           dans ce cas les vertex correspondants aux extremites de l interval
-//           sont ranges dans le detrompeur.
-//           => Si un meme vertex apparait deux fois dans le detrompeur la 
-//           frontiere de la zone de proximitee est tangente a l offset .
+//purpose  : For each interval on bissectrice defined by parameters
+//           test if the medium point is at a distance > offset        
+//           in this case vertices corresponding to the extremities of the interval
+//           are ranked in the proofing.
+//           => If the same vertex appears in the proofing, the 
+//           border of the zone of proximity is tangent to the offset .
 //=======================================================================
 
 void UpdateDetromp (TopTools_ListOfShape&           Detromp1,
@@ -1890,7 +1934,7 @@ void UpdateDetromp (TopTools_ListOfShape&           Detromp1,
   U1 = Bis->FirstParameter();
   
   if (SOnE) { 
-    // le premier point de la bissectrice est sur l offset
+    // the first point of the bissectrice is on the offset
     V1 = TopoDS::Vertex(Vertices.Value(ii));
     ii++; 
   }
@@ -1913,7 +1957,7 @@ void UpdateDetromp (TopTools_ListOfShape&           Detromp1,
     ii ++;
   }
 
-  // test point milieu entre le dernier params et la fin de la bissectrice.
+  // test medium point between the last parameter and the end of the bissectrice.
   U2 = Bis->LastParameter();
   if (!EOnE) {
     if (!Precision::IsInfinite(U2)) {
@@ -1951,7 +1995,7 @@ Standard_Boolean VertexFromNode (const Handle(MAT_Node)&      aNode,
 
   if (!aNode->Infinite() && Abs(aNode->Distance()-Offset) < Tol) {
     //------------------------------------------------
-    // le Noeud donne un vertex sur l offset
+    // the Node gives a vertex on the offset
     //------------------------------------------------
     if (MapNodeVertex.IsBound(aNode)) {
       VN = TopoDS::Vertex(MapNodeVertex(aNode));
@@ -2012,7 +2056,7 @@ void TrimEdge (const TopoDS_Edge&              E,
   S.Clear();
 
   //-----------------------------------------------------------
-  // Tri des deux sequences en fonction du parametre sur l edge.
+  // Parse two sequences depending on the parameter on the edge.
   //-----------------------------------------------------------
   while (Change) {
     Change = Standard_False;
@@ -2026,7 +2070,7 @@ void TrimEdge (const TopoDS_Edge&              E,
   }
 
   //----------------------------------------------------------
-  // Si un vertex n est pas dans le detrompeur il est elimine.
+  // If a vertex is not in the proofing, it is eliminated.
   //----------------------------------------------------------
   if (!BRep_Tool::Degenerated(E)) {
     for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
@@ -2040,9 +2084,9 @@ void TrimEdge (const TopoDS_Edge&              E,
   }
 
   //----------------------------------------------------------
-  // Si un vertex_double apparait deux fois dans le detrompeur
-  // le vertex est elimine .
-  // sinon on garde une seule de ces representations.
+  // If a vertex_double appears twice in the proofing 
+  // the vertex is removed.
+  // otherwise preserve only one of its representations.
   //----------------------------------------------------------
   if (!BRep_Tool::Degenerated(E)) {
     for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
@@ -2072,9 +2116,9 @@ void TrimEdge (const TopoDS_Edge&              E,
     }
   }
   //-----------------------------------------------------------
-  // Creation des edges.
-  // le nombre de vertex doit etre pair les edges a creer vont 
-  // d un vertex d indice impair i au vertex i+1;
+  // Creation of edges.
+  // the number of vertices should be even. The created edges  
+  // go from a vertex with uneven index i to vertex i+1;
   //-----------------------------------------------------------
   for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
     TopoDS_Shape aLocalShape = E.EmptyCopied();
@@ -2119,7 +2163,7 @@ void TrimEdge (const TopoDS_Edge&              E,
 
 //=======================================================================
 //function : DoubleOrNotInside
-//purpose  : return True si V apparait 2 fois dans LV ou n est pas dedans.
+//purpose  : return True if V appears twice in LV or is not inside.
 //=======================================================================
 
 Standard_Boolean DoubleOrNotInside (const TopTools_ListOfShape& LV,
@@ -2338,7 +2382,7 @@ static void QuasiFleche(const Adaptor3d_Curve& C,
   Standard_Real theFleche=0;
   Standard_Boolean flecheok = Standard_False;
   if (Norme > Eps) { 
-    // Evaluation de la fleche par interpolation . Voir IntWalk_IWalking_5.gxx
+    // Evaluation of the arrow by interpolation. See IntWalk_IWalking_5.gxx
     Standard_Real N1 = Vdeb.SquareMagnitude();
     Standard_Real N2 = Vdelta.SquareMagnitude();
     if (N1 > Eps && N2 > Eps) {
@@ -2381,4 +2425,4 @@ static void QuasiFleche(const Adaptor3d_Curve& C,
                Parameters,Points);
   }
 }
-                       
+