0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Geom2d / Geom2d_TrimmedCurve.cxx
CommitLineData
b311480e 1// Created on: 1993-03-24
2// Created by: JCV
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
42cf5bc1 17
18#include <ElCLib.hxx>
7fd59977 19#include <Geom2d_BezierCurve.hxx>
42cf5bc1 20#include <Geom2d_BSplineCurve.hxx>
42cf5bc1 21#include <Geom2d_Curve.hxx>
42cf5bc1 22#include <Geom2d_Geometry.hxx>
42cf5bc1 23#include <Geom2d_OffsetCurve.hxx>
42cf5bc1 24#include <Geom2d_TrimmedCurve.hxx>
25#include <Geom2d_UndefinedDerivative.hxx>
42cf5bc1 26#include <gp.hxx>
27#include <gp_Pnt2d.hxx>
28#include <gp_Trsf2d.hxx>
29#include <gp_Vec2d.hxx>
30#include <Precision.hxx>
7fd59977 31#include <Standard_ConstructionError.hxx>
32#include <Standard_RangeError.hxx>
42cf5bc1 33#include <Standard_Type.hxx>
7fd59977 34
92efcf78 35IMPLEMENT_STANDARD_RTTIEXT(Geom2d_TrimmedCurve,Geom2d_BoundedCurve)
36
7fd59977 37typedef Geom2d_TrimmedCurve TrimmedCurve;
7fd59977 38typedef gp_Ax2d Ax2d;
39typedef gp_Pnt2d Pnt2d;
40typedef gp_Trsf2d Trsf2d;
41typedef gp_Vec2d Vec2d;
42
7fd59977 43//=======================================================================
44//function : Copy
45//purpose :
46//=======================================================================
47
48Handle(Geom2d_Geometry) Geom2d_TrimmedCurve::Copy () const
49{
c04c30b3 50 Handle(Geom2d_TrimmedCurve) Tc;
7fd59977 51 Tc = new TrimmedCurve (basisCurve, uTrim1, uTrim2);
52 return Tc;
53}
54
55//=======================================================================
56//function : Geom2d_TrimmedCurve
57//purpose :
58//=======================================================================
59
60Geom2d_TrimmedCurve::Geom2d_TrimmedCurve (const Handle(Geom2d_Curve)& C,
8ac0cf52 61 const Standard_Real U1,
62 const Standard_Real U2,
63 const Standard_Boolean Sense,
64 const Standard_Boolean theAdjustPeriodic) :
7fd59977 65 uTrim1 (U1),
66 uTrim2 (U2)
67{
9775fa61 68 if(C.IsNull()) throw Standard_ConstructionError("Geom2d_TrimmedCurve:: C is null");
7fd59977 69 // kill trimmed basis curves
70 Handle(Geom2d_TrimmedCurve) T = Handle(Geom2d_TrimmedCurve)::DownCast(C);
71 if (!T.IsNull())
c04c30b3 72 basisCurve = Handle(Geom2d_Curve)::DownCast(T->BasisCurve()->Copy());
7fd59977 73 else
c04c30b3 74 basisCurve = Handle(Geom2d_Curve)::DownCast(C->Copy());
7fd59977 75
8ac0cf52 76 SetTrim(U1, U2, Sense, theAdjustPeriodic);
7fd59977 77}
78
79//=======================================================================
80//function : Reverse
81//purpose :
82//=======================================================================
83
84void Geom2d_TrimmedCurve::Reverse ()
85{
86 Standard_Real U1 = basisCurve->ReversedParameter(uTrim2);
87 Standard_Real U2 = basisCurve->ReversedParameter(uTrim1);
88 basisCurve->Reverse();
8ac0cf52 89 SetTrim(U1, U2, Standard_True, Standard_False);
7fd59977 90}
91
92//=======================================================================
a25d5aaa 93//function : ReversedParameter
7fd59977 94//purpose :
95//=======================================================================
96
97Standard_Real Geom2d_TrimmedCurve::ReversedParameter( const Standard_Real U) const
98{
99 return basisCurve->ReversedParameter(U);
100}
101
102//=======================================================================
103//function : SetTrim
104//purpose :
105//=======================================================================
106
8ac0cf52 107void Geom2d_TrimmedCurve::SetTrim (const Standard_Real U1,
108 const Standard_Real U2,
109 const Standard_Boolean Sense,
110 const Standard_Boolean theAdjustPeriodic)
7fd59977 111{
112 Standard_Boolean sameSense = Standard_True;
113 if (U1 == U2)
9775fa61 114 throw Standard_ConstructionError("Geom2d_TrimmedCurve::U1 == U2");
7fd59977 115
116 Standard_Real Udeb = basisCurve->FirstParameter();
117 Standard_Real Ufin = basisCurve->LastParameter();
118
119 if (basisCurve->IsPeriodic()) {
120 sameSense = Sense;
121
122 // set uTrim1 in the range Udeb , Ufin
123 // set uTrim2 in the range uTrim1 , uTrim1 + Period()
124 uTrim1 = U1;
8ac0cf52 125 uTrim2 = U2;
126 if (theAdjustPeriodic)
127 ElCLib::AdjustPeriodic(Udeb, Ufin,
128 Min(Abs(uTrim2-uTrim1)/2,Precision::PConfusion()),
129 uTrim1, uTrim2);
7fd59977 130 }
131 else {
132 if (U1 < U2) {
133 sameSense = Sense;
134 uTrim1 = U1;
135 uTrim2 = U2;
136 }
137 else {
138 sameSense = !Sense;
139 uTrim1 = U2;
140 uTrim2 = U1;
141 }
142
143 if ((Udeb - uTrim1 > Precision::PConfusion()) ||
144 (uTrim2 - Ufin > Precision::PConfusion())) {
9775fa61 145 throw Standard_ConstructionError("Geom_TrimmedCurve::parameters out of range");
7fd59977 146 }
147 }
148
149 if (!sameSense)
150 Reverse();
151}
152
153//=======================================================================
154//function : BasisCurve
155//purpose :
156//=======================================================================
157
c04c30b3 158Handle(Geom2d_Curve) Geom2d_TrimmedCurve::BasisCurve () const
7fd59977 159{
160 return basisCurve;
161}
162
163//=======================================================================
164//function : Continuity
165//purpose :
166//=======================================================================
167
168GeomAbs_Shape Geom2d_TrimmedCurve::Continuity () const
169{
170 return basisCurve->Continuity();
171}
172
173//=======================================================================
174//function : IsCN
175//purpose :
176//=======================================================================
177
178Standard_Boolean Geom2d_TrimmedCurve::IsCN (const Standard_Integer N) const
179{
180 Standard_RangeError_Raise_if (N < 0, " ");
181 return basisCurve->IsCN (N);
182}
183
184//=======================================================================
185//function : EndPoint
186//purpose :
187//=======================================================================
188
189Pnt2d Geom2d_TrimmedCurve::EndPoint () const
190{
191 return basisCurve->Value(uTrim2);
192}
193
194//=======================================================================
195//function : FirstParameter
196//purpose :
197//=======================================================================
198
199Standard_Real Geom2d_TrimmedCurve::FirstParameter () const { return uTrim1; }
200
201//=======================================================================
202//function : IsClosed
203//purpose :
204//=======================================================================
205
206Standard_Boolean Geom2d_TrimmedCurve::IsClosed () const
207{
208 Standard_Real Dist =
209 Value(FirstParameter()).Distance(Value(LastParameter()));
210 return ( Dist <= gp::Resolution());
211}
212
213//=======================================================================
214//function : IsPeriodic
215//purpose :
216//=======================================================================
217
218Standard_Boolean Geom2d_TrimmedCurve::IsPeriodic () const
219{
220 //return basisCurve->IsPeriodic();
221 return Standard_False;
222}
223
224//=======================================================================
225//function : Period
226//purpose :
227//=======================================================================
228
229Standard_Real Geom2d_TrimmedCurve::Period () const
230{
231 return basisCurve->Period();
232}
233
234//=======================================================================
235//function : LastParameter
236//purpose :
237//=======================================================================
238
239Standard_Real Geom2d_TrimmedCurve::LastParameter () const { return uTrim2; }
240
241//=======================================================================
242//function : StartPoint
243//purpose :
244//=======================================================================
245
246Pnt2d Geom2d_TrimmedCurve::StartPoint () const
247{
248 gp_Pnt2d P;
249 P = basisCurve->Value(uTrim1);
250 return P;
251}
252
253//=======================================================================
254//function : D0
255//purpose :
256//=======================================================================
257
258void Geom2d_TrimmedCurve::D0 (const Standard_Real U,
259 Pnt2d& P ) const {
260 basisCurve->D0(U, P);
261}
262
263//=======================================================================
264//function : D1
265//purpose :
266//=======================================================================
267
268void Geom2d_TrimmedCurve::D1 (const Standard_Real U, Pnt2d& P, Vec2d& V1) const
269{
270 basisCurve->D1 (U, P, V1);
271}
272
273//=======================================================================
274//function : D2
275//purpose :
276//=======================================================================
277
278void Geom2d_TrimmedCurve::D2 (const Standard_Real U,
279 Pnt2d& P,
280 Vec2d& V1, Vec2d& V2) const
281{
282 basisCurve->D2 (U, P, V1, V2);
283}
284
285//=======================================================================
286//function : D3
287//purpose :
288//=======================================================================
289
290void Geom2d_TrimmedCurve::D3 (const Standard_Real U,
291 Pnt2d& P,
292 Vec2d& V1, Vec2d& V2, Vec2d& V3) const
293{
294 basisCurve->D3 (U, P, V1, V2, V3);
295}
296
297//=======================================================================
298//function : DN
299//purpose :
300//=======================================================================
301
302Vec2d Geom2d_TrimmedCurve::DN (const Standard_Real U, const Standard_Integer N) const
303{
304 return basisCurve->DN(U, N);
305}
306
307//=======================================================================
308//function : Transform
309//purpose :
310//=======================================================================
311
312void Geom2d_TrimmedCurve::Transform (const Trsf2d& T)
313{
314 basisCurve->Transform (T);
315 Standard_Real U1 = basisCurve->TransformedParameter(uTrim1,T);
316 Standard_Real U2 = basisCurve->TransformedParameter(uTrim2,T);
8ac0cf52 317 SetTrim(U1, U2, Standard_True, Standard_False);
7fd59977 318}
319
320//=======================================================================
321//function : TransformedParameter
322//purpose :
323//=======================================================================
324
325Standard_Real Geom2d_TrimmedCurve::TransformedParameter(const Standard_Real U,
326 const gp_Trsf2d& T) const
327{
328 return basisCurve->TransformedParameter(U,T);
329}
330
331//=======================================================================
332//function : ParametricTransformation
333//purpose :
334//=======================================================================
335
336Standard_Real Geom2d_TrimmedCurve::ParametricTransformation(const gp_Trsf2d& T) const
337{
338 return basisCurve->ParametricTransformation(T);
339}
340
bc73b006 341//=======================================================================
342//function : DumpJson
343//purpose :
344//=======================================================================
345void Geom2d_TrimmedCurve::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
346{
347 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
348
349 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom2d_BoundedCurve)
350
351 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, basisCurve.get())
352 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, uTrim1)
353 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, uTrim2)
354}