0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Geom2d / Geom2d_OffsetCurve.cxx
CommitLineData
b311480e 1// Created on: 1991-06-25
2// Created by: JCV
3// Copyright (c) 1991-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// modified by Edward AGAPOV (eap) Jan 28 2002 --- DN(), occ143(BUC60654)
18
42cf5bc1 19#include <Geom2d_BezierCurve.hxx>
20#include <Geom2d_BSplineCurve.hxx>
42cf5bc1 21#include <Geom2d_Curve.hxx>
42cf5bc1 22#include <Geom2d_Geometry.hxx>
42cf5bc1 23#include <Geom2d_OffsetCurve.hxx>
7fd59977 24#include <Geom2d_TrimmedCurve.hxx>
42cf5bc1 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>
7fd59977 30#include <gp_XY.hxx>
3d58dc49 31#include <Precision.hxx>
42cf5bc1 32#include <Standard_ConstructionError.hxx>
42cf5bc1 33#include <Standard_NotImplemented.hxx>
34#include <Standard_RangeError.hxx>
35#include <Standard_Type.hxx>
7fd59977 36
f5f4ebd0 37IMPLEMENT_STANDARD_RTTIEXT(Geom2d_OffsetCurve,Geom2d_Curve)
7fd59977 38
3d58dc49 39static const Standard_Real MyAngularToleranceForG1 = Precision::Angular();
7fd59977 40
94f71cad 41
7fd59977 42//=======================================================================
43//function : Copy
44//purpose :
45//=======================================================================
46
47Handle(Geom2d_Geometry) Geom2d_OffsetCurve::Copy () const
48{
c04c30b3 49 Handle(Geom2d_OffsetCurve) C;
d660a72a 50 C = new Geom2d_OffsetCurve (basisCurve, offsetValue);
7fd59977 51 return C;
52}
53
54
55//=======================================================================
56//function : Geom2d_OffsetCurve
3d58dc49 57//purpose : Basis curve cannot be an Offset curve or trimmed from
58// offset curve.
7fd59977 59//=======================================================================
60
3d58dc49 61Geom2d_OffsetCurve::Geom2d_OffsetCurve (const Handle(Geom2d_Curve)& theCurve,
62 const Standard_Real theOffset,
63 const Standard_Boolean isTheNotCheckC0)
64: offsetValue (theOffset)
7fd59977 65{
3d58dc49 66 SetBasisCurve (theCurve, isTheNotCheckC0);
7fd59977 67}
68
69//=======================================================================
70//function : Reverse
71//purpose :
72//=======================================================================
73
74void Geom2d_OffsetCurve::Reverse ()
75{
76 basisCurve->Reverse();
77 offsetValue = -offsetValue;
78}
79
80//=======================================================================
81//function : ReversedParameter
82//purpose :
83//=======================================================================
84
85Standard_Real Geom2d_OffsetCurve::ReversedParameter( const Standard_Real U) const
86{
87 return basisCurve->ReversedParameter( U);
88}
89
90//=======================================================================
91//function : SetBasisCurve
92//purpose :
93//=======================================================================
94
c04c30b3 95void Geom2d_OffsetCurve::SetBasisCurve (const Handle(Geom2d_Curve)& C,
3d58dc49 96 const Standard_Boolean isNotCheckC0)
7fd59977 97{
3d58dc49 98 const Standard_Real aUf = C->FirstParameter(),
99 aUl = C->LastParameter();
100 Handle(Geom2d_Curve) aCheckingCurve = C;
101 Standard_Boolean isTrimmed = Standard_False;
102
103 while(aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)) ||
104 aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
105 {
106 if (aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
107 {
108 Handle(Geom2d_TrimmedCurve) aTrimC =
109 Handle(Geom2d_TrimmedCurve)::DownCast(aCheckingCurve);
110 aCheckingCurve = aTrimC->BasisCurve();
111 isTrimmed = Standard_True;
112 }
113
114 if (aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve)))
115 {
116 Handle(Geom2d_OffsetCurve) aOC =
117 Handle(Geom2d_OffsetCurve)::DownCast(aCheckingCurve);
118 aCheckingCurve = aOC->BasisCurve();
119 offsetValue += aOC->Offset();
120 }
121 }
122
123 myBasisCurveContinuity = aCheckingCurve->Continuity();
124
125 Standard_Boolean isC0 = !isNotCheckC0 &&
126 (myBasisCurveContinuity == GeomAbs_C0);
06be28a4
RL
127
128 // Basis curve must be at least C1
3d58dc49 129 if (isC0 && aCheckingCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)))
06be28a4 130 {
3d58dc49 131 Handle(Geom2d_BSplineCurve) aBC = Handle(Geom2d_BSplineCurve)::DownCast(aCheckingCurve);
132 if(aBC->IsG1(aUf, aUl, MyAngularToleranceForG1))
06be28a4 133 {
3d58dc49 134 //Checking if basis curve has more smooth (C1, G2 and above) is not done.
135 //It can be done in case of need.
136 myBasisCurveContinuity = GeomAbs_G1;
137 isC0 = Standard_False;
06be28a4
RL
138 }
139
140 // Raise exception if still C0
3d58dc49 141 if (isC0)
9775fa61 142 throw Standard_ConstructionError("Offset on C0 curve");
06be28a4 143 }
3d58dc49 144 //
145 if(isTrimmed)
146 {
147 basisCurve = new Geom2d_TrimmedCurve(aCheckingCurve, aUf, aUl);
148 }
149 else
150 {
151 basisCurve = aCheckingCurve;
152 }
06be28a4 153
d660a72a 154 myEvaluator = new Geom2dEvaluator_OffsetCurve(basisCurve, offsetValue);
7fd59977 155}
156
157//=======================================================================
158//function : SetOffsetValue
159//purpose :
160//=======================================================================
161
d660a72a 162void Geom2d_OffsetCurve::SetOffsetValue (const Standard_Real D)
163{
164 offsetValue = D;
165 myEvaluator->SetOffsetValue(offsetValue);
166}
7fd59977 167
168//=======================================================================
169//function : BasisCurve
170//purpose :
171//=======================================================================
172
c04c30b3 173Handle(Geom2d_Curve) Geom2d_OffsetCurve::BasisCurve () const
7fd59977 174{
175 return basisCurve;
176}
177
178//=======================================================================
179//function : Continuity
180//purpose :
181//=======================================================================
182
183GeomAbs_Shape Geom2d_OffsetCurve::Continuity () const
184{
185 GeomAbs_Shape OffsetShape=GeomAbs_C0;
3d58dc49 186 switch (myBasisCurveContinuity) {
7fd59977 187 case GeomAbs_C0 : OffsetShape = GeomAbs_C0; break;
188 case GeomAbs_C1 : OffsetShape = GeomAbs_C0; break;
189 case GeomAbs_C2 : OffsetShape = GeomAbs_C1; break;
190 case GeomAbs_C3 : OffsetShape = GeomAbs_C2; break;
191 case GeomAbs_CN : OffsetShape = GeomAbs_CN; break;
192 case GeomAbs_G1 : OffsetShape = GeomAbs_G1; break;
193 case GeomAbs_G2 : OffsetShape = GeomAbs_G2; break;
194 }
3d58dc49 195
7fd59977 196 return OffsetShape;
197}
198
199//=======================================================================
200//function : D0
201//purpose :
202//=======================================================================
203
94f71cad 204void Geom2d_OffsetCurve::D0 (const Standard_Real theU,
d660a72a 205 gp_Pnt2d& theP) const
206{
207 myEvaluator->D0(theU, theP);
94f71cad 208}
7fd59977 209
210//=======================================================================
211//function : D1
212//purpose :
213//=======================================================================
d660a72a 214void Geom2d_OffsetCurve::D1 (const Standard_Real theU, gp_Pnt2d& theP, gp_Vec2d& theV1) const
94f71cad 215{
d660a72a 216 myEvaluator->D1(theU, theP, theV1);
7fd59977 217}
218
219//=======================================================================
220//function : D2
221//purpose :
222//=======================================================================
223
32ca7a51 224void Geom2d_OffsetCurve::D2 (const Standard_Real theU,
d660a72a 225 gp_Pnt2d& theP,
226 gp_Vec2d& theV1, gp_Vec2d& theV2) const
7fd59977 227{
d660a72a 228 myEvaluator->D2(theU, theP, theV1, theV2);
7fd59977 229}
230
231
232//=======================================================================
233//function : D3
234//purpose :
235//=======================================================================
236
32ca7a51 237void Geom2d_OffsetCurve::D3 (const Standard_Real theU,
d660a72a 238 gp_Pnt2d& theP,
239 gp_Vec2d& theV1, gp_Vec2d& theV2, gp_Vec2d& theV3) const
94f71cad 240{
d660a72a 241 myEvaluator->D3(theU, theP, theV1, theV2, theV3);
94f71cad 242}
7fd59977 243
244//=======================================================================
245//function : DN
246//purpose :
247//=======================================================================
248
d660a72a 249gp_Vec2d Geom2d_OffsetCurve::DN (const Standard_Real U,
250 const Standard_Integer N) const
7fd59977 251{
d660a72a 252 Standard_RangeError_Raise_if (N < 1, "Exception: Geom2d_OffsetCurve::DN(). N<1.");
7fd59977 253
254 gp_Vec2d VN, VBidon;
255 gp_Pnt2d PBidon;
256 switch (N) {
257 case 1: D1( U, PBidon, VN); break;
258 case 2: D2( U, PBidon, VBidon, VN); break;
259 case 3: D3( U, PBidon, VBidon, VBidon, VN); break;
260 default:
9775fa61 261 throw Standard_NotImplemented("Exception: Derivative order is greater than 3. "
32ca7a51 262 "Cannot compute of derivative.");
7fd59977 263 }
264
265 return VN;
266}
267
7fd59977 268//=======================================================================
269//function : FirstParameter
270//purpose :
271//=======================================================================
272
273Standard_Real Geom2d_OffsetCurve::FirstParameter () const
274{
275 return basisCurve->FirstParameter();
276}
277
278//=======================================================================
279//function : LastParameter
280//purpose :
281//=======================================================================
282
283Standard_Real Geom2d_OffsetCurve::LastParameter () const
284{
285 return basisCurve->LastParameter();
286}
287
288
289//=======================================================================
290//function : Offset
291//purpose :
292//=======================================================================
293
d660a72a 294Standard_Real Geom2d_OffsetCurve::Offset () const
295{ return offsetValue; }
7fd59977 296
297//=======================================================================
298//function : IsClosed
299//purpose :
300//=======================================================================
301
302Standard_Boolean Geom2d_OffsetCurve::IsClosed () const
303{
304 gp_Pnt2d PF, PL;
305 D0(FirstParameter(),PF);
306 D0(LastParameter(),PL);
307 return ( PF.Distance(PL) <= gp::Resolution());
308}
309
310//=======================================================================
311//function : IsCN
312//purpose :
313//=======================================================================
314
315Standard_Boolean Geom2d_OffsetCurve::IsCN (const Standard_Integer N) const
316{
317 Standard_RangeError_Raise_if (N < 0, " " );
318 return basisCurve->IsCN (N + 1);
319}
320
321//=======================================================================
322//function : IsPeriodic
323//purpose :
324//=======================================================================
325
326Standard_Boolean Geom2d_OffsetCurve::IsPeriodic () const
327{
328 return basisCurve->IsPeriodic();
329}
330
331//=======================================================================
332//function : Period
333//purpose :
334//=======================================================================
335
336Standard_Real Geom2d_OffsetCurve::Period() const
337{
338 return basisCurve->Period();
339}
340
341//=======================================================================
342//function : Transform
343//purpose :
344//=======================================================================
345
d660a72a 346void Geom2d_OffsetCurve::Transform (const gp_Trsf2d& T)
7fd59977 347{
348 basisCurve->Transform (T);
349 offsetValue *= Abs(T.ScaleFactor());
d660a72a 350
351 myEvaluator->SetOffsetValue(offsetValue);
7fd59977 352}
353
354
355//=======================================================================
356//function : TransformedParameter
357//purpose :
358//=======================================================================
359
360Standard_Real Geom2d_OffsetCurve::TransformedParameter(const Standard_Real U,
361 const gp_Trsf2d& T) const
362{
363 return basisCurve->TransformedParameter(U,T);
364}
365
366//=======================================================================
367//function : ParametricTransformation
368//purpose :
369//=======================================================================
370
371Standard_Real Geom2d_OffsetCurve::ParametricTransformation(const gp_Trsf2d& T) const
372{
373 return basisCurve->ParametricTransformation(T);
374}
3d58dc49 375
376//=======================================================================
377//function : GetBasisCurveContinuity
378//purpose :
379//=======================================================================
380GeomAbs_Shape Geom2d_OffsetCurve::GetBasisCurveContinuity() const
381{
382 return myBasisCurveContinuity;
383}
bc73b006 384
385//=======================================================================
386//function : DumpJson
387//purpose :
388//=======================================================================
389void Geom2d_OffsetCurve::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
390{
391 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
392
393 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom2d_Curve)
394
395 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, basisCurve.get())
396
397 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, offsetValue)
398 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBasisCurveContinuity)
399}