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