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