summaryrefslogtreecommitdiff
path: root/src/IGESToBRep/project.pxx
blob: a7d8c06a1cb2bc4c08c478e1a5b260587acd4529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <GeomAbs_CurveType.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <GeomAdaptor_HCurve.hxx>
#include <GeomAdaptor_HSurface.hxx>
#include <ProjLib_ProjectedCurve.hxx>
#include <Geom_TrimmedCurve.hxx>

#include <gp_Lin2d.hxx>
#include <gp_Circ2d.hxx>
#include <gp_Elips2d.hxx>
#include <gp_Hypr2d.hxx>
#include <gp_Parab2d.hxx>


Standard_Boolean  IGESToBRep_TopoCurve::Project(TopoDS_Wire& wir, 
						const TopoDS_Face& face)
{

  //  Creation du GeomAdaptor pour la surface support :
  //  =================================================

  if (face.IsNull() || wir.IsNull()) return Standard_False;
  TopLoc_Location          SrfLoc;
  Handle(Geom_Surface)     Srf = BRep_Tool::Surface(face,SrfLoc);
  Standard_Real            UMin, UMax, VMin, VMax;
  BRepTools::UVBounds(face,UMin, UMax, VMin, VMax);
  GeomAdaptor_Surface      GASrf(Srf, UMin, UMax, VMin, VMax);


  //  Creation des GeomAdaptors pour mettre a jour les edges du wire :
  //  ================================================================

  BRep_Builder  B;
  for (TopoDS_Iterator  Iter(wir); Iter.More(); Iter.Next()) {

    Standard_Integer  num = 1;
    TopoDS_Shape      Sh  = Iter.Value();
    if (Sh.IsNull() || Sh.ShapeType()!=TopAbs_EDGE)
      continue;

    TopoDS_Edge                 E = TopoDS::Edge(Sh);
    TopLoc_Location             L;
    Standard_Real               a,b;
    Handle(Geom_Curve)          C = BRep_Tool::Curve(E,L,a,b);
    GeomAdaptor_Curve           GACrv(C,a,b);


    //  Test of the 3d curve type :
    //  ===========================

    ProjLib_ProjectedCurve  PrjCrv;
    GeomAbs_CurveType           CrvTpe = GACrv.GetType();
    if (CrvTpe==GeomAbs_BezierCurve  ||
	CrvTpe==GeomAbs_BSplineCurve ||
	CrvTpe==GeomAbs_OtherCurve) {
      return  Standard_False;
    }
    else {
      PrjCrv = ProjLib_ProjectedCurve
	(new GeomAdaptor_HSurface(GASrf),
	 new GeomAdaptor_HCurve(GACrv));

      CrvTpe = PrjCrv.GetType();
    }

    //  Test of the 2d curve type :
    //  ===========================

    switch (CrvTpe) {

    case GeomAbs_Line :
      {
	gp_Lin2d  Lin = PrjCrv.Line();
	Handle(Geom2d_Line)  GLin = new Geom2d_Line(Lin);
	B.UpdateEdge(E,GLin,face,GetEpsGeom());
	B.Range(E,face,a,b);
      }
      break;
    case GeomAbs_Circle :
      {
	gp_Circ2d  C = PrjCrv.Circle();
	Handle(Geom2d_Circle)  GC = new Geom2d_Circle(C);
	B.UpdateEdge(E,GC,face,GetEpsGeom());
	B.Range(E,face,a,b);
      }
      break;
    case GeomAbs_Ellipse :
      {
	gp_Elips2d  Elps = PrjCrv.Ellipse();
	Handle(Geom2d_Ellipse)  GElps = new Geom2d_Ellipse(Elps);
	B.UpdateEdge(E,GElps,face,GetEpsGeom());
	B.Range(E,face,a,b);
      }
      break;
    case GeomAbs_Hyperbola :
      {
	gp_Hypr2d  H = PrjCrv.Hyperbola();
	Handle(Geom2d_Hyperbola)  GH = new Geom2d_Hyperbola(H);
	B.UpdateEdge(E,GH,face,GetEpsGeom());
	B.Range(E,face,a,b);
      }
      break;
    case GeomAbs_Parabola :
      {
	gp_Parab2d  P = PrjCrv.Parabola();
	Handle(Geom2d_Parabola)  GP = new Geom2d_Parabola(P);
	B.UpdateEdge(E,GP,face,GetEpsGeom());
	B.Range(E,face,a,b);
      }
      break;
    default :
      {
	return  Standard_False;
      }
      break;
    }
  }

  return  Standard_True;
  
}