0022898: IGES import fails in german environment
[occt.git] / src / SWDRAW / SWDRAW_ShapeFix.cxx
index 6c8ea3e..a5051be 100755 (executable)
@@ -1,10 +1,26 @@
-// File:       SWDRAW_ShapeFix.cxx
-// Created:    Tue Mar  9 15:49:13 1999
-// Author:     data exchange team
-//             <det@kinox.nnov.matra-dtv.fr>
-
+// Created on: 1999-03-09
+// Created by: data exchange team
+// Copyright (c) 1999-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
 
 #include <SWDRAW_ShapeFix.ixx>
+
+#include <Draw.hxx>
 #include <DBRep.hxx>
 #include <SWDRAW.hxx>
 #include <gp_XYZ.hxx>
 #include <TopAbs_State.hxx>
 
 #include <Draw_ProgressIndicator.hxx>
+#include <ShapeAnalysis_FreeBounds.hxx>
+#include <TopTools_HSequenceOfShape.hxx>
+#include <BRep_Builder.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopExp.hxx>
 
 #ifdef AIX
 #include <strings.h>
@@ -104,10 +125,10 @@ static Standard_Integer settolerance (Draw_Interpretor& di, Standard_Integer arg
 
   Standard_Real tmin,tmax;
   mod2 = argv[premarg][0];
-  if (mod2 == '=') tmin = tmax = atof (argv[argc-1]);
-  else if (mod2 == '<') { tmin = 0; tmax = atof (argv[argc-1]); }
-  else if (mod2 == '>') { tmin = atof (argv[argc-1]); tmax = 0; }
-  else { tmin = atof (argv[premarg]);  tmax = atof (argv[argc-1]); }
+  if (mod2 == '=') tmin = tmax = Draw::Atof (argv[argc-1]);
+  else if (mod2 == '<') { tmin = 0; tmax = Draw::Atof (argv[argc-1]); }
+  else if (mod2 == '>') { tmin = Draw::Atof (argv[argc-1]); tmax = 0; }
+  else { tmin = Draw::Atof (argv[premarg]);  tmax = Draw::Atof (argv[argc-1]); }
 
   if (argc == premarg + 1 || tmin == tmax) di<<"Setting Tolerance to "<<tmin<<"\n";
   else if (tmax < tmin) di<<"Minimum Tolerance to "<<tmin<<"\n";
@@ -418,8 +439,8 @@ static Standard_Integer fixshape (Draw_Interpretor& di, Standard_Integer argc, c
         if(initShape.IsNull()) continue;
         sfs->Init ( initShape );
       } break;
-      case 2: sfs->SetPrecision   (atof(argv[i])); break;
-      case 3: sfs->SetMaxTolerance(atof(argv[i])); break;
+      case 2: sfs->SetPrecision   (Draw::Atof(argv[i])); break;
+      case 3: sfs->SetMaxTolerance(Draw::Atof(argv[i])); break;
       }
     }
     par++;
@@ -487,7 +508,7 @@ static Standard_Integer fixshape (Draw_Interpretor& di, Standard_Integer argc, c
     if ( mess < 0 )
     {
       char buff[256];
-      sprintf ( buff, "%s_%s", res, "m" );
+      Sprintf ( buff, "%s_%s", res, "m" );
       di << " Modified shapes saved in compound: " << buff;
       DBRep::Set (buff, aCompound);
     }
@@ -512,7 +533,7 @@ Standard_Integer fixgaps(Draw_Interpretor& di, Standard_Integer n, const char**
   }
 
   Handle(ShapeFix_Wireframe) SFWF = new ShapeFix_Wireframe(S);
-  Standard_Real prec = ( n >3 ? atof(a[3]) : 0. );
+  Standard_Real prec = ( n >3 ? Draw::Atof(a[3]) : 0. );
   SFWF->SetPrecision(prec);
   if ( SFWF->FixWireGaps() ) {
     DBRep::Set(a[1],SFWF->Shape());
@@ -537,7 +558,7 @@ Standard_Integer fixsmall(Draw_Interpretor& di, Standard_Integer n, const char**
     return 1;
   }
 
-  Standard_Real prec = (n == 4)? atof(a[3]) : 1.;
+  Standard_Real prec = (n == 4)? Draw::Atof(a[3]) : 1.;
   ShapeFix_Wireframe SFWF(S);
   SFWF.SetPrecision(prec);
   
@@ -567,13 +588,13 @@ static Standard_Integer fixsmalledges(Draw_Interpretor& di, Standard_Integer n,
   Standard_Integer mode = 2;
   Standard_Real tolang = M_PI/2;
   if(n > k) 
-    tol = atof(a[k++]);
+    tol = Draw::Atof(a[k++]);
   
   if(n > k) 
-    mode=  atoi(a[k++]);
+    mode=  Draw::Atoi(a[k++]);
    
   if(n > k) 
-    tolang = atof(a[k++]);
+    tolang = Draw::Atof(a[k++]);
      
   Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe();
   Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape;
@@ -621,9 +642,9 @@ static Standard_Integer checkoverlapedges(Draw_Interpretor& di, Standard_Integer
    Standard_Real aDistDomain = 0.0;
    Standard_Integer k = 3;
    if(k < n)
-     aTol = atof(a[k++]);
+     aTol = Draw::Atof(a[k++]);
    if(k < n)
-     aDistDomain = atof(a[k++]);
+     aDistDomain = Draw::Atof(a[k++]);
    
    ShapeAnalysis_Edge sae;
    if(sae.CheckOverlapping(e1,e2,aTol,aDistDomain)) {
@@ -651,8 +672,8 @@ static Standard_Integer checkfclass2d(Draw_Interpretor& di, Standard_Integer n,
     return 1;
   }
   TopoDS_Shape Sh1 = DBRep::Get(a[1]);
-  Standard_Real ucoord = atof(a[2]);
-  Standard_Real vcoord = atof(a[3]);
+  Standard_Real ucoord = Draw::Atof(a[2]);
+  Standard_Real vcoord = Draw::Atof(a[3]);
   if(Sh1.IsNull() || Sh1.ShapeType()!= TopAbs_FACE) {
     di<<"Invalid arguments"<<"\n";
     return 1;
@@ -672,6 +693,69 @@ static Standard_Integer checkfclass2d(Draw_Interpretor& di, Standard_Integer n,
   return 0;
 }
 
+static Standard_Integer connectedges(Draw_Interpretor& di, Standard_Integer n, const char** a)
+{
+  if( n < 3) {
+    di<<"Invalid number of arguments. Should be : result shape [toler shared]"<<"\n";
+    return 1;
+  }
+  TopoDS_Shape aSh1 = DBRep::Get(a[2]);
+  if(aSh1.IsNull()) {
+    di<<"Shape is null"<<"\n";
+    return 1;
+  }
+  Standard_Real aTol = Precision::Confusion();
+  if( n > 3)
+    aTol = Draw::Atof(a[3]);
+  
+  Standard_Boolean shared = Standard_True;
+  if( n > 4)
+    shared = (Draw::Atoi(a[4]) == 1);
+  TopExp_Explorer aExpE(aSh1,TopAbs_EDGE);
+  Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
+  Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
+  TopTools_IndexedMapOfShape aMapEdges;
+  for( ; aExpE.More(); aExpE.Next())
+  {
+    aSeqEdges->Append(aExpE.Current());
+    aMapEdges.Add(aExpE.Current());
+  }
+  
+  ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,aTol,shared,aSeqWires );
+  TopoDS_Compound aComp;
+  BRep_Builder aB;
+  aB.MakeCompound(aComp);
+  Standard_Integer i = 1;
+  for( ; i <= aSeqWires->Length() ; i++)
+  {
+    TopoDS_Shape aW = aSeqWires->Value(i);
+    di<<"Wire - "<<i<<" : "<<"\n";
+    
+    TopExp_Explorer aExp1(aW, TopAbs_EDGE);
+    for( ; aExp1.More(); aExp1.Next())
+    {
+      if(shared)
+      {
+        Standard_Integer ind = aMapEdges.FindIndex(aExp1.Current());
+        di<<ind<<" ";
+      }
+       else
+      {
+        TopoDS_Vertex aV1, aV2;
+        TopExp::Vertices(TopoDS::Edge(aExp1.Current()), aV1,aV2);
+        gp_Pnt aP = BRep_Tool::Pnt(aV1);
+        di<<aP.X()<<" "<<aP.Y()<<" "<<aP.Z()<<"\n";
+      }
+    }
+   
+    di<<"\n";
+    aB.Add( aComp,aSeqWires->Value(i));
+  }
+  DBRep::Set(a[1],aComp);
+  return 0;
+  
+}
+
 //=======================================================================
 //function : InitCommands
 //purpose  : 
@@ -706,5 +790,8 @@ static Standard_Integer checkfclass2d(Draw_Interpretor& di, Standard_Integer n,
                   __FILE__,checkoverlapedges,g);
   theCommands.Add ("checkfclass2d","face ucoord vcoord",
                   __FILE__,checkfclass2d,g);
+  theCommands.Add ("connectedges","res shape [toler shared]",
+                  __FILE__,connectedges,g);
+  
 }