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