0031301: Data Exchange - Export to STEP corrupts the shape
[occt.git] / src / GeomToStep / GeomToStep_MakeCurve.cxx
1 // Created on: 1993-06-21
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Geom2d_BoundedCurve.hxx>
19 #include <Geom2d_BSplineCurve.hxx>
20 #include <Geom2d_Circle.hxx>
21 #include <Geom2d_Conic.hxx>
22 #include <Geom2d_Curve.hxx>
23 #include <Geom2d_Ellipse.hxx>
24 #include <Geom2d_Line.hxx>
25 #include <Geom2dConvert.hxx>
26 #include <Geom_BezierCurve.hxx>
27 #include <Geom_BoundedCurve.hxx>
28 #include <Geom_BSplineCurve.hxx>
29 #include <Geom_Conic.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom_Line.hxx>
32 #include <Geom_TrimmedCurve.hxx>
33 #include <GeomToStep_MakeBoundedCurve.hxx>
34 #include <GeomToStep_MakeConic.hxx>
35 #include <GeomToStep_MakeCurve.hxx>
36 #include <GeomToStep_MakeLine.hxx>
37 #include <gp_Circ2d.hxx>
38 #include <gp_Elips2d.hxx>
39 #include <StdFail_NotDone.hxx>
40 #include <StepGeom_Axis2Placement3d.hxx>
41 #include <StepGeom_BoundedCurve.hxx>
42 #include <StepGeom_Conic.hxx>
43 #include <StepGeom_Curve.hxx>
44 #include <StepGeom_Line.hxx>
45 #include <Geom2d_TrimmedCurve.hxx>
46
47 //=============================================================================
48 // Creation d' une Curve de prostep a partir d' une Curve de Geom
49 //=============================================================================
50 GeomToStep_MakeCurve::GeomToStep_MakeCurve ( const Handle(Geom_Curve)& C)
51 {
52   done = Standard_True;
53   if (C->IsKind(STANDARD_TYPE(Geom_Line))) {
54     Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(C);
55     GeomToStep_MakeLine MkLine(L);
56     theCurve = MkLine.Value();
57   }
58   else if (C->IsKind(STANDARD_TYPE(Geom_Conic))) {
59     Handle(Geom_Conic) L = Handle(Geom_Conic)::DownCast(C);
60     GeomToStep_MakeConic MkConic(L);
61     theCurve = MkConic.Value();
62   }
63   else if (C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
64     Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(C);
65     Handle(Geom_Curve) B = T->BasisCurve();
66 //    TANT PIS, on passe la courbe de base ...
67     if (B->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
68       Handle(Geom_BSplineCurve) BS = Handle(Geom_BSplineCurve)::DownCast
69         (B->Copy());
70       BS->Segment (T->FirstParameter(),T->LastParameter());
71       B = BS;
72     }
73     else if (B->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
74       Handle(Geom_BezierCurve) BZ = Handle(Geom_BezierCurve)::DownCast
75         (B->Copy());
76       BZ->Segment (T->FirstParameter(),T->LastParameter());
77       B = BZ;
78     }
79     else {
80 #ifdef OCCT_DEBUG
81       std::cout<<"GeomToStep_MakeCurve, TrimmedCurve, BasisCurve is transferred not trimmed"<<std::endl;
82       std::cout<<"BasisCurve Type : "<<B->DynamicType()->Name()<<std::endl;
83 #endif
84     }
85     GeomToStep_MakeCurve MkBasisC(B);
86     theCurve = MkBasisC.Value();
87   }
88   else if (C->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
89     Handle(Geom_BoundedCurve) L = Handle(Geom_BoundedCurve)::DownCast(C);
90     GeomToStep_MakeBoundedCurve MkBoundedC(L);
91     theCurve = MkBoundedC.Value();
92   }
93   else
94     done = Standard_False;
95 }        
96
97 //=============================================================================
98 // Creation d'une Curve de prostep a partir d' une Curve de Geom2d
99 //=============================================================================
100
101 GeomToStep_MakeCurve::GeomToStep_MakeCurve ( const Handle(Geom2d_Curve)& C)
102 {
103   done = Standard_True;
104   if (C->IsKind(STANDARD_TYPE(Geom2d_Line))) {
105     Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C);
106     GeomToStep_MakeLine MkLine(L);
107     theCurve = MkLine.Value();
108   }
109   else if (C->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
110
111     // ----------------------------------------------------------------------
112     // A Circle of an Ellipse can be indirect. An indirect Axis in not 
113     // mappable onto STEP. Then to avoid changing the topology, the Circle 
114     // or the Ellipse are converted into BSpline Curves
115     // ----------------------------------------------------------------------
116     
117     if (C->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
118       Handle(Geom2d_Circle) theC2d = Handle(Geom2d_Circle)::DownCast(C);
119       gp_Circ2d C2d = theC2d->Circ2d();
120       if (!C2d.IsDirect()) {
121 #ifdef OCCT_DEBUG
122         std::cout << "Warning : Circle converted to BSpline." << std::endl;
123 #endif
124         Handle(Geom2d_BSplineCurve) aBSplineCurve2d = 
125           Geom2dConvert::CurveToBSplineCurve(theC2d);
126         const Handle(Geom2d_BoundedCurve)& aBC2d = aBSplineCurve2d; // to avoid ambiguity
127         GeomToStep_MakeBoundedCurve MkBoundedC(aBC2d);
128         theCurve = MkBoundedC.Value();
129       }
130       else {
131         Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
132         GeomToStep_MakeConic MkConic(L);
133         theCurve = MkConic.Value();
134       }
135     }
136     else if (C->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
137       Handle(Geom2d_Ellipse) theE2d = Handle(Geom2d_Ellipse)::DownCast(C);
138       gp_Elips2d E2d = theE2d->Elips2d();
139       if (!E2d.IsDirect()) {
140 #ifdef OCCT_DEBUG
141         std::cout << "Warning : Ellipse converted to BSpline." << std::endl;
142 #endif
143         Handle(Geom2d_BSplineCurve) aBSplineCurve2d = 
144           Geom2dConvert::CurveToBSplineCurve(theE2d);
145         const Handle(Geom2d_BoundedCurve)& aBC2d = aBSplineCurve2d; // to avoid ambiguity
146         GeomToStep_MakeBoundedCurve MkBoundedC(aBC2d);
147         theCurve = MkBoundedC.Value();
148       }
149       else {
150         Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
151         GeomToStep_MakeConic MkConic(L);
152         theCurve = MkConic.Value();
153       }
154     }
155     else {
156       Handle(Geom2d_Conic) L = Handle(Geom2d_Conic)::DownCast(C);
157       GeomToStep_MakeConic MkConic(L);
158       theCurve = MkConic.Value();
159     }
160   }
161   else if (C->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve))) {
162     Handle(Geom2d_BoundedCurve) L = Handle(Geom2d_BoundedCurve)::DownCast(C);
163     GeomToStep_MakeBoundedCurve MkBoundedC(L);
164     theCurve = MkBoundedC.Value();
165   }
166   else if (C->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
167     GeomToStep_MakeCurve aMaker = (Handle(Geom2d_TrimmedCurve)::DownCast(C)->BasisCurve());
168     theCurve = aMaker.Value();
169   }
170   else
171     done = Standard_False;
172
173
174
175 //=============================================================================
176 // renvoi des valeurs
177 //=============================================================================
178
179 const Handle(StepGeom_Curve) &
180       GeomToStep_MakeCurve::Value() const
181 {
182   StdFail_NotDone_Raise_if (!done, "GeomToStep_MakeCurve::Value() - no result");
183   return theCurve;
184 }