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