]> OCCT Git - occt-copy.git/commitdiff
Modified files of CR25334, CR25406 for 6.6.0
authorbugmaster <bugmaster@opencascade.com>
Thu, 23 Oct 2014 13:38:58 +0000 (17:38 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 23 Oct 2014 13:38:58 +0000 (17:38 +0400)
src/BRepFill/BRepFill_OffsetWire.cxx
src/BRepOffset/BRepOffset_MakeOffset.cxx
src/BRepOffset/BRepOffset_Offset.cxx
src/MAT/MAT_Mat.cdl
src/MAT/MAT_Mat.gxx
src/MAT2d/MAT2d_BisectingLocus.gxx
src/MAT2d/MAT2d_Circuit.cxx
src/MAT2d/MAT2d_Tool2d.cdl
src/MAT2d/MAT2d_Tool2d.cxx

index 7b6e90fc293cb1c7dec11ca17d68bd828cc4cfe8..d9d96cbcbce2cd48a971c6886b8f806efc43a040 100755 (executable)
@@ -648,9 +648,11 @@ void BRepFill_OffsetWire::Perform (const Standard_Real Offset,
   {
     myShape.Nullify();
     myIsDone = Standard_False;
+#ifdef BREPFILL_DEB
     cout<<"An exception was caught in BRepFill_OffsetWire::Perform : ";
     Standard_Failure::Caught()->Print(cout);
     cout<<endl;
+#endif
 
     return;
   }
@@ -799,8 +801,9 @@ void BRepFill_OffsetWire::PerformWithBiLo
     for (Standard_Integer ie = 1; ie <= Locus.NumberOfElts(ic); ie++) {
       const TopoDS_Shape& SE = Link.GeneratingShape(Locus.BasicElt(ic,ie));
       if (SE.ShapeType() == TopAbs_VERTEX) {
-       MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
-                   myWorkSpine,myOffset,myMap,RefPlane);
+        if (!SE.IsSame(Ends[0]) && !SE.IsSame(Ends[1]))
+          MakeCircle (TopoDS::Edge(PE),TopoDS::Vertex(SE),
+                      myWorkSpine,myOffset,myMap,RefPlane);
       }
       else {
        MakeOffset (TopoDS::Edge(SE),myWorkSpine,myOffset,myMap,RefPlane,
index 7e452f4146b23da0cfc04145bbbf1e8741e0725e..7f42a328c20b1b2098cf45ca54f6bdc03d602e2a 100755 (executable)
@@ -1,24 +1,18 @@
 // Created on: 1995-10-27
 // Created by: Yves FRICAUD
 // Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 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.
+// This file is part of Open CASCADE Technology software library.
 //
-// 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.
+// 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.
 //
-// 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.
-
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 //  Modified by skv - Tue Mar 15 16:20:43 2005
 // Add methods for supporting history.
 #endif
 #ifdef DEB
 #include <OSD_Chronometer.hxx>
-
+//#define DEB_VERB
   Standard_Boolean AffichInt2d = Standard_False;       
   Standard_Boolean AffichOffC  = Standard_False;       
   Standard_Boolean ChronBuild  = Standard_False;
 static void DEBVerticesControl (const TopTools_IndexedMapOfShape& NewEdges,
                                      Handle(BRepAlgo_AsDes)      AsDes)
 {
-  Standard_Integer NVP = 0;
-  Standard_Integer NVM = 0;
-  Standard_Integer NVN = 0;
-
   TopTools_ListOfShape               LVP;
-  //TopTools_MapIteratorOfMapOfShape   it;
   TopTools_ListIteratorOfListOfShape it1LE ;    
   TopTools_ListIteratorOfListOfShape it2LE ;
   
-  //for (it.Initialize(NewEdges) ; it.More(); it.Next()) {
   Standard_Integer i;
   for (i = 1; i <= NewEdges.Extent(); i++) {
     const TopoDS_Edge& NE = TopoDS::Edge(NewEdges(i));
@@ -801,16 +789,33 @@ void BRepOffset_MakeOffset::MakeThickSolid()
       Glue.Add (exp.Current());
     } 
     Standard_Boolean YaResult = 0;
-    if (!myOffsetShape.IsNull()) {
-      for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next()) {
-       YaResult = 1;
-       Glue.Add (exp.Current().Reversed());
+    if (!myOffsetShape.IsNull())
+      {
+      for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next())
+        {
+        YaResult = 1;
+        Glue.Add (exp.Current().Reversed());
+        }
+#ifdef BREPOFFSET_DEB
+      if(YaResult == 0)
+        {
+        cout << "OffsetShape does not contain a FACES." << endl;
+        }
+#endif
       }
-    }
-    if (YaResult == 0) {
+#ifdef BREPOFFSET_DEB
+    else
+      {
+      cout << "OffsetShape is null!" << endl;
+      }
+#endif
+
+    if (YaResult == 0)
+      {
       myDone = Standard_False;
       return;
-    }
+      }
+
     myOffsetShape = Glue.Shells();
     for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next()) {
       B.Add(Res,exp.Current());
@@ -1620,7 +1625,7 @@ void BRepOffset_MakeOffset::BuildOffsetByArc()
 //purpose  : 
 //=======================================================================
 
-void BRepOffset_MakeOffset::SelfInter(TopTools_MapOfShape& Modif)
+void BRepOffset_MakeOffset::SelfInter(TopTools_MapOfShape& /*Modif*/)
 {
 #ifdef DEB
   if ( ChronBuild) {
@@ -1845,58 +1850,58 @@ void BRepOffset_MakeOffset::CorrectConicalFaces()
   //TopTools_DataMapOfShapeShape DegEdges;
   TopExp_Explorer Explo( myOffsetShape, TopAbs_FACE );
   if (myJoin == GeomAbs_Arc)
+  {
+    for (; Explo.More(); Explo.Next())
     {
-      for (; Explo.More(); Explo.Next())
-       {
-         TopoDS_Face aFace = TopoDS::Face( Explo.Current() );
-         Handle(Geom_Surface) aSurf = BRep_Tool::Surface( aFace );
-         //if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-         //aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface(); //???
-         
-         TopTools_IndexedMapOfShape Emap;
-         TopExp::MapShapes( aFace, TopAbs_EDGE, Emap );
-         for (i = 1; i <= Emap.Extent(); i++)
-           {
-             TopoDS_Edge anEdge = TopoDS::Edge( Emap(i) );
-             //Standard_Real f, l;
-             //Handle(Geom_Curve) theCurve = BRep_Tool::Curve( anEdge, f, l );
-             //Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
-             if (BRep_Tool::Degenerated(anEdge))
-               {
-                 //Check if anEdge is a really degenerated edge or not
-                 BRepAdaptor_Curve BACurve(anEdge, aFace);
-                 gp_Pnt Pfirst, Plast, Pmid;
-                 Pfirst = BACurve.Value(BACurve.FirstParameter());
-                 Plast  = BACurve.Value(BACurve.LastParameter());
-                 Pmid   = BACurve.Value((BACurve.FirstParameter()+BACurve.LastParameter())/2.);
-                 if (Pfirst.Distance(Plast) <= TolApex &&
-                     Pfirst.Distance(Pmid)  <= TolApex)
-                   continue;
-                 //Cones.Append( aFace );
-                 //Circs.Append( anEdge );
-                 //TopoDS_Vertex Vdeg = TopExp::FirstVertex( anEdge );
-                 TopoDS_Edge OrEdge = 
-                   TopoDS::Edge( myInitOffsetEdge.Root( anEdge) );
-                 TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
-                 if ( FacesOfCone.IsBound(VF) )
-                   {
-                     //add a face to the existing list
-                     TopTools_ListOfShape& aFaces = FacesOfCone.ChangeFind(VF);
-                     aFaces.Append (aFace);
-                     //DegEdges.Bind(aFace, anEdge);
-                   }
-                 else
-                   {
-                     //the vertex is not in the map => create a new key and items
-                     TopTools_ListOfShape aFaces;
-                     aFaces.Append (aFace);
-                     FacesOfCone.Bind(VF, aFaces);
-                     //DegEdges.Bind(aFace, anEdge);
-                   }
-               }
-           } //for (i = 1; i <= Emap.Extent(); i++)
-       } //for (; fexp.More(); fexp.Next())
-    } //if (myJoin == GeomAbs_Arc)
+      TopoDS_Face aFace = TopoDS::Face( Explo.Current() );
+      Handle(Geom_Surface) aSurf = BRep_Tool::Surface( aFace );
+      //if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
+      //aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface(); //???
+      
+      TopTools_IndexedMapOfShape Emap;
+      TopExp::MapShapes( aFace, TopAbs_EDGE, Emap );
+      for (i = 1; i <= Emap.Extent(); i++)
+      {
+        TopoDS_Edge anEdge = TopoDS::Edge( Emap(i) );
+        //Standard_Real f, l;
+        //Handle(Geom_Curve) theCurve = BRep_Tool::Curve( anEdge, f, l );
+        //Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
+        if (BRep_Tool::Degenerated(anEdge))
+        {
+          //Check if anEdge is a really degenerated edge or not
+          BRepAdaptor_Curve BACurve(anEdge, aFace);
+          gp_Pnt Pfirst, Plast, Pmid;
+          Pfirst = BACurve.Value(BACurve.FirstParameter());
+          Plast  = BACurve.Value(BACurve.LastParameter());
+          Pmid   = BACurve.Value((BACurve.FirstParameter()+BACurve.LastParameter())/2.);
+          if (Pfirst.Distance(Plast) <= TolApex &&
+              Pfirst.Distance(Pmid)  <= TolApex)
+            continue;
+          //Cones.Append( aFace );
+          //Circs.Append( anEdge );
+          //TopoDS_Vertex Vdeg = TopExp::FirstVertex( anEdge );
+          TopoDS_Edge OrEdge = 
+            TopoDS::Edge( myInitOffsetEdge.Root( anEdge) );
+          TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
+          if ( FacesOfCone.IsBound(VF) )
+          {
+            //add a face to the existing list
+            TopTools_ListOfShape& aFaces = FacesOfCone.ChangeFind(VF);
+            aFaces.Append (aFace);
+            //DegEdges.Bind(aFace, anEdge);
+          }
+          else
+          {
+            //the vertex is not in the map => create a new key and items
+            TopTools_ListOfShape aFaces;
+            aFaces.Append (aFace);
+            FacesOfCone.Bind(VF, aFaces);
+            //DegEdges.Bind(aFace, anEdge);
+          }
+        }
+      } //for (i = 1; i <= Emap.Extent(); i++)
+    } //for (; fexp.More(); fexp.Next())
+  } //if (myJoin == GeomAbs_Arc)
 
   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape Cone(FacesOfCone);
   BRep_Builder BB;
@@ -1913,218 +1918,218 @@ void BRepOffset_MakeOffset::CorrectConicalFaces()
     gp_Pnt FirstPoint;
     TopoDS_Vertex theFirstVertex, CurFirstVertex;
     for (; itFaces.More(); itFaces.Next())
+    {
+      TopoDS_Face aFace = TopoDS::Face(itFaces.Value()); //TopoDS::Face(Faces.First());
+      TopoDS_Edge DegEdge; // = TopoDS::Edge(DegEdges(aFace));
+      for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
       {
-       TopoDS_Face aFace = TopoDS::Face(itFaces.Value()); //TopoDS::Face(Faces.First());
-       TopoDS_Edge DegEdge; // = TopoDS::Edge(DegEdges(aFace));
-       for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
-         {
-           DegEdge = TopoDS::Edge(Explo.Current());
-           if (BRep_Tool::Degenerated(DegEdge))
-             {
-               TopoDS_Edge OrEdge = TopoDS::Edge( myInitOffsetEdge.Root( DegEdge) );
-               TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
-               if (VF.IsSame(anApex))
-                 break;
-             }
-         }
-       TopoDS_Shape aLocalDegShape = DegEdge.Oriented(TopAbs_FORWARD);
-       TopoDS_Edge CurEdge = TopoDS::Edge(aLocalDegShape);
-       BB.Degenerated(CurEdge, Standard_False);
-       BB.SameRange(CurEdge, Standard_False);
-       BB.SameParameter(CurEdge, Standard_False);
-       gp_Pnt fPnt, lPnt, mPnt;
-       GetEdgePoints(CurEdge, aFace, fPnt, mPnt, lPnt);
-       Standard_Real f, l;
-       BRep_Tool::Range(CurEdge, f, l);
-       if (isFirstFace)
-         {
-           gp_Vec aVec1(fPnt, mPnt);
-           gp_Vec aVec2(fPnt, lPnt);
-           gp_Vec aNorm = aVec1.Crossed(aVec2);
-           gp_Pnt theApex = BRep_Tool::Pnt(anApex);
-           gp_Vec ApexToFpnt(theApex, fPnt);
-           gp_Vec Ydir = aNorm ^ ApexToFpnt;
-           gp_Vec Xdir = Ydir ^ aNorm;
-           //Xdir.Rotate(gp_Ax1(theApex, aNorm), -f);
-           gp_Ax2 anAx2(theApex, gp_Dir(aNorm), gp_Dir(Xdir));
-           theSphere.SetRadius(myOffset);
-           theSphere.SetPosition(gp_Ax3(anAx2) /*gp_Ax3(theApex, gp_Dir(aNorm))*/);
-           aSphSurf = new Geom_SphericalSurface(theSphere);
-           FirstPoint = fPnt;
-           theFirstVertex = BRepLib_MakeVertex(fPnt);
-           CurFirstVertex = theFirstVertex;
-         }
-
-       TopoDS_Vertex v1, v2, FirstVert, EndVert;
-       TopExp::Vertices(CurEdge, v1, v2);
-       FirstVert = CurFirstVertex;
-       if (lPnt.Distance(FirstPoint) <= Precision::Confusion())
-         EndVert = theFirstVertex;
-       else
-         EndVert = BRepLib_MakeVertex(lPnt);
-       CurEdge.Free( Standard_True );
-       BB.Remove(CurEdge, v1);
-       BB.Remove(CurEdge, v2);
-       BB.Add(CurEdge, FirstVert.Oriented(TopAbs_FORWARD));
-       BB.Add(CurEdge, EndVert.Oriented(TopAbs_REVERSED));
-       //take the curve from sphere an put it to the edge
-       Standard_Real Uf, Vf, Ul, Vl;
-       ElSLib::Parameters( theSphere, fPnt, Uf, Vf );
-       ElSLib::Parameters( theSphere, lPnt, Ul, Vl );
-       if (Abs(Ul) <= Precision::Confusion())
-         Ul = 2.*M_PI;
-       Handle(Geom_Curve) aCurv = aSphSurf->VIso(Vf);
-       /*
+        DegEdge = TopoDS::Edge(Explo.Current());
+        if (BRep_Tool::Degenerated(DegEdge))
+        {
+          TopoDS_Edge OrEdge = TopoDS::Edge( myInitOffsetEdge.Root( DegEdge) );
+          TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
+          if (VF.IsSame(anApex))
+            break;
+        }
+      }
+      TopoDS_Shape aLocalDegShape = DegEdge.Oriented(TopAbs_FORWARD);
+      TopoDS_Edge CurEdge = TopoDS::Edge(aLocalDegShape);
+      BB.Degenerated(CurEdge, Standard_False);
+      BB.SameRange(CurEdge, Standard_False);
+      BB.SameParameter(CurEdge, Standard_False);
+      gp_Pnt fPnt, lPnt, mPnt;
+      GetEdgePoints(CurEdge, aFace, fPnt, mPnt, lPnt);
+      Standard_Real f, l;
+      BRep_Tool::Range(CurEdge, f, l);
+      if (isFirstFace)
+      {
+        gp_Vec aVec1(fPnt, mPnt);
+        gp_Vec aVec2(fPnt, lPnt);
+        gp_Vec aNorm = aVec1.Crossed(aVec2);
+        gp_Pnt theApex = BRep_Tool::Pnt(anApex);
+        gp_Vec ApexToFpnt(theApex, fPnt);
+        gp_Vec Ydir = aNorm ^ ApexToFpnt;
+        gp_Vec Xdir = Ydir ^ aNorm;
+        //Xdir.Rotate(gp_Ax1(theApex, aNorm), -f);
+        gp_Ax2 anAx2(theApex, gp_Dir(aNorm), gp_Dir(Xdir));
+        theSphere.SetRadius(myOffset);
+        theSphere.SetPosition(gp_Ax3(anAx2) /*gp_Ax3(theApex, gp_Dir(aNorm))*/);
+        aSphSurf = new Geom_SphericalSurface(theSphere);
+        FirstPoint = fPnt;
+        theFirstVertex = BRepLib_MakeVertex(fPnt);
+        CurFirstVertex = theFirstVertex;
+      }
+      
+      TopoDS_Vertex v1, v2, FirstVert, EndVert;
+      TopExp::Vertices(CurEdge, v1, v2);
+      FirstVert = CurFirstVertex;
+      if (lPnt.Distance(FirstPoint) <= Precision::Confusion())
+        EndVert = theFirstVertex;
+      else
+        EndVert = BRepLib_MakeVertex(lPnt);
+      CurEdge.Free( Standard_True );
+      BB.Remove(CurEdge, v1);
+      BB.Remove(CurEdge, v2);
+      BB.Add(CurEdge, FirstVert.Oriented(TopAbs_FORWARD));
+      BB.Add(CurEdge, EndVert.Oriented(TopAbs_REVERSED));
+      //take the curve from sphere an put it to the edge
+      Standard_Real Uf, Vf, Ul, Vl;
+      ElSLib::Parameters( theSphere, fPnt, Uf, Vf );
+      ElSLib::Parameters( theSphere, lPnt, Ul, Vl );
+      if (Abs(Ul) <= Precision::Confusion())
+        Ul = 2.*M_PI;
+      Handle(Geom_Curve) aCurv = aSphSurf->VIso(Vf);
+      /*
        if (!isFirstFace)
-         {
-           gp_Circ aCircle = (Handle(Geom_Circle)::DownCast(aCurv))->Circ();
-           if (Abs(Uf - f) > Precision::Confusion())
-             {
-               aCircle.Rotate(aCircle.Axis(), f - Uf);
-               aCurv = new Geom_Circle(aCircle);
-             }
-         }
-       */
-       Handle(Geom_TrimmedCurve) aTrimCurv = new Geom_TrimmedCurve(aCurv, Uf, Ul);
-       BB.UpdateEdge(CurEdge, aTrimCurv, Precision::Confusion());
-       BB.Range(CurEdge, Uf, Ul, Standard_True);
-       Handle(Geom2d_Line) theLin2d = new Geom2d_Line( gp_Pnt2d( 0., Vf ), gp::DX2d() );
-       Handle(Geom2d_TrimmedCurve) theTrimLin2d = new Geom2d_TrimmedCurve(theLin2d, Uf, Ul);
-       BB.UpdateEdge(CurEdge, theTrimLin2d, aSphSurf, L, Precision::Confusion());
-       BB.Range(CurEdge, aSphSurf, L, Uf, Ul);
-       BRepLib::SameParameter(CurEdge);
-       BB.Add(SphereWire, CurEdge);
-       //Modifying correspondent edges in aFace: substitute vertices common with CurEdge
-       BRepAdaptor_Curve2d BAc2d(CurEdge, aFace);
-       gp_Pnt2d fPnt2d, lPnt2d;
-       fPnt2d = BAc2d.Value(BAc2d.FirstParameter());
-       lPnt2d = BAc2d.Value(BAc2d.LastParameter());
-       TopTools_IndexedMapOfShape Emap;
-       TopExp::MapShapes(aFace, TopAbs_EDGE, Emap);
-       TopoDS_Edge EE [2];
-       Standard_Integer j = 0, k;
-       for (k = 1; k <= Emap.Extent(); k++)
-         {
-           const TopoDS_Edge& anEdge = TopoDS::Edge(Emap(k));
-           if (!BRep_Tool::Degenerated(anEdge))
-             {
-               TopoDS_Vertex V1, V2;
-               TopExp::Vertices(anEdge, V1, V2);
-               if (V1.IsSame(v1) || V2.IsSame(v1))
-                 EE[j++] = anEdge;
-             }
-         }
-       for (k = 0; k < j; k++)
-         {
-           TopoDS_Shape aLocalShape = EE[k].Oriented(TopAbs_FORWARD);
-           TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
-           Eforward.Free(Standard_True);
-           TopoDS_Vertex V1, V2;
-           TopExp::Vertices( Eforward, V1, V2 );
-           BRepAdaptor_Curve2d EEc( Eforward, aFace );
-           gp_Pnt2d p2d1, p2d2;
-           p2d1 = EEc.Value(EEc.FirstParameter());
-           p2d2 = EEc.Value(EEc.LastParameter());
-           if (V1.IsSame(v1))
-             {
-               TopoDS_Vertex NewV = (p2d1.Distance(fPnt2d) <= Precision::Confusion())?
-                 FirstVert : EndVert;
-               BB.Remove( Eforward, V1 );
-               BB.Add( Eforward, NewV.Oriented(TopAbs_FORWARD) );
-             }
-           else
-             {
-               TopoDS_Vertex NewV = (p2d2.Distance(fPnt2d) <= Precision::Confusion())?
-                 FirstVert : EndVert;
-               BB.Remove( Eforward, V2 );
-               BB.Add( Eforward, NewV.Oriented(TopAbs_REVERSED) );
-             }
-         }
-
-       isFirstFace = Standard_False;
-       CurFirstVertex = EndVert;
+        {
+        gp_Circ aCircle = (Handle(Geom_Circle)::DownCast(aCurv))->Circ();
+        if (Abs(Uf - f) > Precision::Confusion())
+        {
+        aCircle.Rotate(aCircle.Axis(), f - Uf);
+        aCurv = new Geom_Circle(aCircle);
+        }
+        }
+      */
+      Handle(Geom_TrimmedCurve) aTrimCurv = new Geom_TrimmedCurve(aCurv, Uf, Ul);
+      BB.UpdateEdge(CurEdge, aTrimCurv, Precision::Confusion());
+      BB.Range(CurEdge, Uf, Ul, Standard_True);
+      Handle(Geom2d_Line) theLin2d = new Geom2d_Line( gp_Pnt2d( 0., Vf ), gp::DX2d() );
+      Handle(Geom2d_TrimmedCurve) theTrimLin2d = new Geom2d_TrimmedCurve(theLin2d, Uf, Ul);
+      BB.UpdateEdge(CurEdge, theTrimLin2d, aSphSurf, L, Precision::Confusion());
+      BB.Range(CurEdge, aSphSurf, L, Uf, Ul);
+      BRepLib::SameParameter(CurEdge);
+      BB.Add(SphereWire, CurEdge);
+      //Modifying correspondent edges in aFace: substitute vertices common with CurEdge
+      BRepAdaptor_Curve2d BAc2d(CurEdge, aFace);
+      gp_Pnt2d fPnt2d, lPnt2d;
+      fPnt2d = BAc2d.Value(BAc2d.FirstParameter());
+      lPnt2d = BAc2d.Value(BAc2d.LastParameter());
+      TopTools_IndexedMapOfShape Emap;
+      TopExp::MapShapes(aFace, TopAbs_EDGE, Emap);
+      TopoDS_Edge EE [2];
+      Standard_Integer j = 0, k;
+      for (k = 1; k <= Emap.Extent(); k++)
+      {
+        const TopoDS_Edge& anEdge = TopoDS::Edge(Emap(k));
+        if (!BRep_Tool::Degenerated(anEdge))
+        {
+          TopoDS_Vertex V1, V2;
+          TopExp::Vertices(anEdge, V1, V2);
+          if (V1.IsSame(v1) || V2.IsSame(v1))
+            EE[j++] = anEdge;
+        }
+      }
+      for (k = 0; k < j; k++)
+      {
+        TopoDS_Shape aLocalShape = EE[k].Oriented(TopAbs_FORWARD);
+        TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
+        Eforward.Free(Standard_True);
+        TopoDS_Vertex V1, V2;
+        TopExp::Vertices( Eforward, V1, V2 );
+        BRepAdaptor_Curve2d EEc( Eforward, aFace );
+        gp_Pnt2d p2d1, p2d2;
+        p2d1 = EEc.Value(EEc.FirstParameter());
+        p2d2 = EEc.Value(EEc.LastParameter());
+        if (V1.IsSame(v1))
+        {
+          TopoDS_Vertex NewV = (p2d1.Distance(fPnt2d) <= Precision::Confusion())?
+            FirstVert : EndVert;
+          BB.Remove( Eforward, V1 );
+          BB.Add( Eforward, NewV.Oriented(TopAbs_FORWARD) );
+        }
+        else
+        {
+          TopoDS_Vertex NewV = (p2d2.Distance(fPnt2d) <= Precision::Confusion())?
+            FirstVert : EndVert;
+          BB.Remove( Eforward, V2 );
+          BB.Add( Eforward, NewV.Oriented(TopAbs_REVERSED) );
+        }
       }
+      
+      isFirstFace = Standard_False;
+      CurFirstVertex = EndVert;
+    }
     //Building new spherical face
     Standard_Real Ufirst = RealLast(), Ulast = RealFirst();
     gp_Pnt2d p2d1, p2d2;
     TopTools_ListOfShape EdgesOfWire;
     TopoDS_Iterator itw(SphereWire);
     for (; itw.More(); itw.Next())
-      {
-       const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
-       EdgesOfWire.Append(anEdge);
-       Standard_Real f, l;
-       Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aSphSurf, L, f, l);
-       p2d1 = aC2d->Value(f);
-       p2d2 = aC2d->Value(l);
-       if (p2d1.X() < Ufirst)
-         Ufirst = p2d1.X();
-       if (p2d1.X() > Ulast)
-         Ulast = p2d1.X();
-       if (p2d2.X() < Ufirst)
-         Ufirst = p2d2.X();
-       if (p2d2.X() > Ulast)
-         Ulast = p2d2.X();
-      }
+    {
+      const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
+      EdgesOfWire.Append(anEdge);
+      Standard_Real f, l;
+      Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aSphSurf, L, f, l);
+      p2d1 = aC2d->Value(f);
+      p2d2 = aC2d->Value(l);
+      if (p2d1.X() < Ufirst)
+        Ufirst = p2d1.X();
+      if (p2d1.X() > Ulast)
+        Ulast = p2d1.X();
+      if (p2d2.X() < Ufirst)
+        Ufirst = p2d2.X();
+      if (p2d2.X() > Ulast)
+        Ulast = p2d2.X();
+    }
     TopTools_ListOfShape NewEdges;
     TopoDS_Edge FirstEdge;
     TopTools_ListIteratorOfListOfShape itl(EdgesOfWire);
     for (; itl.More(); itl.Next())
+    {
+      FirstEdge = TopoDS::Edge(itl.Value());
+      Standard_Real f, l;
+      Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(FirstEdge, aSphSurf, L, f, l);
+      p2d1 = aC2d->Value(f);
+      p2d2 = aC2d->Value(l);
+      if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion())
       {
-       FirstEdge = TopoDS::Edge(itl.Value());
-       Standard_Real f, l;
-       Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(FirstEdge, aSphSurf, L, f, l);
-       p2d1 = aC2d->Value(f);
-       p2d2 = aC2d->Value(l);
-       if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion())
-         {
-           EdgesOfWire.Remove(itl);
-           break;
-         }
+        EdgesOfWire.Remove(itl);
+        break;
       }
+    }
     NewEdges.Append(FirstEdge);
     TopoDS_Vertex Vf1, CurVertex;
     TopExp::Vertices(FirstEdge, Vf1, CurVertex);
     itl.Initialize(EdgesOfWire);
     while (itl.More())
+    {
+      const TopoDS_Edge& anEdge = TopoDS::Edge(itl.Value());
+      TopoDS_Vertex V1, V2;
+      TopExp::Vertices(anEdge, V1, V2);
+      if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex))
       {
-       const TopoDS_Edge& anEdge = TopoDS::Edge(itl.Value());
-       TopoDS_Vertex V1, V2;
-       TopExp::Vertices(anEdge, V1, V2);
-       if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex))
-         {
-           NewEdges.Append(anEdge);
-           CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
-           EdgesOfWire.Remove(itl);
-         }
-       else
-         itl.Next();
+        NewEdges.Append(anEdge);
+        CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
+        EdgesOfWire.Remove(itl);
       }
-
+      else
+        itl.Next();
+    }
+    
     Standard_Real Vfirst, Vlast;
     if (p2d1.Y() > 0.)
-      {
-       Vfirst = p2d1.Y(); Vlast = M_PI/2.;
-      }
+    {
+      Vfirst = p2d1.Y(); Vlast = M_PI/2.;
+    }
     else
-      {
-       Vfirst = -M_PI/2.; Vlast = p2d1.Y();
-      }
+    {
+      Vfirst = -M_PI/2.; Vlast = p2d1.Y();
+    }
     TopoDS_Face NewSphericalFace = BRepLib_MakeFace(aSphSurf, Ufirst, Ulast, Vfirst, Vlast, Precision::Confusion());
     TopoDS_Edge OldEdge;
     for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next())
+    {
+      OldEdge = TopoDS::Edge(Explo.Current());
+      if (!BRep_Tool::Degenerated(OldEdge))
       {
-       OldEdge = TopoDS::Edge(Explo.Current());
-       if (!BRep_Tool::Degenerated(OldEdge))
-         {
-           BRepAdaptor_Curve2d BAc2d(OldEdge, NewSphericalFace);
-           p2d1 = BAc2d.Value(BAc2d.FirstParameter());
-           p2d2 = BAc2d.Value(BAc2d.LastParameter());
-           if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion() &&
-               Abs(p2d2.X() - Ulast)  <= Precision::Confusion())
-             break;
-         }
+        BRepAdaptor_Curve2d BAc2d(OldEdge, NewSphericalFace);
+        p2d1 = BAc2d.Value(BAc2d.FirstParameter());
+        p2d2 = BAc2d.Value(BAc2d.LastParameter());
+        if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion() &&
+            Abs(p2d2.X() - Ulast)  <= Precision::Confusion())
+          break;
       }
+    }
     TopoDS_Vertex V1, V2;
     TopExp::Vertices(OldEdge, V1, V2);
     TopTools_ListOfShape LV1, LV2;
@@ -2137,11 +2142,11 @@ void BRepOffset_MakeOffset::CorrectConicalFaces()
     theSubstitutor.Substitute(OldEdge, NewEdges);
     theSubstitutor.Build(NewSphericalFace);
     if (theSubstitutor.IsCopied(NewSphericalFace))
-      {
-       const TopTools_ListOfShape& listSh = theSubstitutor.Copy(NewSphericalFace);
-       NewSphericalFace = TopoDS::Face(listSh.First());
-      }
-
+    {
+      const TopTools_ListOfShape& listSh = theSubstitutor.Copy(NewSphericalFace);
+      NewSphericalFace = TopoDS::Face(listSh.First());
+    }
+    
     //Adding NewSphericalFace to the shell
     Explo.Init( myOffsetShape, TopAbs_SHELL );
     TopoDS_Shape theShell = Explo.Current();
@@ -2149,415 +2154,39 @@ void BRepOffset_MakeOffset::CorrectConicalFaces()
     BB.Add( theShell, NewSphericalFace );
   }
 
-  Explo.Init( myOffsetShape, TopAbs_SHELL );
-
-  if (Explo.More()) {
-    TopoDS_Shape theShell = Explo.Current();
-    theShell.Closed( Standard_True );
-  }
-
-/*
-  //Reconstructing
-  BRep_Builder BB;
-  for (i = 1; i <= Cones.Length(); i++)
-    {
-      TopoDS_Face Cone = TopoDS::Face( Cones(i) );
-      TopoDS_Edge Circ = TopoDS::Edge( Circs(i) );
-      TopoDS_Edge Seam = TopoDS::Edge( Seams(i) );
-      if (Circ.IsNull()) //case 1 with big offset
-       {
-         //ExtraFace is absent
-         
-         Handle(Geom_Surface) aSurf = BRep_Tool::Surface( Cone ), OffSurf = aSurf;
-
-         if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-           aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface();
-         gp_Cone theCone = (Handle(Geom_ConicalSurface)::DownCast(aSurf))->Cone();
-         gp_Pnt apex = theCone.Apex();
-         Standard_Real Uapex, Vapex;
-         ElSLib::Parameters( theCone, apex, Uapex, Vapex );
-         if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-           apex = OffSurf->Value( Uapex, Vapex );
-
-         //Making new degenerated edge
-         Handle(Geom2d_Line) theLine = GCE2d_MakeLine( gp_Pnt2d( 0., Vapex ), gp_Pnt2d( 2.*M_PI, Vapex ) );
-         TopoDS_Edge NewEdge;
-         BB.MakeEdge( NewEdge );
-         NewEdge.Orientation(TopAbs_FORWARD);
-         BB.UpdateEdge( NewEdge, theLine, Cone, Precision::Confusion() );
-         BB.Range( NewEdge, 0., 2.*M_PI );
-         BB.SameParameter( NewEdge, Standard_True );
-         BB.SameRange( NewEdge, Standard_True );
-         BB.Degenerated( NewEdge, Standard_True );
-         TopoDS_Vertex Apex = BRepLib_MakeVertex( apex );
-         BB.Add( NewEdge, Apex.Oriented(TopAbs_FORWARD) );
-         BB.Add( NewEdge, Apex.Oriented(TopAbs_REVERSED) );
-
-         //Reconstructing Seam
-         Standard_Real f, l, par, cpar;
-         Handle(Geom2d_Curve) theCurve = BRep_Tool::CurveOnSurface( Seam, Cone, f, l );
-         gp_Lin2d aLine = (Handle(Geom2d_Line)::DownCast(theCurve))->Lin2d();
-         par = ElCLib::Parameter( aLine, gp_Pnt2d( Uapex, Vapex ) );
-         TopoDS_Shape aLocalShape = Seam.Oriented(TopAbs_FORWARD);
-         TopoDS_Vertex cver = TopExp::LastVertex( TopoDS::Edge(aLocalShape) );
-         cpar = BRep_Tool::Parameter( cver, Seam, Cone );
-         if (Abs(f-cpar) < Abs(l-cpar))
-           BB.Range( Seam, par, l );
-         else
-           BB.Range( Seam, f, par );
-         Seam.Free( Standard_True );
-         TopoDS_Shape cver1;
-         TopoDS_Iterator iter( Seam );
-         for (; iter.More(); iter.Next())
-           {
-             cver1 = iter.Value();
-             if (cver1.IsSame(cver))
-               break;
-           }
-         BB.Remove( Seam, cver1 );
-         if (Abs(f-cpar) < Abs(l-cpar))
-           BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_FORWARD) ) );
-         else
-           BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_REVERSED) ) );
-
-         //Adding NewEdge into Cone
-         TopoDS_Shape theWire;
-         for (fexp.Init( Cone, TopAbs_WIRE ); fexp.More(); fexp.Next())
-           {
-             theWire = fexp.Current();
-             Standard_Boolean found = Standard_False;
-             for (iter.Initialize( theWire ); iter.More(); iter.Next())
-               {
-                 if (Seam.IsSame( iter.Value() ))
-                   {
-                     found = Standard_True;
-                     break;
-                   }
-               }
-             if (found)
-               break;
-           }
-         theWire.Free( Standard_True );
-         NewEdge.Orientation( TopAbs::Compose(theWire.Orientation(),TopAbs_REVERSED) );
-         BB.Add( theWire, NewEdge );
-       } //end of case 1 with big offset
-      else
-       {
-         Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Circ.TShape());
-         if (! TE->Degenerated()) //case 1
-           {
-             //Find ExtraFace
-             TopoDS_Face ExtraFace;
-             for (fexp.Init( myOffsetShape, TopAbs_FACE ); fexp.More(); fexp.Next())
-               {
-                 ExtraFace = TopoDS::Face( fexp.Current() );
-                 if (ExtraFace.IsSame( Cone ))
-                   continue;
-                 Standard_Boolean found = Standard_False;
-                 TopExp_Explorer eexp( ExtraFace, TopAbs_EDGE );
-                 for (; eexp.More(); eexp.Next())
-                   if (Circ.IsSame( eexp.Current() ))
-                     {
-                       found = Standard_True;
-                       break;
-                     }
-                 if (found)
-                   break;
-               }
-             
-             Handle(Geom_Surface) aSurf = BRep_Tool::Surface( Cone ), OffSurf = aSurf;
-             if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-               aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface();
-             gp_Cone theCone = (Handle(Geom_ConicalSurface)::DownCast(aSurf))->Cone();
-             gp_Pnt apex = theCone.Apex();
-             Standard_Real Uapex, Vapex;
-             ElSLib::Parameters( theCone, apex, Uapex, Vapex );
-             if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-               apex = OffSurf->Value( Uapex, Vapex );
-             
-             //Making new degenerated edge
-             Handle(Geom2d_Line) theLine = GCE2d_MakeLine( gp_Pnt2d( 0., Vapex ), gp_Pnt2d( 2.*M_PI, Vapex ) );
-             TopoDS_Edge NewEdge;
-             BB.MakeEdge( NewEdge );
-             NewEdge.Orientation(TopAbs_FORWARD);
-             BB.UpdateEdge( NewEdge, theLine, Cone, BRep_Tool::Tolerance( Circ ) );
-             BB.Range( NewEdge, 0., 2.*M_PI );
-             BB.SameParameter( NewEdge, Standard_True );
-             BB.SameRange( NewEdge, Standard_True );
-             BB.Degenerated( NewEdge, Standard_True );
-             TopoDS_Vertex Apex = BRepLib_MakeVertex( apex );
-             BB.Add( NewEdge, Apex.Oriented(TopAbs_FORWARD) );
-             BB.Add( NewEdge, Apex.Oriented(TopAbs_REVERSED) );
-             
-             TopoDS_Vertex cver = TopExp::FirstVertex( Circ );
-             
-             //Reconstructing Seam
-             Standard_Real f, l, par, cpar;
-             Handle(Geom2d_Curve) theCurve = BRep_Tool::CurveOnSurface( Seam, Cone, f, l );
-             gp_Lin2d aLine = (Handle(Geom2d_Line)::DownCast(theCurve))->Lin2d();
-             par = ElCLib::Parameter( aLine, gp_Pnt2d( Uapex, Vapex ) );
-             cpar = BRep_Tool::Parameter( cver, Seam, Cone );
-             if (Abs(f-cpar) < Abs(l-cpar))
-               BB.Range( Seam, par, l );
-             else
-               BB.Range( Seam, f, par );
-             Seam.Free( Standard_True );
-             TopoDS_Shape cver1;
-             TopoDS_Iterator iter( Seam );
-             for (; iter.More(); iter.Next())
-               {
-                 cver1 = iter.Value();
-                 if (cver1.IsSame(cver))
-                   break;
-               }
-             BB.Remove( Seam, cver1 );
-             if (Abs(f-cpar) < Abs(l-cpar))
-               BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_FORWARD) ) );
-             else
-               BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_REVERSED) ) );
-             
-             //Removing ExtraFace from the shell
-             fexp.Init( myOffsetShape, TopAbs_SHELL );
-             TopoDS_Shape theShell = fexp.Current();
-             theShell.Free( Standard_True );
-             TopoDS_Shape ExtraFace1;
-             for (iter.Initialize( theShell ); iter.More(); iter.Next())
-               {
-                 ExtraFace1 = iter.Value();
-                 if (ExtraFace1.IsSame(ExtraFace))
-                   break;
-               }
-             BB.Remove( theShell, ExtraFace1 );
-             
-             //Substitute Circ by NewEdge in Cone
-             TopoDS_Shape theWire;
-             TopoDS_Shape Circ1;
-             for (fexp.Init( Cone, TopAbs_WIRE ); fexp.More(); fexp.Next())
-               {
-                 theWire = fexp.Current();
-                 Standard_Boolean found = Standard_False;
-                 for (iter.Initialize( theWire ); iter.More(); iter.Next())
-                   {
-                     Circ1 = iter.Value();
-                     if (Circ1.IsSame(Circ))
-                       {
-                         found = Standard_True;
-                         break;
-                       }
-                   }
-                 if (found)
-                   break;
-               }
-             TopAbs_Orientation Or = Circ1.Orientation();
-             theWire.Free( Standard_True );
-             BB.Remove( theWire, Circ1 );
-             BB.Add( theWire, NewEdge.Oriented(Or) );
-           } //end of case 1
-         else // Circ is degenerated
-           {
-             if (myOffset > 0. && myJoin == GeomAbs_Arc) //case 2
-               {
-                 TopoDS_Vertex cver = TopExp::FirstVertex( Circ );
-                 
-                 TopoDS_Face OrCone = TopoDS::Face( myInitOffsetFace.Root( Cone ) );
-                 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( OrCone ), OffSurf = aSurf;
-                 if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-                   aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface();
-                 gp_Cone theCone = (Handle(Geom_ConicalSurface)::DownCast(aSurf))->Cone();
-                 gp_Pnt apex = theCone.Apex();
-                 if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-                   {
-                     Standard_Real Uapex, Vapex;
-                     ElSLib::Parameters( theCone, apex, Uapex, Vapex );
-                     apex = OffSurf->Value( Uapex, Vapex );
-                   }
-
-                 Standard_Real f, l;
-                 Handle(Geom_Curve) ccur = BRep_Tool::Curve( Circ, f, l );
-                 gp_Ax2 Axe2 = (Handle(Geom_Circle)::DownCast(ccur))->Circ().Position();
-                 gp_Ax3 Axe3( Axe2 );
-                 Axe3.SetLocation( apex );
-                 gp_Sphere theSphere( Axe3, myOffset );
-
-                 gp_Pnt OrPnt = BRep_Tool::Pnt(cver);
-                 Standard_Real Uor, Vor;
-                 ElSLib::Parameters( theSphere, OrPnt, Uor, Vor );
-                 TopoDS_Face NewFace;
-                 if (Vor > 0.)
-                   NewFace = BRepLib_MakeFace( theSphere, 0., 2.*M_PI, Vor, M_PI/2. );
-                 else
-                   NewFace = BRepLib_MakeFace( theSphere, 0., 2.*M_PI, -M_PI/2., Vor );
-                 
-                 //Updating the bound of NewFace
-                 TopoDS_Edge Bound;
-                 TopExp_Explorer eexp( NewFace, TopAbs_EDGE );
-                 for (; eexp.More(); eexp.Next())
-                   {
-                     Bound = TopoDS::Edge( eexp.Current() );
-                     Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Bound.TShape());
-                     if (!TE->Degenerated() && !BRepTools::IsReallyClosed( Bound, NewFace ))
-                       break;
-                   }
-                 Handle(Geom2d_Curve) pcurve = BRep_Tool::CurveOnSurface( Circ, Cone, f, l );
-                 BB.UpdateEdge( Bound, pcurve, Cone, BRep_Tool::Tolerance(Circ) );
-                 TopoDS_Vertex bver = TopExp::FirstVertex( Bound );
-                 BB.UpdateVertex( bver, BRep_Tool::Tolerance(cver) );
-                 
-                 //Updating cver in Seam
-                 TopoDS_Vertex cver1;
-                 TopoDS_Iterator iter( Seam );
-                 for (; iter.More(); iter.Next())
-                   {
-                     cver1 = TopoDS::Vertex( iter.Value() );
-                     if (cver1.IsSame(cver))
-                       break;
-                   }
-                 TopAbs_Orientation Or = cver1.Orientation();
-                 Seam.Free( Standard_True );
-                 BB.Remove( Seam, cver1 );
-                 BB.Add( Seam, bver.Oriented(Or) );
-                 
-                 //Substitute Circ by Bound in Cone
-                 TopoDS_Shape theWire;
-                 TopoDS_Shape Circ1;
-                 for (fexp.Init( Cone, TopAbs_WIRE ); fexp.More(); fexp.Next())
-                   {
-                     theWire = fexp.Current();
-                     Standard_Boolean found = Standard_False;
-                     for (iter.Initialize( theWire ); iter.More(); iter.Next())
-                       {
-                         Circ1 = iter.Value();
-                         if (Circ1.IsSame(Circ))
-                           {
-                             found = Standard_True;
-                             break;
-                           }
-                       }
-                     if (found)
-                       break;
-                   }
-                 Or = Circ1.Orientation();
-                 theWire.Free( Standard_True );
-                 BB.Remove( theWire, Circ1 );
-                 BB.Add( theWire, Bound.Oriented(Or) );
-                 
-                 //Adding NewFace to the shell
-                 fexp.Init( myOffsetShape, TopAbs_SHELL );
-                 TopoDS_Shape theShell = fexp.Current();
-                 theShell.Free( Standard_True );
-                 BB.Add( theShell, NewFace );
-                 
-                 theShell.Closed( Standard_True );
-               } //end of case 2
-             else // if ((myOffset > 0. && myJoin == GeomAbs_Intersection) || myOffset < 0.) //case 3, 4
-               {
-                 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( Cone ), OffSurf = aSurf;
-                 if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-                   aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface();
-                 gp_Cone theCone = (Handle(Geom_ConicalSurface)::DownCast(aSurf))->Cone();
-                 gp_Pnt apex = theCone.Apex();
-                 Standard_Real Uapex, Vapex;
-                 ElSLib::Parameters( theCone, apex, Uapex, Vapex );
-                 if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
-                   apex = OffSurf->Value( Uapex, Vapex );
-                 
-                 //Making new degenerated edge
-                 Handle(Geom2d_Line) theLine = GCE2d_MakeLine( gp_Pnt2d( 0., Vapex ), gp_Pnt2d( 2.*M_PI, Vapex ) );
-                 TopoDS_Edge NewEdge;
-                 BB.MakeEdge( NewEdge );
-                 NewEdge.Orientation(TopAbs_FORWARD);
-                 BB.UpdateEdge( NewEdge, theLine, Cone, BRep_Tool::Tolerance( Circ ) );
-                 BB.Range( NewEdge, 0., 2.*M_PI );
-                 BB.SameParameter( NewEdge, Standard_True );
-                 BB.SameRange( NewEdge, Standard_True );
-                 BB.Degenerated( NewEdge, Standard_True );
-                 TopoDS_Vertex Apex = BRepLib_MakeVertex( apex );
-                 BB.Add( NewEdge, Apex.Oriented(TopAbs_FORWARD) );
-                 BB.Add( NewEdge, Apex.Oriented(TopAbs_REVERSED) );
-                 
-                 TopoDS_Vertex cver = TopExp::FirstVertex( Circ );
-                 
-                 //Reconstructing Seam
-                 Standard_Real f, l, par, cpar;
-                 Handle(Geom2d_Curve) theCurve = BRep_Tool::CurveOnSurface( Seam, Cone, f, l );
-                 gp_Lin2d aLine = (Handle(Geom2d_Line)::DownCast(theCurve))->Lin2d();
-                 par = ElCLib::Parameter( aLine, gp_Pnt2d( Uapex, Vapex ) );
-                 cpar = BRep_Tool::Parameter( cver, Seam, Cone );
-                 if (Abs(f-cpar) < Abs(l-cpar))
-                   BB.Range( Seam, par, l );
-                 else
-                   BB.Range( Seam, f, par );
-                 Seam.Free( Standard_True );
-                 TopoDS_Shape cver1;
-                 TopoDS_Iterator iter( Seam );
-                 for (; iter.More(); iter.Next())
-                   {
-                     cver1 = iter.Value();
-                     if (cver1.IsSame(cver))
-                       break;
-                   }
-                 BB.Remove( Seam, cver1 );
-                 if (Abs(f-cpar) < Abs(l-cpar))
-                   BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_FORWARD) ) );
-                 else
-                   BB.Add( Seam, Apex.Oriented( TopAbs::Compose(Seam.Orientation(),TopAbs_REVERSED) ) );
-                 
-                 //Substitute Circ by NewEdge in Cone
-                 TopoDS_Shape theWire;
-                 TopoDS_Shape Circ1;
-                 for (fexp.Init( Cone, TopAbs_WIRE ); fexp.More(); fexp.Next())
-                   {
-                     theWire = fexp.Current();
-                     Standard_Boolean found = Standard_False;
-                     for (iter.Initialize( theWire ); iter.More(); iter.Next())
-                       {
-                         Circ1 = iter.Value();
-                         if (Circ1.IsSame(Circ))
-                           {
-                             found = Standard_True;
-                             break;
-                           }
-                       }
-                     if (found)
-                       break;
-                   }
-                 TopAbs_Orientation Or = Circ1.Orientation();
-                 theWire.Free( Standard_True );
-                 BB.Remove( theWire, Circ1 );
-                 BB.Add( theWire, NewEdge.Oriented(Or) );
-                 
-                 fexp.Init( myOffsetShape, TopAbs_SHELL );
-                 TopoDS_Shape theShell = fexp.Current();
-                 theShell.Closed( Standard_True );
-               } //end of case 3, 4
-           }
-       } //else (! Circ.IsNull())
-    }
-*/
-
-  Standard_Integer            NbShell = 0;
-  TopoDS_Compound             NC;
-  TopoDS_Shape                S1;
-  BB.MakeCompound (NC);
-  
-  for (Explo.Init(myOffsetShape,TopAbs_SHELL); Explo.More(); Explo.Next()) {
-    const TopoDS_Shell& Sh = TopoDS::Shell(Explo.Current());
-    NbShell++;
-    if (Sh.Closed()) {
-      TopoDS_Solid  Sol;
-      BB.MakeSolid  (Sol);
-      BB.Add        (Sol,Sh);
-      Sol.Closed(Standard_True);
-      BB.Add (NC,Sol);
-      if (NbShell == 1) S1 = Sol;
+  if (myShape.ShapeType() == TopAbs_SOLID || myThickening)
+  {
+    Explo.Init( myOffsetShape, TopAbs_SHELL );
+    
+    if (Explo.More()) {
+      TopoDS_Shape theShell = Explo.Current();
+      theShell.Closed( Standard_True );
     }
-    else {
-      BB.Add (NC,Sh);
-      if (NbShell == 1) S1 = Sh;
+    
+    Standard_Integer            NbShell = 0;
+    TopoDS_Compound             NC;
+    TopoDS_Shape                S1;
+    BB.MakeCompound (NC);
+    
+    for (Explo.Init(myOffsetShape,TopAbs_SHELL); Explo.More(); Explo.Next()) {
+      const TopoDS_Shell& Sh = TopoDS::Shell(Explo.Current());
+      NbShell++;
+      if (Sh.Closed()) {
+        TopoDS_Solid  Sol;
+        BB.MakeSolid  (Sol);
+        BB.Add        (Sol,Sh);
+        Sol.Closed(Standard_True);
+        BB.Add (NC,Sol);
+        if (NbShell == 1) S1 = Sol;
+      }
+      else {
+        BB.Add (NC,Sh);
+        if (NbShell == 1) S1 = Sh;
+      }
     }
+    if (NbShell == 1) myOffsetShape = S1;
+    else              myOffsetShape = NC;
   }
-  if (NbShell == 1) myOffsetShape = S1;
-  else              myOffsetShape = NC;
 }
 
 
@@ -2692,7 +2321,7 @@ void BRepOffset_MakeOffset::MakeLoops(TopTools_IndexedMapOfShape& Modif)
 //           share edges that were reconstructed.
 //=======================================================================
 
-void BRepOffset_MakeOffset::MakeFaces(TopTools_IndexedMapOfShape& Modif)
+void BRepOffset_MakeOffset::MakeFaces(TopTools_IndexedMapOfShape& /*Modif*/)
 {
 #ifdef DEb
   if (ChronBuild) {  
@@ -3322,9 +2951,8 @@ void BRepOffset_MakeOffset::EncodeRegularity ()
     const TopTools_ListOfShape& LofOF    = myAsDes->Ascendant(ROE);
     
     if (LofOF.Extent() != 2) {
-#ifdef DEB
-      if ( Standard_False)
-       cout << " Edge shared by " << LofOF.Extent() << " Faces" << endl;
+#ifdef DEB_VERB
+    cout << " Edge shared by " << LofOF.Extent() << " Faces" << endl;
 #endif
       continue;
     }
index 72fd019f69889b05fbc211420f1e9227a20bbd59..3df41186849ded8ee0745a2212e99fe8ffffc388 100755 (executable)
@@ -530,8 +530,12 @@ void BRepOffset_Offset::Init(const TopoDS_Face&                  Face,
     BRepOffset::Surface( S, myOffset, myStatus);
 
   //processing offsets of faces with possible degenerated edges
+  Standard_Boolean UminDegen = Standard_False;
+  Standard_Boolean UmaxDegen = Standard_False;
   Standard_Boolean VminDegen = Standard_False;
   Standard_Boolean VmaxDegen = Standard_False;
+  Standard_Boolean UisoDegen = Standard_False;
+  Standard_Boolean VisoDegen = Standard_False;
   gp_Pnt MinApex, MaxApex;
   Standard_Boolean HasSingularity = Standard_False;
   Standard_Real uf1, uf2, vf1, vf2, fpar, lpar;
@@ -551,20 +555,41 @@ void BRepOffset_Offset::Init(const TopoDS_Face&                  Face,
       if (!DegEdges.IsEmpty())
        {
          const Standard_Real TolApex = 1.e-5;
+          //define the iso of singularity (u or v)
+          const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1));
+          Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar);
+          gp_Pnt2d fp2d = aCurve->Value(fpar);
+          gp_Pnt2d lp2d = aCurve->Value(lpar);
+          if (Abs(fp2d.X() - lp2d.X()) <= Precision::PConfusion())
+            UisoDegen = Standard_True;
+          else
+            VisoDegen = Standard_True;
+          
          if (DegEdges.Length() == 2)
            {
-             VminDegen = Standard_True;
-             VmaxDegen = Standard_True;
+              if (UisoDegen)
+              { UminDegen = Standard_True; UmaxDegen = Standard_True; }
+              else
+              { VminDegen = Standard_True; VmaxDegen = Standard_True; }
            }
          else //DegEdges.Length() == 1
            {
              const TopoDS_Edge& theDegEdge = TopoDS::Edge(DegEdges(1));
              Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theDegEdge, Face, fpar, lpar);
-             gp_Pnt2d aPnt2d = aCurve->Value(fpar);
-             if (Abs(aPnt2d.Y() - vf1) <= Precision::Confusion())
-               VminDegen = Standard_True;
-             else
-               VmaxDegen = Standard_True;
+              if (UisoDegen)
+              {
+                if (Abs(fp2d.X() - uf1) <= Precision::Confusion())
+                  UminDegen = Standard_True;
+                else
+                  UmaxDegen = Standard_True;
+              }
+              else
+              {
+                if (Abs(fp2d.Y() - vf1) <= Precision::Confusion())
+                  VminDegen = Standard_True;
+                else
+                  VmaxDegen = Standard_True;
+              }
            }
          if (TheSurf->DynamicType() == STANDARD_TYPE(Geom_ConicalSurface))
            {
@@ -587,94 +612,171 @@ void BRepOffset_Offset::Init(const TopoDS_Face&                  Face,
            }
          else //TheSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface)
            {
+              if (UminDegen)
+              {
+                Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
+                if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
+                {
+                  Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
+                  gp_Pnt Papex, Pfirst, Pquart, Pmid;
+                  Papex = BasisSurf->Value( uf1, vf1 );
+                  Pfirst = TheSurf->Value( uf1, vf1 );
+                  Pquart = TheSurf->Value( uf1, 0.75*vf1+0.25*vf2 );
+                  Pmid   = TheSurf->Value( uf1, 0.5*(vf1+vf2) );
+                  gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
+                  Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
+                  gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 1, 0 );
+                  Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
+                  GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
+                  gp_Pnt Pint1, Pint2;
+                  theExtrema.NearestPoints(Pint1, Pint2);
+                  Standard_Real length = Pfirst.Distance(Pint1);
+                  if (OffsetOutside)
+                  {
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
+                    GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
+                                                Standard_True, Standard_False);
+                    Standard_Real u1, u2, v1, v2;
+                    TheSurf->Bounds( u1, u2, v1, v2 );
+                    MinApex = TheSurf->Value( u1, vf1 );
+                  }
+                  else
+                  {
+                    Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
+                    GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
+                    Standard_Real NewFirstU = Projector.LowerDistanceParameter();
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, NewFirstU, uf2, vf1, vf2);
+                    MinApex = TheSurf->Value( NewFirstU, vf1 );
+                  }
+                  HasSingularity = Standard_True;
+                }
+              } //end of if (UminDegen)
+             if (UmaxDegen)
+              {
+                Handle(Geom_Curve) uiso = TheSurf->UIso( uf2 );
+                if (BRepOffset_Tool::Gabarit( uiso ) > TolApex)
+                {
+                  Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
+                  gp_Pnt Papex, Pfirst, Pquart, Pmid;
+                  Papex  = BasisSurf->Value( uf2, vf1 );
+                  Pfirst = TheSurf->Value( uf2, vf1 );
+                  Pquart = TheSurf->Value( uf2, 0.75*vf1+0.25*vf2 );
+                  Pmid   = TheSurf->Value( uf2, 0.5*(vf1+vf2) );
+                  gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
+                  Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
+                  gp_Vec DirGeneratrix = BasisSurf->DN( uf2, vf1, 1, 0 );
+                  Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
+                  GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
+                  gp_Pnt Pint1, Pint2;
+                  theExtrema.NearestPoints(Pint1, Pint2);
+                  Standard_Real length = Pfirst.Distance(Pint1);
+                  if (OffsetOutside)
+                  {
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
+                    GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
+                                                Standard_True, Standard_True);
+                    Standard_Real u1, u2, v1, v2;
+                    TheSurf->Bounds( u1, u2, v1, v2 );
+                    MaxApex = TheSurf->Value( u2, vf1 );
+                  }
+                  else
+                  {
+                    Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
+                    GeomAPI_ProjectPointOnCurve Projector( Pint1, viso );
+                    Standard_Real NewLastU = Projector.LowerDistanceParameter();
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, NewLastU, vf1, vf2);
+                    MaxApex = TheSurf->Value( NewLastU, vf1 );
+                  }
+                  HasSingularity = Standard_True;
+                }
+              } //end of if (UmaxDegen)
              if (VminDegen)
-               {
-                 Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
-                 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
-                   {
-                     Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
-                     gp_Pnt Papex, Pfirst, Plast, Pmid;
-                     Papex = BasisSurf->Value( uf1, vf1 );
-                     Pfirst = TheSurf->Value( uf1, vf1 );
-                     Plast  = TheSurf->Value( uf2, vf1 );
-                     Pmid   = TheSurf->Value( (uf1+uf2)/2., vf1 );
-                     gp_Vec DirApex = gp_Vec(Pfirst,Pmid) ^ gp_Vec(Pfirst,Plast);
-                     Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
-                     gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 0, 1 );
-                     Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
-                     GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
-                     gp_Pnt Pint1, Pint2;
-                     theExtrema.NearestPoints(Pint1, Pint2);
-                     Standard_Real length = Pfirst.Distance(Pint1);
-                     if (OffsetOutside)
-                       {
-                         TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
-                         GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
-                                                     Standard_False, Standard_False);
-                         Standard_Real u1, u2, v1, v2;
-                         TheSurf->Bounds( u1, u2, v1, v2 );
-                         MinApex = TheSurf->Value( uf1, v1 );
-                       }
-                     else
-                       {
-                         Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
-                         GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
-                         Standard_Real NewFirstV = Projector.LowerDistanceParameter();
-                         TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, NewFirstV, vf2);
-                         MinApex = TheSurf->Value( uf1, NewFirstV );
-                         //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1+length, vf2);
-                         //MinApex = TheSurf->Value( uf1, vf1+length );
-                       }
-                     HasSingularity = Standard_True;
-                   }
-               } //end of if (VminDegen)
+              {
+                Handle(Geom_Curve) viso = TheSurf->VIso( vf1 );
+                if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
+                {
+                  Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
+                  gp_Pnt Papex, Pfirst, Pquart, Pmid;
+                  Papex = BasisSurf->Value( uf1, vf1 );
+                  Pfirst = TheSurf->Value( uf1, vf1 );
+                  Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf1 );
+                  Pmid   = TheSurf->Value( 0.5*(uf1+uf2), vf1 );
+                  gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
+                  Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
+                  gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf1, 0, 1 );
+                  Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
+                  GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
+                  gp_Pnt Pint1, Pint2;
+                  theExtrema.NearestPoints(Pint1, Pint2);
+                  Standard_Real length = Pfirst.Distance(Pint1);
+                  if (OffsetOutside)
+                  {
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
+                    GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
+                                                Standard_False, Standard_False);
+                    Standard_Real u1, u2, v1, v2;
+                    TheSurf->Bounds( u1, u2, v1, v2 );
+                    MinApex = TheSurf->Value( uf1, v1 );
+                  }
+                  else
+                  {
+                    Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
+                    GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
+                    Standard_Real NewFirstV = Projector.LowerDistanceParameter();
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, NewFirstV, vf2);
+                    MinApex = TheSurf->Value( uf1, NewFirstV );
+                    //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1+length, vf2);
+                    //MinApex = TheSurf->Value( uf1, vf1+length );
+                  }
+                  HasSingularity = Standard_True;
+                }
+              } //end of if (VminDegen)
              if (VmaxDegen)
-               {
-                 Handle(Geom_Curve) viso = TheSurf->VIso( vf2 );
-                 if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
-                   {
-                     Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
-                     gp_Pnt Papex, Pfirst, Plast, Pmid;
-                     Papex = BasisSurf->Value( uf1, vf2 );
-                     Pfirst = TheSurf->Value( uf1, vf2 );
-                     Plast  = TheSurf->Value( uf2, vf2 );
-                     Pmid   = TheSurf->Value( (uf1+uf2)/2., vf2 );
-                     gp_Vec DirApex = gp_Vec(Pfirst,Pmid) ^ gp_Vec(Pfirst,Plast);
-                     Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
-                     gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf2, 0, 1 );
-                     Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
-                     GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
-                     gp_Pnt Pint1, Pint2;
-                     theExtrema.NearestPoints(Pint1, Pint2);
-                     Standard_Real length = Pfirst.Distance(Pint1);
-                     if (OffsetOutside)
-                       {
-                         TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
-                         GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
-                                                     Standard_False, Standard_True);
-                         Standard_Real u1, u2, v1, v2;
-                         TheSurf->Bounds( u1, u2, v1, v2 );
-                         MaxApex = TheSurf->Value( uf1, v2 );
-                       }
-                     else
-                       {
-                         Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
-                         GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
-                         Standard_Real NewLastV = Projector.LowerDistanceParameter();
-                         TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, NewLastV);
-                         MaxApex = TheSurf->Value( uf1, NewLastV );
-                         //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2-length);
-                         //MaxApex = TheSurf->Value( uf1, vf2-length );
-                       }
-                     HasSingularity = Standard_True;
-                   }
-               } //end of if (VmaxDegen)
+              {
+                Handle(Geom_Curve) viso = TheSurf->VIso( vf2 );
+                if (BRepOffset_Tool::Gabarit( viso ) > TolApex)
+                {
+                  Handle(Geom_Surface) BasisSurf = (*((Handle(Geom_OffsetSurface)*)&TheSurf))->BasisSurface();
+                  gp_Pnt Papex, Pfirst, Pquart, Pmid;
+                  Papex = BasisSurf->Value( uf1, vf2 );
+                  Pfirst = TheSurf->Value( uf1, vf2 );
+                  Pquart = TheSurf->Value( 0.75*uf1+0.25*uf2, vf2 );
+                  Pmid   = TheSurf->Value( 0.5*(uf1+uf2), vf2 );
+                  gp_Vec DirApex = gp_Vec(Pfirst,Pquart) ^ gp_Vec(Pfirst,Pmid);
+                  Handle(Geom_Line) LineApex = new Geom_Line( Papex, DirApex );
+                  gp_Vec DirGeneratrix = BasisSurf->DN( uf1, vf2, 0, 1 );
+                  Handle(Geom_Line) LineGeneratrix = new Geom_Line( Pfirst, DirGeneratrix );
+                  GeomAPI_ExtremaCurveCurve theExtrema( LineGeneratrix, LineApex );
+                  gp_Pnt Pint1, Pint2;
+                  theExtrema.NearestPoints(Pint1, Pint2);
+                  Standard_Real length = Pfirst.Distance(Pint1);
+                  if (OffsetOutside)
+                  {
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2);
+                    GeomLib::ExtendSurfByLength(*((Handle(Geom_BoundedSurface)*)&TheSurf), length, 1,
+                                                Standard_False, Standard_True);
+                    Standard_Real u1, u2, v1, v2;
+                    TheSurf->Bounds( u1, u2, v1, v2 );
+                    MaxApex = TheSurf->Value( uf1, v2 );
+                  }
+                  else
+                  {
+                    Handle(Geom_Curve) uiso = TheSurf->UIso( uf1 );
+                    GeomAPI_ProjectPointOnCurve Projector( Pint1, uiso );
+                    Standard_Real NewLastV = Projector.LowerDistanceParameter();
+                    TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, NewLastV);
+                    MaxApex = TheSurf->Value( uf1, NewLastV );
+                    //TheSurf = new Geom_RectangularTrimmedSurface(TheSurf, uf1, uf2, vf1, vf2-length);
+                    //MaxApex = TheSurf->Value( uf1, vf2-length );
+                  }
+                  HasSingularity = Standard_True;
+                }
+              } //end of if (VmaxDegen)
            } //end of else (case of Geom_OffsetSurface)
        } //end of if (!DegEdges.IsEmpty())
     } //end of processing offsets of faces with possible degenerated edges
   
   // find the PCurves of the edges of <Faces> 
-
   BRep_Builder myBuilder;
   myBuilder.MakeFace(myFace);
   myBuilder.UpdateFace(myFace,TheSurf,L,BRep_Tool::Tolerance(Face));
index 8f5899c4a642db3af58d2cc8418ebe0df0a38313..600c9f09738807f6e79ff5bb147a98104988153f 100755 (executable)
@@ -34,7 +34,7 @@ uses
     
 is
 
-    Create
+    Create(IsOpenResult : Boolean from Standard = Standard_False)
     ---Purpose: Empty construtor.
     returns Mat from MAT;
     
@@ -44,6 +44,11 @@ is
        ---Purpose: Algoritm of computation of the bisecting locus.
     is static;
     
+    CreateMatOpen(me : in out ; aTool : in out Tool)
+       ---Purpose: Algoritm of computation of the bisecting locus for
+       --          open wire.
+    is static;
+    
     IsDone(me) returns Boolean from Standard
        ---Purpose:  Returns <TRUE> if CreateMat has succeeded. 
     is static;
@@ -98,6 +103,7 @@ is
 
 fields
 
+    myIsOpenResult        : Boolean;
     thenumberofbisectors  : Integer;
     thenumberofedges      : Integer;
     semiInfinite          : Boolean;
index 28c85495f393d09b9082b6295e00fe3fc579fd5d..99b4d7b14be8f45b7942644e1e3908b39554d7be 100755 (executable)
@@ -34,8 +34,9 @@
 //  purpose  :
 //========================================================================
 
-MAT_Mat::MAT_Mat()
+MAT_Mat::MAT_Mat(const Standard_Boolean IsOpenResult)
 {
+  myIsOpenResult = IsOpenResult;
   thenumberofbisectors = 0;
   thenumberofedges     = 0;
 }
@@ -123,6 +124,670 @@ MAT_Mat::MAT_Mat()
 //            dans la boucle.
 //
 //========================================================================
+void MAT2d_Mat2d::CreateMatOpen(Tool& atool)
+{
+
+#ifdef ICONTINUE
+  Standard_Boolean Icontinue;
+#endif
+
+  Standard_Boolean interrupt = Standard_False;
+
+  Handle(MAT_Edge) edgetoremove;
+  Handle(MAT_Edge) previousedge,currentedge;
+
+  Standard_Integer      noofbisectorstoremove;
+  Handle(MAT_Bisector)  firstbisector,secondbisector;
+  Handle(MAT_Edge)      edge;
+  Standard_Integer      intersectionpoint;
+  Standard_Integer      beginbisector;
+  Standard_Integer      noofbisectors;
+
+  Standard_Integer     NbIterBis = 0;
+  Standard_Integer     EvenNbIterBis = 10;
+  TColStd_Array1OfInteger EdgeNumbers(1, EvenNbIterBis+1);
+  EdgeNumbers.Init(-1);
+  Standard_Boolean     ToNullifyNoofbisectorstoremove = Standard_False;
+
+  Handle(MAT_ListOfBisector) currentbisectorlist;
+
+  Handle(MAT_Bisector) bisectortoremove,lastbisector,currentbisector;
+  Handle(MAT_Bisector) previousbisector;
+
+  Standard_Integer     i,j,k,narea,shift,compact,all;
+  Standard_Integer     noofedges;
+  Standard_Integer     NumberMaxOfIte;
+  Standard_Real        toleranceofconfusion;
+
+  noofedges            = atool.NumberOfItems();
+  toleranceofconfusion = atool.ToleranceOfConfusion();
+  NumberMaxOfIte       = noofedges*noofedges;
+
+  TColStd_Array1OfInteger firstarea(0, noofedges);
+  TColStd_Array1OfInteger lastarea(0, noofedges);
+  TColStd_Array1OfInteger noofarea(0, noofedges);
+
+  Standard_Integer  parama[2];
+  Standard_Integer  paramb[2];
+
+// -----------------------------------------
+// Initialisation et remise a zero des maps.
+// -----------------------------------------
+  bisectoronetoremove.Clear();
+  bisectortwotoremove.Clear();
+  typeofbisectortoremove.Clear();
+  bisectormap.Clear();
+
+  isDone        = Standard_True;
+  noofbisectors = noofedges-1;
+  beginbisector = 0;
+
+// --------------------------------------------------------------------
+// Construction de <theedgelist> un edge correspond a un element simple
+// du contour.
+// --------------------------------------------------------------------
+  theedgelist = new MAT_ListOfEdge();
+
+  for(i=0; i<noofedges; i++) {
+    edge = new MAT_Edge();
+    edge->EdgeNumber(i+1);
+    edge->Distance(-1);
+    theedgelist->BackAdd(edge);
+  }
+  
+  theedgelist->Loop();
+
+//---------------------------------------------------
+// Initialisation des bissectrices issues du contour.
+//---------------------------------------------------
+  Standard_Real Dist;
+  theedgelist->First();
+
+  for(i=0; i<theedgelist->Number()-1; i++) {
+    bisectormap.Bind(i,new MAT_Bisector());
+    bisectormap(i)->IndexNumber(i);
+    bisectormap(i)->FirstEdge(theedgelist->Current());
+    bisectormap(i)->FirstVector
+      (atool.TangentBefore(theedgelist->Current()->EdgeNumber(), myIsOpenResult));
+    theedgelist->Next();
+    bisectormap(i)->SecondEdge(theedgelist->Current());
+    bisectormap(i)->IssuePoint
+      (atool.FirstPoint(theedgelist->Current()->EdgeNumber(),Dist));  
+    bisectormap(i)->DistIssuePoint(Dist);
+    bisectormap(i)->SecondVector
+      (atool.TangentAfter(theedgelist->Current()->EdgeNumber(), myIsOpenResult));
+  }
+
+//----------------------------------------------------
+// Affectation a chaque edge de ses deux bissectrices.
+//----------------------------------------------------
+  theedgelist->First();
+  theedgelist->Current()->FirstBisector(bisectormap(0));
+  theedgelist->Current()->SecondBisector(bisectormap(0));
+  theedgelist->Next();
+
+  for(i=1; i<theedgelist->Number()-1; i++) {
+    theedgelist->Current()->FirstBisector
+      (bisectormap(i-1));
+    theedgelist->Current()->SecondBisector
+      (bisectormap(i));
+    theedgelist->Next();
+  }
+
+  theedgelist->Current()->FirstBisector(bisectormap(theedgelist->Number()-2));
+  theedgelist->Current()->SecondBisector(bisectormap(theedgelist->Number()-2));
+
+//===========================================================================
+//                         Boucle Principale   (etape 2)
+//===========================================================================
+  Standard_Integer NumberOfIte = 0;
+
+  while(theedgelist->Number()>1) {
+
+
+    // ------------------------------------------------------------------
+    //  Creation des geometries des bissectrices via le tool. (etape 2.1)
+    // -------------------------------------------------------------------
+
+    for(i=beginbisector; i<noofbisectors; i++) {
+
+      atool.CreateBisector(bisectormap(i));
+      thenumberofbisectors++;
+      
+#ifdef DEBUG_Mat
+      atool.Dump(bisectormap(i)->BisectorNumber(),1);
+#ifdef ICONTINUE
+      cin>>Icontinue;
+#endif
+#endif
+    }
+
+    // ---------------------------------------------
+    //  Condition de sortie de la boucle principale.
+    // ---------------------------------------------
+
+//  Modified by Sergey KHROMOV - Fri Nov 17 10:28:28 2000 Begin
+    if (theedgelist->Number() < 3)
+      break;
+//  Modified by Sergey KHROMOV - Fri Nov 17 10:28:37 2000 End
+    
+    //---------------------------------------------------
+    // boucle 2 Tant qu il y a des bisectrices a effacer.
+    //---------------------------------------------------
+    for(;;) {
+      NbIterBis++;
+
+      noofbisectorstoremove = 0;
+      theedgelist->First();
+      theedgelist->Next();
+
+      //--------------------------------------------------------------
+      // Calcul des intersections des bisectrices voisines.(etape 2.2)
+      //--------------------------------------------------------------
+
+      if (NbIterBis <= EvenNbIterBis+1)
+       EdgeNumbers(NbIterBis) = theedgelist->Number();
+      else
+       {
+         for (k = 1; k <= EvenNbIterBis; k++)
+           EdgeNumbers(k) = EdgeNumbers(k+1);
+         EdgeNumbers(EvenNbIterBis+1) = theedgelist->Number();
+       }
+      if (EdgeNumbers(EvenNbIterBis+1) == EdgeNumbers(1))
+       ToNullifyNoofbisectorstoremove = Standard_True;
+
+      for(i=1; i<theedgelist->Number()-1; i++) {
+       edge = theedgelist->Current();
+       if(edge->Distance() == -1.) {
+         firstbisector = edge->FirstBisector();
+         secondbisector = edge->SecondBisector();
+         edge->Distance(atool.IntersectBisector
+                        (firstbisector,secondbisector,intersectionpoint));
+         edge->IntersectionPoint(intersectionpoint);
+
+         if(edge->Distance() == Precision::Infinite()) {
+           if(firstbisector->IndexNumber() >= beginbisector ||
+              secondbisector->IndexNumber() >= beginbisector) 
+             Intersect(atool,0,noofbisectorstoremove,
+                       firstbisector,secondbisector );
+         }
+         else {
+           if(firstbisector->IndexNumber() >= beginbisector) {
+             Intersect(atool,1,noofbisectorstoremove,
+                       firstbisector,secondbisector );
+           }
+           if(secondbisector->IndexNumber() >= beginbisector) {
+             Intersect(atool,2,noofbisectorstoremove,
+                       firstbisector,secondbisector );
+           }
+         }
+       }
+       theedgelist->Next();
+      }
+      
+      //-------------------------------
+      // Test de sortie de la boucle 2.
+      //-------------------------------
+
+      if (ToNullifyNoofbisectorstoremove)
+       noofbisectorstoremove = 0;
+      if(noofbisectorstoremove == 0) break;
+
+      //---------------------------------------------------
+      // Annulation des bissectrices a effacer. (etape 2.4)
+      //---------------------------------------------------
+
+      for(i=0; i<noofbisectorstoremove; i++) {
+
+       bisectortoremove = bisectoronetoremove(i);
+
+       //---------------------------------------------------------------
+       // Destruction des bisectrices descendantes de <bisectortoremove>
+       // On descend dans l arbre jusqu a ce qu on atteigne
+       // <bisectortwotoremove(i).
+       //---------------------------------------------------------------
+
+       for(;;){
+
+#ifdef DEBUG_Mat
+         atool.Dump(bisectortoremove->BisectorNumber(),0);
+#endif
+         // ----------------------------------
+         // Annulation de <bisectortoremove>.
+         // ----------------------------------
+         thenumberofbisectors--;
+         currentbisectorlist = bisectortoremove->List();
+         currentbisectorlist->First();
+         currentbisector = currentbisectorlist->FirstItem();
+         previousedge = currentbisector->FirstEdge();
+         theedgelist->Init(previousedge);
+         previousedge->Distance(-1.);
+         previousedge->FirstBisector()->SecondParameter(Precision::Infinite());
+         previousedge->SecondBisector()->FirstParameter(Precision::Infinite());
+
+         //------------------------------------------
+         // Annulation des fils de <currentbisector>.
+         //------------------------------------------
+
+         while(currentbisectorlist->More()) {
+           currentbisector = currentbisectorlist->Current();
+           currentedge  = currentbisector->SecondEdge();
+
+           //---------------------------------------
+           // Reinsertion de l edge dans le contour.
+           //---------------------------------------
+           theedgelist->LinkAfter(currentedge);
+           theedgelist->Next();
+           
+           currentedge->FirstBisector(currentbisector);
+           previousedge->SecondBisector(currentbisector);
+#ifdef DEBUG_Mat                     
+           atool.Dump(currentbisector->BisectorNumber(),0);
+#endif
+
+           //------------------------------------------------------
+           // Annulation de l intersection ie les fils qui
+           // ont generes l intersection sont prolonges a l infini.
+           //------------------------------------------------------
+
+           currentbisector->FirstParameter (Precision::Infinite());
+           currentbisector->SecondParameter(Precision::Infinite());
+                     
+           atool.TrimBisector(currentbisector);
+           
+#ifdef DEBUG_Mat
+           atool.Dump(currentbisector->BisectorNumber(),1);
+#endif
+           currentedge->Distance(-1.);
+           currentedge->FirstBisector()->SecondParameter(Precision::Infinite());
+           currentedge->SecondBisector()->FirstParameter(Precision::Infinite());
+           
+           previousedge = currentedge;
+           currentbisectorlist->Next();
+         }
+         
+         theedgelist->Unlink();
+
+         //-----------------------------------------------------------
+         // Test de sortie de la boucle d annulation des bissectrices.
+         //-----------------------------------------------------------
+
+         if(bisectortoremove->BisectorNumber() ==
+            bisectortwotoremove(i)->BisectorNumber()) break;
+
+         //-----------------------
+         // Descente dans l arbre.
+         //-----------------------
+
+         if(typeofbisectortoremove(i) == 1)
+           bisectortoremove = bisectortoremove->FirstBisector();
+         else
+           bisectortoremove = bisectortoremove->LastBisector();
+       
+       }  //----------------------------------------------------
+          // Fin boucle d annulation des bissectrices issue de 
+          // <bisectoronetoremove(i)>.
+          //----------------------------------------------------
+
+      } //------------------------------------------
+        // Fin boucle d annulation des bissectrices.
+        //-------------------------------------------
+
+#ifdef ICONTINUE
+      cin>>Icontinue;
+#endif
+    } //--------------
+      // Fin Boucle 2.
+      //--------------
+    
+    // ----------------------------------------------------------------------
+    // Analyse des parametres des intersections sur les bisectrices de chaque
+    // edge et determination des portions de contour a supprimees. (etape 2.5)
+    // ----------------------------------------------------------------------
+
+    theedgelist->First();
+    theedgelist->Next();
+      
+    currentbisector = theedgelist->Current()->FirstBisector();
+    if (currentbisector->FirstParameter()  == Precision::Infinite() &&
+       currentbisector->SecondParameter() == Precision::Infinite()) {
+      parama[0] = -1;
+      paramb[0] = -1;
+    }
+    else if(currentbisector->FirstParameter() == Precision::Infinite()) {
+      parama[0] = -1;
+      paramb[0] =  1;
+    }
+    else if(currentbisector->SecondParameter() == Precision::Infinite()) {
+      paramb[0] = -1;
+      parama[0] =  1;
+    }
+    else if (atool.Distance(currentbisector,
+                           currentbisector->FirstParameter(),
+                           currentbisector->SecondParameter()) 
+            > toleranceofconfusion) {
+      if((currentbisector->FirstParameter() - 
+         currentbisector->SecondParameter())
+        *currentbisector->Sense() > 0.) {      
+       parama[0] = -1;
+       paramb[0] =  1;
+      }
+      else {
+       paramb[0] = -1;
+       parama[0] =  1;
+      }
+    }
+    else {
+      parama[0] = 1;
+      paramb[0] = 1;
+    }
+    
+    narea = -1;
+    
+    for(i=1; i<theedgelist->Number()-1; i++) {
+      currentbisector = theedgelist->Current()->SecondBisector();
+      if (currentbisector->FirstParameter()  == Precision::Infinite() &&
+         currentbisector->SecondParameter() == Precision::Infinite()) {
+       parama[1] = -1;
+       paramb[1] = -1;
+      }
+      else if(currentbisector->FirstParameter() == Precision::Infinite()) {
+       parama[1] = -1;
+       paramb[1] =  1;
+      }
+      else if(currentbisector->SecondParameter() == Precision::Infinite()) {
+       paramb[1] = -1;
+       parama[1] =  1;
+      }
+      else if (atool.Distance(currentbisector,
+                             currentbisector->FirstParameter(),
+                             currentbisector->SecondParameter()) 
+              > toleranceofconfusion) {
+       if((currentbisector->FirstParameter() - 
+           currentbisector->SecondParameter()) 
+          *currentbisector->Sense() > 0.) {      
+         parama[1] = -1;
+         paramb[1] =  1;
+       }
+       else {
+         paramb[1] = -1;
+         parama[1] =  1;
+       }
+      }
+      else {
+       parama[1] = 1;
+       paramb[1] = 1;
+      }
+
+      //-----------------------------------------------------------------
+      // Test si l edge est a enlever du contour
+      // Construction des portions de contour a eliminer.
+      //
+      //  narea : nombre de portions continues du contour a eliminer.
+      //  firstarea[i] : indice premier edge de la portion i.
+      //  lastarea[i]  : indice dernier edge de la portion i.
+      //-----------------------------------------------------------------
+
+#ifdef DEBUG_Mat
+      cout <<" Test sur les parametres pour elimination"<<endl;
+      cout << " Edge number :"<<theedgelist->Current()->EdgeNumber()<<endl;
+#endif
+
+      if(paramb[0] > 0 && parama[1] > 0) {
+
+#ifdef DEBUG_Mat
+      cout <<" A ELIMINER "<<endl;
+#endif 
+       if(narea < 0) {
+         firstarea(++narea) = theedgelist->Index();
+         lastarea(narea) = firstarea(narea);
+         noofarea(narea) = 1;
+       }
+       else {
+         if(theedgelist->Index() == lastarea(narea)+1) {
+           lastarea(narea)++;
+           noofarea(narea)++;
+         }
+         else {
+           firstarea(++narea) = theedgelist->Index();
+           lastarea(narea) = firstarea(narea);
+           noofarea(narea) = 1;
+         }
+       }
+      }
+      parama[0] = parama[1];
+      paramb[0] = paramb[1];
+      theedgelist->Next();
+    
+    } 
+    
+    compact = 0;
+    if(narea > 0) {
+      if(lastarea(narea) == theedgelist->Number() && firstarea(0) == 1) {
+       firstarea(0) = firstarea(narea);
+       noofarea(0) = noofarea(0)+noofarea(narea);
+       compact = noofarea(narea);
+       narea--;
+      }
+    }
+    
+    narea++;
+
+    //------------------------------------------------------------------
+    // Sortie de la boucle principale si il n y a pas d edge a eliminer.
+    // (etape 2.6)
+    //------------------------------------------------------------------
+    if(narea == 0) {
+      interrupt = Standard_True;
+      break;
+    }
+    
+
+    //----------------------------------------------------------------
+    // Elimination des edges a enlever du contour
+    // => Mise a jour du nouveau contour.
+    // => Creation des bissectrices entre les nouvelles edges voisines.
+    //----------------------------------------------------------------
+
+    beginbisector = noofbisectors;
+    shift = 0;
+    all = 0;
+    if(narea == 1 && noofarea(0) == theedgelist->Number()) all = 1;
+
+    for(i=0; i<narea; i++) {
+      if(i == 1)shift = shift-compact;
+      theedgelist->First();
+      theedgelist->Next();
+      edgetoremove = theedgelist->Brackets(firstarea(i)-shift);
+      
+      edgetoremove->FirstBisector()->EndPoint(edgetoremove
+                                             ->IntersectionPoint());
+      
+#ifdef DEBUG_Mat
+      atool.Dump(edgetoremove->FirstBisector()->BisectorNumber(),0);
+#endif
+
+      edgetoremove->FirstBisector()->FirstParameter
+       (edgetoremove->FirstBisector()->SecondParameter());
+         
+#ifdef DEBUG_Mat
+      if(atool.TrimBisector(edgetoremove->FirstBisector()))
+       atool.Dump(edgetoremove->FirstBisector()->BisectorNumber(),1);
+#else
+      atool.TrimBisector(edgetoremove->FirstBisector());
+#endif
+
+      bisectormap.Bind(noofbisectors,new MAT_Bisector());
+      bisectormap(noofbisectors)->IndexNumber(noofbisectors);
+      bisectormap(noofbisectors)->DistIssuePoint(edgetoremove->Distance());
+      bisectormap(noofbisectors)->IssuePoint(edgetoremove
+                                               ->IntersectionPoint());
+      bisectormap(noofbisectors)->FirstEdge(theedgelist->PreviousItem());
+      bisectormap(noofbisectors)->AddBisector(edgetoremove
+                                                ->FirstBisector());
+
+      for(j=0; j<noofarea(i); j++) {
+       theedgelist->Unlink();
+       theedgelist->Next();
+       shift++;
+
+#ifdef DEBUG_Mat
+       cout<<" Suppression de l'arete : "<<edgetoremove->EdgeNumber()<<endl;
+#endif
+
+       if(all == 0 || j+1 != noofarea(i)) {
+         bisectormap(noofbisectors)->AddBisector(edgetoremove
+                                                    ->SecondBisector());
+       }
+       edgetoremove->SecondBisector()->EndPoint(edgetoremove
+                                                ->IntersectionPoint());
+
+#ifdef DEBUG_Mat
+       atool.Dump(edgetoremove->SecondBisector()->BisectorNumber(),0);
+#endif
+
+       edgetoremove->SecondBisector()->SecondParameter
+         (edgetoremove->SecondBisector()->FirstParameter());
+#ifdef DEBUG_Mat
+       if(atool.TrimBisector(edgetoremove->SecondBisector()))
+         atool.Dump(edgetoremove->SecondBisector()->BisectorNumber(),1);
+#else
+       atool.TrimBisector(edgetoremove->SecondBisector());
+#endif
+       edgetoremove = theedgelist->Current();
+      }
+      bisectormap(noofbisectors)->SecondEdge(theedgelist->Current());
+
+      theedgelist->PreviousItem()
+        ->SecondBisector(bisectormap(noofbisectors));
+      theedgelist->Current()->FirstBisector(bisectormap(noofbisectors));
+         
+      bisectormap(noofbisectors)->FirstVector
+       (atool.Tangent
+        (bisectormap(noofbisectors)->FirstBisector()
+         ->BisectorNumber()));
+      
+      bisectormap(noofbisectors)->SecondVector
+       (atool.Tangent
+        (bisectormap(noofbisectors)->LastBisector()
+         ->BisectorNumber()));
+      
+      noofbisectors++;
+      
+      theedgelist->PreviousItem()->Distance(-1);
+      theedgelist->Current()->Distance(-1);
+
+      theedgelist->PreviousItem()->FirstBisector()
+        ->SecondParameter(Precision::Infinite());
+      theedgelist->Current()->SecondBisector()->FirstParameter(Precision::Infinite());
+    }
+
+    //-----------------------------------------------------------------------
+    // Test sur le nombre d iterations :
+    // A chaque iteration est elimine un element du contour qui ne sera plus
+    // reinsere par la suite => le nombre d iterartions doit etre < au nombre
+    // d elements.
+    // Le nombre d iteration maximum est fixe a numberofedges*numberofedges.
+    //-----------------------------------------------------------------------
+    if (NumberOfIte > NumberMaxOfIte) {
+      isDone = Standard_False;             //Echec calcul de la carte.
+      break;
+    }
+    NumberOfIte++;
+
+  }  //===============================================
+     //            Fin Boucle Principale.
+     //===============================================
+     
+  //----------
+  // etape 3.
+  //----------
+
+
+  //----------------------------------------------
+  // interupt = True => bissectrices semi_infinies.
+  //----------------------------------------------
+  
+  if(interrupt)
+    semiInfinite = Standard_True;
+  else {
+    semiInfinite = Standard_False;
+
+    //------------------------------------------------------------------
+    // Si le nombre d edge > 1 => le nombre d edge = 2 
+    //              (cf test sortie boucle principale)
+    // Les deux dernieres bisectrices separent les memes edges .
+    // Soit elles sont confondues si calcul a l interieur, soit elles
+    // sont semi-Infinies (exemple : contour compose seulement de deux
+    // arcs de cercles).                          
+    //------------------------------------------------------------------
+
+    if(theedgelist->Number() > 1) { //Now this branch is never reachable
+                                    //because the case edgenumber = 2 is processed in the main loop
+      theedgelist->First();
+      edge = theedgelist->Current();
+      if(edge->FirstBisector()->IndexNumber() == noofbisectors-1) {
+//  Modified by skv - Tue Sep 13 12:13:28 2005 IDEM Begin
+       if (atool.TrimBisector(edge->SecondBisector(),
+                              edge->FirstBisector()->IssuePoint())) {
+         if (edge->SecondBisector()->EndPoint() == 0)
+           edge->SecondBisector()->EndPoint(edge->FirstBisector()->IssuePoint());
+         bisectormap(noofbisectors-1)->AddBisector(edge->SecondBisector());
+       } else
+         semiInfinite = Standard_True;
+//  Modified by skv - Tue Sep 13 12:13:28 2005 IDEM End
+      }
+      else {
+//  Modified by skv - Tue Sep 13 12:13:28 2005 IDEM Begin
+       if (atool.TrimBisector(edge->FirstBisector(),
+                              edge->SecondBisector()->IssuePoint())) {
+         if (edge->FirstBisector()->EndPoint() == 0)
+           edge->FirstBisector()->EndPoint(edge->SecondBisector()->IssuePoint());
+         bisectormap(noofbisectors-1)->AddBisector(edge->FirstBisector());
+       } else 
+         semiInfinite = Standard_True;
+//  Modified by skv - Tue Sep 13 12:13:28 2005 IDEM End
+      }
+      if (!semiInfinite) {     
+       thenumberofbisectors--;
+       bisectormap(noofbisectors-1)->SecondEdge(edge);
+       bisectormap(noofbisectors-1)->BisectorNumber(-1);
+      }
+    }
+  }
+
+  if(semiInfinite) {
+    beginbisector = noofbisectors;
+    theedgelist->First();
+    for(i=1; i<theedgelist->Number(); i++) {
+      edge = theedgelist->Current();
+      bisectormap.Bind(noofbisectors,edge->SecondBisector());
+      noofbisectors++;
+      theedgelist->Next();
+    }
+
+  }
+
+  //---------------------------
+  // Recuperations des racines.
+  //---------------------------
+
+  roots = new MAT_ListOfBisector;
+  
+  if (bisectormap(noofbisectors-1)->BisectorNumber() == -1) {
+    roots = bisectormap(noofbisectors-1)->List();
+    roots->First();
+    roots->Current()->FirstEdge()
+      ->Distance(bisectormap(noofbisectors-1)->DistIssuePoint());
+  }
+  else {
+    for (i=beginbisector;i<noofbisectors;i++) {
+      roots->BackAdd(bisectormap(i));
+    }
+  }
+  
+}
+
 void MAT_Mat::CreateMat(Tool& atool)
 {
 
@@ -207,14 +872,14 @@ void MAT_Mat::CreateMat(Tool& atool)
     bisectormap(i)->IndexNumber(i);
     bisectormap(i)->FirstEdge(theedgelist->Current());
     bisectormap(i)->FirstVector
-      (atool.TangentBefore(theedgelist->Current()->EdgeNumber()));
+      (atool.TangentBefore(theedgelist->Current()->EdgeNumber(), myIsOpenResult));
     theedgelist->Next();
     bisectormap(i)->SecondEdge(theedgelist->Current());
     bisectormap(i)->IssuePoint
       (atool.FirstPoint(theedgelist->Current()->EdgeNumber(),Dist));  
     bisectormap(i)->DistIssuePoint(Dist);
     bisectormap(i)->SecondVector
-      (atool.TangentAfter(theedgelist->Current()->EdgeNumber()));
+      (atool.TangentAfter(theedgelist->Current()->EdgeNumber(), myIsOpenResult));
   }
 
 //----------------------------------------------------
index 8290176f20a85f1fd6343e5fc5aa92724ee7d04c..633e7e28f23d41bfdd8f2c3cedc77cd58ae199b6 100755 (executable)
@@ -65,7 +65,7 @@ void MAT2d_BisectingLocus::Compute(Explorer&        anExplo,
                                    const GeomAbs_JoinType aJoinType,
                                    const Standard_Boolean IsOpenResult)
 {
-  MAT2d_Mat2d                        TheMAT;
+  MAT2d_Mat2d                        TheMAT( IsOpenResult );
   Handle(MAT_ListOfBisector)         TheRoots = new MAT_ListOfBisector();
   MAT2d_SequenceOfSequenceOfGeometry Figure;
   Standard_Integer                   i;
@@ -108,7 +108,10 @@ void MAT2d_BisectingLocus::Compute(Explorer&        anExplo,
   // --------------------------------------------
   // Initialisation et execution de l algorithme.
   // --------------------------------------------
-  TheMAT.CreateMat(theTool);
+  if (IsOpenResult)
+    TheMAT.CreateMatOpen(theTool);
+  else
+    TheMAT.CreateMat(theTool);
 
   isDone = TheMAT.IsDone(); if (!isDone) return;
 
index 3481e3287e6d3b5146b148758fe6f5d9f967c888..a809adc0f47625884809837acfdad51c2afb5ed4 100755 (executable)
@@ -485,16 +485,12 @@ void MAT2d_Circuit::InitOpen (TColGeom2d_SequenceOfGeometry& Line) const
   Handle(Geom2d_TrimmedCurve) Curve;
   Standard_Real               DotProd;
 
-  if (!myIsOpenResult)
-  {
-    Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.First());
-    Line.InsertBefore(1,new Geom2d_CartesianPoint(Curve->StartPoint()));
-    Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Last());
-    Line.Append(new Geom2d_CartesianPoint(Curve->EndPoint()));
-  }
-
-  Standard_Integer addition = (myIsOpenResult)? 1 : 2;
-  for ( Standard_Integer i = addition; i <= Line.Length() - addition; i++) {
+  Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.First());
+  Line.InsertBefore(1,new Geom2d_CartesianPoint(Curve->StartPoint()));
+  Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Last());
+  Line.Append(new Geom2d_CartesianPoint(Curve->EndPoint()));
+  
+  for ( Standard_Integer i = 2; i <= Line.Length() - 2; i++) {
     if ( Abs(CrossProd(Line.Value(i),Line.Value(i+1),DotProd)) > 1.E-8 ||
         DotProd < 0. ) {
       Curve = Handle(Geom2d_TrimmedCurve)::DownCast(Line.Value(i));
index 7113cfdc2b7125e784f013c5d3581c1b4d4cccba..d793065966d482ee2dffee0d322292618a7b5544 100755 (executable)
@@ -82,13 +82,15 @@ is
        --            Returns the index of this point in <theGeomPnts>.    
     returns Integer is static;
     
-    TangentBefore(me : in out ; anitem : Integer) 
+    TangentBefore(me : in out ; anitem : Integer;
+                               IsOpenResult : Boolean)
        --- Purpose : Creates the Tangent at the end of the Item defined
        --            by <anitem>. Returns the index of this vector in
        --            <theGeomVecs>
     returns Integer is static;
     
-    TangentAfter(me : in out ; anitem : Integer) 
+    TangentAfter(me : in out ; anitem : Integer;
+                              IsOpenResult : Boolean)
        --- Purpose : Creates the Reversed Tangent at the origin of the Item 
        --            defined by <anitem>. Returns the index of this vector in
        --            <theGeomVecs>
index 73efc72dd66d9175e302e3392e4bf0fa715af22b..8e149853ada6ec0b97be3f6a4a90bffa172a899e 100755 (executable)
@@ -199,13 +199,17 @@ Standard_Integer MAT2d_Tool2d::FirstPoint(const Standard_Integer anitem,
 //function : TangentBefore
 //purpose  :
 //=============================================================================
-Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem) 
+Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem,
+                                             const Standard_Boolean IsOpenResult)
 {
   Standard_Integer     item;
   Handle(Geom2d_Curve) curve;
   theNumberOfVecs++;
-  
-  item  = (anitem == theCircuit->NumberOfItems()) ? 1 : (anitem + 1);
+
+  if (!IsOpenResult)
+    item  = (anitem == theCircuit->NumberOfItems()) ? 1 : (anitem + 1);
+  else
+    item = (anitem == theCircuit->NumberOfItems()) ? (anitem - 1) : (anitem + 1);
   if (theCircuit->ConnexionOn(item)){
     Standard_Real x1,y1,x2,y2;
     theCircuit->Connexion(item)->PointOnFirst().Coord(x1,y1);
@@ -222,7 +226,9 @@ Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem)
   }
   else {
     curve = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(item));
-    theGeomVecs.Bind(theNumberOfVecs,curve->DN(curve->FirstParameter(),1));
+    Standard_Real param = (IsOpenResult && anitem == theCircuit->NumberOfItems())?
+      curve->LastParameter() : curve->FirstParameter();
+    theGeomVecs.Bind(theNumberOfVecs,curve->DN(param,1));
   }
 
   return theNumberOfVecs;
@@ -232,7 +238,8 @@ Standard_Integer MAT2d_Tool2d::TangentBefore(const Standard_Integer anitem)
 //function : TangentAfter
 //purpose  :
 //=============================================================================
-Standard_Integer MAT2d_Tool2d::TangentAfter(const Standard_Integer anitem)
+Standard_Integer MAT2d_Tool2d::TangentAfter(const Standard_Integer anitem,
+                                            const Standard_Boolean IsOpenResult)
 {
   Standard_Integer     item;
   Handle(Geom2d_Curve) curve;
@@ -254,9 +261,14 @@ Standard_Integer MAT2d_Tool2d::TangentAfter(const Standard_Integer anitem)
     thevector = curve->DN(curve->FirstParameter(),1);
   }
   else {
-    item      = (anitem == 1) ? theCircuit->NumberOfItems() : (anitem - 1);
+    if (!IsOpenResult)
+      item      = (anitem == 1) ? theCircuit->NumberOfItems() : (anitem - 1);
+    else
+      item = (anitem == 1) ? 2 : (anitem - 1);
     curve     = Handle(Geom2d_Curve)::DownCast(theCircuit->Value(item));
-    thevector = curve->DN(curve->LastParameter(),1);
+    Standard_Real param = (IsOpenResult && anitem == 1)?
+      curve->FirstParameter() : curve->LastParameter();
+    thevector = curve->DN(param,1);
   }
   theGeomVecs.Bind(theNumberOfVecs,thevector.Reversed());
   return theNumberOfVecs;