summaryrefslogtreecommitdiff
path: root/src/GeomToStep/GeomToStep_MakeCurve.cxx
blob: c2444da26395b447135257f14d369ad2ec836747 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// File:	GeomToStep_MakeCurve.cxx
// Created:	Mon Jun 21 10:20:35 1993
// Author:	Martine LANGLOIS
//		<mla@mastox>

#include <GeomToStep_MakeCurve.ixx>
#include <StdFail_NotDone.hxx>
#include <StepGeom_Curve.hxx>
#include <GeomToStep_MakeCurve.hxx>
#include <Geom_Line.hxx>
#include <Geom2d_Line.hxx>
#include <GeomToStep_MakeLine.hxx>
#include <Geom_Conic.hxx>
#include <Geom2d_Conic.hxx>
#include <GeomToStep_MakeConic.hxx>
#include <Geom_BoundedCurve.hxx>
#include <Geom2d_BoundedCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <GeomToStep_MakeBoundedCurve.hxx>

#include <Geom_TrimmedCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_BezierCurve.hxx>

#include <Geom2dConvert.hxx>
#include <Geom2d_Circle.hxx>
#include <gp_Circ2d.hxx>
#include <Geom2d_Ellipse.hxx>
#include <gp_Elips2d.hxx>

//=============================================================================
// Creation d' une Curve de prostep a partir d' une Curve de Geom
//=============================================================================

GeomToStep_MakeCurve::GeomToStep_MakeCurve ( const Handle(Geom_Curve)& C)
{
  done = Standard_True;
  if (C->IsKind(STANDARD_TYPE(Geom_Line))) {
    Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(C);
    GeomToStep_MakeLine MkLine(L);
    theCurve = MkLine.Value();
  }
  else if (C->IsKind(STANDARD_TYPE(Geom_Conic))) {
    Handle(Geom_Conic) L = Handle(Geom_Conic)::DownCast(C);
    GeomToStep_MakeConic MkConic(L);
    theCurve = MkConic.Value();
  }
  else if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
    Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(C);
    Handle(Geom_Curve) B = T->BasisCurve();
//    TANT PIS, on passe la courbe de base ...
    if (B->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
      Handle(Geom_BSplineCurve) BS = Handle(Geom_BSplineCurve)::DownCast
	(B->Copy());
      BS->Segment (T->FirstParameter(),T->LastParameter());
      B = BS;
    }
    else if (B->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
      Handle(Geom_BezierCurve) BZ = Handle(Geom_BezierCurve)::DownCast
	(B->Copy());
      BZ->Segment (T->FirstParameter(),T->LastParameter());
      B = BZ;
    }
    else {
#ifdef DEB
      cout<<"GeomToStep_MakeCurve, TrimmedCurve, BasisCurve is transferred not trimmed"<<endl;
      cout<<"BasisCurve Type : "<<B->DynamicType()->Name()<<endl;
#endif
    }
    GeomToStep_MakeCurve MkBasisC(B);
    theCurve = MkBasisC.Value();
  }
  else if (C->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
    Handle(Geom_BoundedCurve) L = Handle(Geom_BoundedCurve)::DownCast(C);
    GeomToStep_MakeBoundedCurve MkBoundedC(L);
    theCurve = MkBoundedC.Value();
  }
  else
    done = Standard_False;
}	 

//=============================================================================
// Creation d'une Curve de prostep a partir d' une Curve de Geom2d
//=============================================================================

GeomToStep_MakeCurve::GeomToStep_MakeCurve ( const Handle(Geom2d_Curve)& C)
{
  done = Standard_True;
  if (C->IsKind(STANDARD_TYPE(Geom2d_Line))) {
    Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C);
    GeomToStep_MakeLine MkLine(L);
    theCurve = MkLine.Value();
  }
  else if (C->IsKind(STANDARD_TYPE(Geom2d_Conic))) {

    // ----------------------------------------------------------------------
    // A Circle of an Ellipse can be indirect. An indirect Axis in not 
    // mappable onto STEP. Then to avoid changing the topology, the Circle 
    // or the Ellipse are converted into BSpline Curves
    // ----------------------------------------------------------------------
    
    if (C->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
      Handle(Geom2d_Circle) theC2d = Handle(Geom2d_Circle)::DownCast(C);
      gp_Circ2d C2d = theC2d->Circ2d();
      if (!C2d.IsDirect()) {
#ifdef DEB
	cout << "Warning : Circle converted to BSpline." << endl;
#endif
	Handle(Geom2d_BSplineCurve) aBSplineCurve2d = 
	  Geom2dConvert::CurveToBSplineCurve(theC2d);
	GeomToStep_MakeBoundedCurve MkBoundedC(aBSplineCurve2d);
	theCurve = MkBoundedC.Value();
      }
      else {
	Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
	GeomToStep_MakeConic MkConic(L);
	theCurve = MkConic.Value();
      }
    }
    else if (C->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
      Handle(Geom2d_Ellipse) theE2d = Handle(Geom2d_Ellipse)::DownCast(C);
      gp_Elips2d E2d = theE2d->Elips2d();
      if (!E2d.IsDirect()) {
#ifdef DEB
	cout << "Warning : Ellipse converted to BSpline." << endl;
#endif
	Handle(Geom2d_BSplineCurve) aBSplineCurve2d = 
	  Geom2dConvert::CurveToBSplineCurve(theE2d);
	GeomToStep_MakeBoundedCurve MkBoundedC(aBSplineCurve2d);
	theCurve = MkBoundedC.Value();
      }
      else {
	Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
	GeomToStep_MakeConic MkConic(L);
	theCurve = MkConic.Value();
      }
    }
    else {
      Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
      GeomToStep_MakeConic MkConic(L);
      theCurve = MkConic.Value();
    }
  }
  else if (C->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve))) {
    Handle(Geom2d_BoundedCurve) L = Handle(Geom2d_BoundedCurve)::DownCast(C);
    GeomToStep_MakeBoundedCurve MkBoundedC(L);
    theCurve = MkBoundedC.Value();
  }
  else
    done = Standard_False;
} 


//=============================================================================
// renvoi des valeurs
//=============================================================================

const Handle(StepGeom_Curve) &
      GeomToStep_MakeCurve::Value() const
{
  StdFail_NotDone_Raise_if(!done == Standard_True,"");
  return theCurve;
}