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