973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | //======================================================================= |
7fd59977 |
15 | //modified: |
16 | // 21.02.2002 skl |
17 | // 21.12.98 rln, gka S4054 |
18 | //:k5 abv 25 Dec 98: PRO8803 1901: extending method of fixing Multi > Degree |
19 | // 28.12.98 dce S3767 New messaging system |
20 | //#61 rln 05.01.99 |
21 | //#60 rln 29.12.98 PRO17015 |
22 | //:l3 abv 11.01.99: CATIA01.igs: using less values for checking short lines |
23 | //%11 pdn 12.01.98 CTS22023 correcting used tolerances |
24 | //sln 29.12.2001 OCC90 : Method checkBSplineCurve and varification before creation of bspline curves were added |
25 | //======================================================================= |
26 | |
7fd59977 |
27 | #include <ElCLib.hxx> |
7fd59977 |
28 | #include <Geom2d_BSplineCurve.hxx> |
29 | #include <Geom2d_Circle.hxx> |
42cf5bc1 |
30 | #include <Geom2d_Curve.hxx> |
7fd59977 |
31 | #include <Geom2d_Ellipse.hxx> |
32 | #include <Geom2d_Hyperbola.hxx> |
33 | #include <Geom2d_Line.hxx> |
34 | #include <Geom2d_Parabola.hxx> |
35 | #include <Geom2d_TrimmedCurve.hxx> |
42cf5bc1 |
36 | #include <Geom_BSplineCurve.hxx> |
37 | #include <Geom_Circle.hxx> |
38 | #include <Geom_Curve.hxx> |
39 | #include <Geom_Ellipse.hxx> |
40 | #include <Geom_Hyperbola.hxx> |
41 | #include <Geom_Line.hxx> |
42 | #include <Geom_Parabola.hxx> |
43 | #include <Geom_Transformation.hxx> |
44 | #include <Geom_TrimmedCurve.hxx> |
7fd59977 |
45 | #include <gp_Ax2.hxx> |
46 | #include <gp_Ax2d.hxx> |
47 | #include <gp_Dir.hxx> |
48 | #include <gp_Dir2d.hxx> |
49 | #include <gp_GTrsf.hxx> |
42cf5bc1 |
50 | #include <gp_Hypr.hxx> |
7fd59977 |
51 | #include <gp_Pnt.hxx> |
52 | #include <gp_Pnt2d.hxx> |
53 | #include <gp_Trsf.hxx> |
7fd59977 |
54 | #include <gp_XYZ.hxx> |
42cf5bc1 |
55 | #include <IGESConvGeom.hxx> |
7fd59977 |
56 | #include <IGESData_ToolLocation.hxx> |
7fd59977 |
57 | #include <IGESGeom_BSplineCurve.hxx> |
58 | #include <IGESGeom_CircularArc.hxx> |
59 | #include <IGESGeom_ConicArc.hxx> |
42cf5bc1 |
60 | #include <IGESGeom_CopiousData.hxx> |
61 | #include <IGESGeom_Line.hxx> |
7fd59977 |
62 | #include <IGESGeom_SplineCurve.hxx> |
63 | #include <IGESGeom_TransformationMatrix.hxx> |
42cf5bc1 |
64 | #include <IGESToBRep_BasicCurve.hxx> |
65 | #include <IGESToBRep_CurveAndSurface.hxx> |
7fd59977 |
66 | #include <Interface_Macros.hxx> |
42cf5bc1 |
67 | #include <Message_Msg.hxx> |
68 | #include <Precision.hxx> |
69 | #include <ShapeConstruct_Curve.hxx> |
70 | #include <Standard_ErrorHandler.hxx> |
71 | #include <Standard_Failure.hxx> |
72 | #include <TColGeom_SequenceOfCurve.hxx> |
7fd59977 |
73 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 |
74 | #include <TColStd_Array1OfInteger.hxx> |
75 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
76 | #include <TColStd_SequenceOfInteger.hxx> |
77 | |
78 | //:36 |
7fd59977 |
79 | // S3767 |
7fd59977 |
80 | //======================================================================= |
81 | //function : CheckBSplineCurve |
82 | //purpose : Check coincidede knots Check whether knots are in ascending |
83 | // order and difference between vaues of weights more than 1000. |
84 | // Send corresponding messages. The function returns Standard_False |
85 | // if curve can not be created, Standard_True otherwise. |
86 | //======================================================================= |
87 | static Standard_Boolean checkBSplineCurve(IGESToBRep_BasicCurve* theCurve, |
88 | const Handle(IGESGeom_BSplineCurve)& theBSplineCurve, |
89 | TColStd_Array1OfReal& CKnots, |
90 | const TColStd_Array1OfReal& CWeights) |
91 | { |
92 | // check whether difference between vaues of weights more than 1000. |
93 | if(!theBSplineCurve->IsPolynomial()) { |
94 | Standard_Real aMinValue = CWeights.Value(CWeights.Lower()); |
95 | Standard_Real aMaxValue = CWeights.Value(CWeights.Lower()); |
96 | for(Standard_Integer i = CWeights.Lower()+1; i<= CWeights.Upper(); i++) { |
97 | if(CWeights.Value(i) < aMinValue) aMinValue = CWeights.Value(i); |
98 | if(CWeights.Value(i) > aMaxValue) aMaxValue = CWeights.Value(i); |
99 | } |
100 | if(aMaxValue - aMinValue > 1000) { |
101 | Message_Msg msg1374("IGES_1374"); // WARNING - Difference between weights is too big. |
102 | theCurve->SendWarning(theBSplineCurve, msg1374); |
103 | } |
104 | } |
105 | |
106 | Standard_Boolean aResult = Standard_True; |
107 | |
108 | //check whether knots are in ascending order. |
109 | for (Standard_Integer i = CKnots.Lower(); i < CKnots.Upper(); i++) |
110 | if(CKnots.Value (i+1) < CKnots.Value (i)) { |
111 | Message_Msg msg1373("IGES_1373"); // FAIL - Knots are not in ascending order |
112 | theCurve->SendFail(theBSplineCurve, msg1373); |
113 | aResult = Standard_False; |
114 | } |
115 | //Fix coincided knots |
116 | if(aResult) ShapeConstruct_Curve::FixKnots(CKnots); |
117 | |
118 | return aResult; |
119 | |
120 | } |
121 | |
122 | |
123 | |
124 | //======================================================================= |
125 | //function : IGESToBRep_BasicCurve |
126 | //purpose : |
127 | //======================================================================= |
128 | IGESToBRep_BasicCurve::IGESToBRep_BasicCurve() |
129 | :IGESToBRep_CurveAndSurface() |
130 | { |
131 | SetModeTransfer(Standard_False); |
132 | } |
133 | |
134 | |
135 | //======================================================================= |
136 | //function : IGESToBRep_BasicCurve |
137 | //purpose : |
138 | //======================================================================= |
139 | IGESToBRep_BasicCurve::IGESToBRep_BasicCurve |
140 | (const IGESToBRep_CurveAndSurface& CS) |
141 | :IGESToBRep_CurveAndSurface(CS) |
142 | { |
143 | } |
144 | |
145 | |
146 | //======================================================================= |
147 | //function : IGESToBRep_BasicCurve |
148 | //purpose : |
149 | //======================================================================= |
150 | IGESToBRep_BasicCurve::IGESToBRep_BasicCurve |
151 | (const Standard_Real eps, |
152 | const Standard_Real epsCoeff, |
153 | const Standard_Real epsGeom, |
154 | const Standard_Boolean mode, |
155 | const Standard_Boolean modeapprox, |
156 | const Standard_Boolean optimized) |
157 | :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode, |
158 | modeapprox,optimized) |
159 | { |
160 | } |
161 | |
162 | |
163 | //======================================================================= |
164 | //function : TransferBasicCurve |
165 | //purpose : |
166 | //======================================================================= |
167 | |
168 | Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferBasicCurve |
169 | (const Handle(IGESData_IGESEntity)& start) |
170 | { |
171 | Handle(Geom_Curve) res; |
172 | if (start.IsNull()) { |
173 | Message_Msg msg1005("IGES_1005"); |
174 | SendFail(start, msg1005); |
175 | return res; |
176 | } |
177 | try { //:36 by abv 11.12.97: Geom_BSplineCurve fails if somw weights are <=0 |
178 | OCC_CATCH_SIGNALS |
179 | //S4054 |
180 | if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineCurve))) { |
181 | DeclareAndCast(IGESGeom_BSplineCurve, st126, start); |
182 | res = TransferBSplineCurve(st126); |
183 | } |
184 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_Line))) { |
185 | DeclareAndCast(IGESGeom_Line, st110, start); |
186 | res = TransferLine(st110); |
187 | } |
188 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) { |
189 | DeclareAndCast(IGESGeom_CircularArc, st100, start); |
190 | res = TransferCircularArc(st100); |
191 | } |
192 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) { |
193 | DeclareAndCast(IGESGeom_ConicArc, st104, start); |
194 | res = TransferConicArc(st104); |
195 | } |
196 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_CopiousData))) { |
197 | DeclareAndCast(IGESGeom_CopiousData, st106, start); |
198 | res = TransferCopiousData(st106); |
199 | } |
200 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineCurve))) { |
201 | DeclareAndCast(IGESGeom_SplineCurve, st112, start); |
202 | res = TransferSplineCurve(st112); |
203 | } |
204 | else { |
205 | // AddFail(start, "The IGESEntity is not a basic curve."); |
206 | // This case can not occur |
207 | return res; |
208 | } |
209 | |
210 | } //:36 |
9775fa61 |
211 | catch(Standard_Failure const& anException) { |
0797d9d3 |
212 | #ifdef OCCT_DEBUG |
04232180 |
213 | std::cout << "\n** Exception in IGESToBRep_BasicCurve::TransferBasicCurve : "; |
214 | anException.Print(std::cout); |
7fd59977 |
215 | #endif |
9775fa61 |
216 | (void)anException; |
7fd59977 |
217 | } |
218 | if (res.IsNull()) { |
21c7c457 |
219 | // AddFail(start, "The IGESEntity cannot be transferred."); |
7fd59977 |
220 | // The more specific function have ever add a fail message for this entity |
221 | } |
222 | else |
223 | res->Scale(gp_Pnt(0,0,0),GetUnitFactor()); |
224 | return res; |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : Transfer2dBasicCurve |
229 | //purpose : |
230 | //======================================================================= |
231 | |
232 | Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dBasicCurve |
233 | (const Handle(IGESData_IGESEntity)& start) |
234 | { |
235 | Handle(Geom2d_Curve) res; |
236 | if (start.IsNull()) { |
237 | Message_Msg msg1005("IGES_1005"); |
238 | SendFail(start, msg1005); |
239 | return res; |
240 | } |
241 | try { //:h8 abv 15 Jul 98: BUC60291 43693: Bspline Multiplicity > Degree+1 -> exception |
242 | OCC_CATCH_SIGNALS |
243 | |
244 | //S4054 |
245 | if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineCurve))) { |
246 | DeclareAndCast(IGESGeom_BSplineCurve, st126, start); |
247 | res = Transfer2dBSplineCurve(st126); |
248 | } |
249 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_Line))) { |
250 | DeclareAndCast(IGESGeom_Line, st110, start); |
251 | res = Transfer2dLine(st110); |
252 | } |
253 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) { |
254 | DeclareAndCast(IGESGeom_CircularArc, st100, start); |
255 | res = Transfer2dCircularArc(st100); |
256 | } |
257 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) { |
258 | DeclareAndCast(IGESGeom_ConicArc, st104, start); |
259 | res = Transfer2dConicArc(st104); |
260 | } |
261 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_CopiousData))) { |
262 | DeclareAndCast(IGESGeom_CopiousData, st106, start); |
263 | res = Transfer2dCopiousData(st106); |
264 | } |
265 | else if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineCurve))) { |
266 | DeclareAndCast(IGESGeom_SplineCurve, st112, start); |
267 | res = Transfer2dSplineCurve(st112); |
268 | } |
269 | else { |
270 | // AddFail(start, "The IGESEntity is not a basic curve."); |
271 | // This case can not occur |
272 | return res; |
273 | } |
274 | } //:h8 |
9775fa61 |
275 | catch(Standard_Failure const& anException) { |
0797d9d3 |
276 | #ifdef OCCT_DEBUG |
04232180 |
277 | std::cout << "\n** Exception in IGESToBRep_BasicCurve::Transfer2dBasicCurve : "; |
278 | anException.Print(std::cout); |
7fd59977 |
279 | #endif |
9775fa61 |
280 | (void)anException; |
7fd59977 |
281 | } |
282 | return res; |
283 | } |
284 | |
285 | |
286 | |
287 | //======================================================================= |
288 | //function : TransferConicArc |
289 | //purpose : |
290 | //======================================================================= |
291 | // |
292 | // A,B,C,D,E,F are the coefficients recorded in IGES. a,b,c,d,e,f are used to |
0177fe26 |
293 | // simplify the equations of conversion. They are already used in Euclid. |
7fd59977 |
294 | |
295 | Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferConicArc |
296 | (const Handle(IGESGeom_ConicArc)& st) |
297 | { |
298 | Handle(Geom_Curve) res; |
299 | if (st.IsNull()) { |
300 | Message_Msg msg1005("IGES_1005"); |
301 | SendFail(st, msg1005); |
302 | return res; |
303 | } |
304 | // If the Conic is closed, the start and end points will be ignored. |
305 | if (!st->ComputedFormNumber()) { |
306 | Message_Msg msg1155("IGES_1155"); |
307 | SendFail(st, msg1155); |
308 | // AddFail(st, "Coefficients do not define correctly a conic."); |
309 | return res; |
310 | } |
311 | |
312 | // Conic = ax2+bxy+cy2+dx+ey+f=0 in the plane z=ZT. |
313 | Standard_Real a,b,c,d,e,f,ZT; |
314 | st->Equation(a, b, c, d, e, f); |
315 | |
316 | ZT = st->ZPlane(); |
317 | |
318 | gp_Pnt center, startPoint, endPoint; |
319 | gp_Dir mainAxis ,normAxis; |
320 | Standard_Real minorRadius, majorRadius; |
321 | |
322 | if (!GetModeTransfer() && st->HasTransf()) { |
323 | |
324 | st->TransformedDefinition(center ,mainAxis, minorRadius, majorRadius); |
325 | normAxis = st->TransformedAxis(); |
326 | |
327 | startPoint = st->TransformedStartPoint(); |
328 | endPoint = st->TransformedEndPoint(); |
329 | } |
330 | else { |
331 | st->Definition(center ,mainAxis, minorRadius, majorRadius); |
332 | normAxis = st->Axis(); |
333 | |
334 | startPoint.SetCoord(st->StartPoint().X(), st->StartPoint().Y(), ZT); |
335 | endPoint.SetCoord (st->EndPoint().X() , st->EndPoint().Y() , ZT); |
336 | } |
337 | gp_Ax2 frame(center, normAxis, mainAxis); |
338 | Standard_Real t1 =0.0, t2 =0.0; |
339 | if (st->IsFromEllipse()) { |
340 | |
341 | //#60 rln 29.12.98 PRO17015 reading back face#67: ellipse with big radii produces |
342 | //small coefficients |
343 | //The dimensions should be also obliged: |
344 | //[a]=[b]=[c]=L^-2 |
345 | //if ( (Abs(a-c) <= GetEpsGeom()) && (Abs(b) < GetEpsCoeff())) |
346 | Standard_Real eps2 = Precision::PConfusion() * Precision::PConfusion(); |
347 | if ( (Abs(a-c) <= eps2) && (Abs(b) < eps2)) { |
348 | |
349 | // ================= |
350 | // == Circle 3D == |
351 | // ================= |
352 | |
353 | res = new Geom_Circle(frame, minorRadius); |
354 | |
355 | if (!st->IsClosed()) { |
356 | |
357 | gp_Circ circ(frame, minorRadius); |
358 | |
359 | t1 = ElCLib::Parameter(circ, startPoint); |
360 | t2 = ElCLib::Parameter(circ, endPoint); |
c6541a0c |
361 | if (t1 > t2 && (t1 - t2) > Precision::Confusion()) t2 += 2.*M_PI; |
7fd59977 |
362 | if (Abs(t1 - t2) <= Precision::Confusion()) { // t1 = t2 |
363 | Message_Msg msg1160("IGES_1160"); |
364 | SendWarning(st, msg1160); |
365 | } |
366 | else |
367 | res = new Geom_TrimmedCurve(res, t1, t2); |
368 | } |
369 | return res; |
370 | } |
371 | else { |
372 | // This is a no circular ellipse which will be computed with |
373 | // the hyperbola at the end of this member. |
374 | } |
375 | } |
376 | else if (st->IsFromParabola()) { |
377 | |
378 | // =================== |
379 | // == Parabola 3D == |
380 | // =================== |
381 | |
382 | Standard_Real focal = minorRadius; |
383 | // PTV 26.03.2002 |
384 | focal = focal/2.; |
385 | gp_Parab parab(frame, focal); |
386 | |
387 | res = new Geom_Parabola(frame, focal); |
388 | |
389 | t1 = ElCLib::Parameter(parab, startPoint); |
390 | t2 = ElCLib::Parameter(parab, endPoint); |
391 | if (Abs(t1 - t2) <= Precision::Confusion()) { // t1 = t2 |
392 | Message_Msg msg1160("IGES_1160"); |
393 | SendWarning(st, msg1160); |
394 | //AddWarning(st, "The trim of the parabola is not correct."); |
395 | } |
396 | else |
397 | // if t1 > t2, the course of the curve is going to be reversed. |
398 | res = new Geom_TrimmedCurve(res, t1, t2); |
399 | |
400 | return res; |
401 | } |
402 | |
403 | // Same computing for the ellipse and the hyperbola. |
404 | |
405 | // ============================================= |
406 | // == Hyperbola or a no circular Ellipse 3D. == |
407 | // ============================================= |
408 | |
409 | |
410 | if (st->IsFromEllipse()) { |
411 | res = new Geom_Ellipse(frame, majorRadius, minorRadius); |
412 | |
413 | if (!st->IsClosed()) { |
414 | gp_Elips elips(frame, majorRadius, minorRadius); |
415 | |
416 | t1 = ElCLib::Parameter(elips, startPoint); |
417 | t2 = ElCLib::Parameter(elips, endPoint); |
c6541a0c |
418 | if (t2 < t1 && (t1 -t2) > Precision::Confusion()) t2 += 2.*M_PI; |
7fd59977 |
419 | if (Abs(t1 - t2) <= Precision::Confusion()) { // t1 = t2 |
420 | Message_Msg msg1160("IGES_1160"); |
421 | SendWarning(st, msg1160); |
422 | //AddWarning(st, "The trim of the ellipse is not correct, the result will be a ellipse."); |
423 | } |
424 | else |
425 | res = new Geom_TrimmedCurve(res, t1, t2); |
426 | } |
427 | } |
428 | else { |
429 | |
430 | gp_Hypr hpr(frame, majorRadius, minorRadius); |
431 | |
432 | t1 = ElCLib::Parameter(hpr, startPoint); |
433 | t2 = ElCLib::Parameter(hpr, endPoint); |
434 | |
435 | res = new Geom_Hyperbola(frame, majorRadius, minorRadius); |
436 | |
437 | //pdn taking PConfusion for parameters. |
438 | if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2 |
439 | Message_Msg msg1160("IGES_1160"); |
440 | SendWarning(st, msg1160); |
441 | } |
442 | else if (t1 > t2) |
443 | res = new Geom_TrimmedCurve(res, t2, t1); // inversion des parametres. |
444 | else |
445 | res = new Geom_TrimmedCurve(res, t1, t2); |
446 | } |
447 | |
448 | return res; |
449 | } |
450 | |
451 | |
452 | //======================================================================= |
453 | //function : Transfer2dConicArc |
454 | //purpose : Transfer 2d of a ConicArc to be used as a boundary of a Face |
455 | //======================================================================= |
456 | |
457 | Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dConicArc |
458 | (const Handle(IGESGeom_ConicArc)& st) |
459 | { |
460 | Handle(Geom2d_Curve) res; |
461 | if (st.IsNull()) { |
462 | Message_Msg msg1005("IGES_1005"); |
463 | SendFail(st, msg1005); |
464 | return res; |
465 | } |
466 | |
467 | if (!st->ComputedFormNumber()) { |
468 | Message_Msg msg1155("IGES_1155"); |
469 | SendFail(st, msg1155); |
470 | return res; |
471 | } |
472 | |
473 | Standard_Real a,b,c,d,e,f; |
474 | // Conic = ax2+bxy+cy2+dx+ey+f=0. |
475 | st->Equation(a, b, c, d, e, f); |
476 | |
477 | gp_Pnt center3d; |
478 | gp_Dir mainAxis3d; |
479 | gp_Pnt2d startPoint, endPoint; |
480 | Standard_Real minorRadius, majorRadius; |
481 | |
482 | SetEpsilon(1.E-03); |
483 | if (!st->TransformedAxis().IsParallel /*#45 rln 23.11.98 IsEqual*/(st->Axis(), GetEpsilon())) { |
484 | SetModeTransfer(Standard_True); |
485 | // Only not to use Trsf. |
486 | // the normal axis is not parallel with Z axis. |
487 | SendWarning(st, "The Trsf is not compatible with a transfer2d, it will not applied."); |
488 | } |
489 | |
490 | if (!GetModeTransfer() && st->HasTransf()) { |
491 | |
492 | st->TransformedDefinition(center3d, |
493 | mainAxis3d, |
494 | minorRadius, |
495 | majorRadius); |
496 | startPoint.SetCoord(st->TransformedStartPoint().X(), |
497 | st->TransformedStartPoint().Y()); |
498 | endPoint.SetCoord(st->TransformedEndPoint().X(), |
499 | st->TransformedEndPoint().Y()); |
500 | } |
501 | else { |
502 | st->Definition(center3d, mainAxis3d, minorRadius, majorRadius); |
503 | startPoint = st->StartPoint(); |
504 | endPoint = st->EndPoint(); |
505 | } |
506 | |
507 | gp_Pnt2d center(center3d.X(), center3d.Y()); |
508 | gp_Dir2d mainAxis(mainAxis3d.X(), mainAxis3d.Y()); |
509 | gp_Ax2d frame(center, mainAxis); |
510 | Standard_Real t1 =0.0, t2=0.0; |
511 | if (st->IsFromEllipse()) { |
512 | |
513 | //#60 rln 29.12.98 PRO17015 |
514 | //if ( (Abs(a-c) <= GetEpsGeom()) && (Abs(b) < GetEpsCoeff())) |
515 | Standard_Real eps2 = Precision::PConfusion() * Precision::PConfusion(); |
516 | if ( (Abs(a-c) <= eps2) && (Abs(b) < eps2)) { |
517 | |
518 | // ================= |
519 | // == Circle 2D == |
520 | // ================= |
521 | |
522 | res = new Geom2d_Circle(frame, minorRadius); |
523 | //#45 rln 23.11.98 |
524 | if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon())) |
525 | res->Reverse(); |
526 | |
527 | if (!st->IsClosed()) { |
528 | |
529 | gp_Circ2d circ = Handle(Geom2d_Circle)::DownCast(res)->Circ2d();//#45 rln (frame, minorRadius); |
530 | |
531 | t1 = ElCLib::Parameter(circ, startPoint); |
532 | t2 = ElCLib::Parameter(circ, endPoint); |
533 | |
c6541a0c |
534 | if (t2 < t1 && (t1 -t2) > Precision::PConfusion()) t2 += 2.*M_PI; |
7fd59977 |
535 | if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2 |
536 | Message_Msg msg1160("IGES_1160"); |
537 | SendWarning(st, msg1160); |
538 | } |
539 | else |
540 | res = new Geom2d_TrimmedCurve(res, t1, t2); |
541 | } |
542 | return res; |
543 | } |
544 | else { |
545 | // This is a no circular ellipse, it will be computed with the hyperbola. |
546 | } |
547 | } |
548 | else if (st->IsFromParabola()) { |
549 | |
550 | // =================== |
551 | // == Parabola 2D == |
552 | // =================== |
553 | |
554 | Standard_Real focal = minorRadius; |
555 | // PTV 26.03.2002 |
556 | focal = focal/2.; |
557 | res = new Geom2d_Parabola(frame, focal); |
558 | //#45 rln 23.11.98 |
559 | if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon())) |
560 | res->Reverse(); |
561 | |
562 | gp_Parab2d parab = Handle(Geom2d_Parabola)::DownCast(res)->Parab2d();//#45 rln (frame, focal); |
563 | |
564 | t1 = ElCLib::Parameter(parab, startPoint); |
565 | t2 = ElCLib::Parameter(parab, endPoint); |
566 | if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2 |
567 | Message_Msg msg1160("IGES_1160"); |
568 | SendWarning(st, msg1160); |
569 | } |
570 | else if (t1 > t2) |
571 | res = new Geom2d_TrimmedCurve(res, t2, t1); // inversion des parametres. |
572 | else |
573 | res = new Geom2d_TrimmedCurve(res, t1, t2); |
574 | return res; |
575 | } |
576 | |
577 | /* Same computing for the ellipse2d and the hyperbola2d. */ |
578 | |
579 | // ============================================ |
580 | // == Hyperbola or a no circular Ellipse 2D == |
581 | // ============================================ |
582 | |
583 | if (st->IsFromEllipse()) { |
584 | |
585 | res = new Geom2d_Ellipse(frame, majorRadius, minorRadius); |
586 | //#45 rln 23.11.98 |
587 | if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon())) |
588 | res->Reverse(); |
589 | |
590 | if (!st->IsClosed()) { |
591 | |
592 | gp_Elips2d elips = Handle(Geom2d_Ellipse)::DownCast(res)->Elips2d();//#45 rln (frame, majorRadius, minorRadius); |
593 | |
594 | t1 = ElCLib::Parameter(elips, startPoint); |
595 | t2 = ElCLib::Parameter(elips, endPoint); |
c6541a0c |
596 | if (t2 < t1 && (t1 - t2) > Precision::PConfusion()) t2 += 2.*M_PI; |
7fd59977 |
597 | if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2 |
598 | Message_Msg msg1160("IGES_1160"); |
599 | SendWarning(st, msg1160); |
600 | } |
601 | else |
602 | res = new Geom2d_TrimmedCurve(res, t1, t2); |
603 | } |
604 | } |
605 | else { |
606 | |
607 | res = new Geom2d_Hyperbola(frame, majorRadius, minorRadius); |
608 | //#45 rln 23.11.98 |
609 | if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon())) |
610 | res->Reverse(); |
611 | |
612 | gp_Hypr2d hpr = Handle(Geom2d_Hyperbola)::DownCast(res)->Hypr2d();//#45 rln (frame, majorRadius, minorRadius); |
613 | |
614 | t1 = ElCLib::Parameter(hpr, startPoint); |
615 | t2 = ElCLib::Parameter(hpr, endPoint); |
616 | |
617 | if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2 |
618 | Message_Msg msg1160("IGES_1160"); |
619 | SendWarning(st, msg1160); |
620 | } |
621 | else if (t1 > t2) |
622 | res = new Geom2d_TrimmedCurve(res, t2, t1); // inversion des parametres. |
623 | else |
624 | res = new Geom2d_TrimmedCurve(res, t1, t2); |
625 | } |
626 | |
627 | return res; |
628 | } |
629 | |
630 | |
631 | //======================================================================= |
632 | //function : TransferCircularArc |
633 | //purpose : |
634 | //======================================================================= |
635 | |
636 | Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferCircularArc |
637 | (const Handle(IGESGeom_CircularArc)& st) |
638 | { |
639 | Handle(Geom_Curve) res; |
640 | if (st.IsNull()) { |
641 | Message_Msg msg1005("IGES_1005"); |
642 | SendFail(st,msg1005); |
643 | return res; |
644 | } |
645 | |
646 | gp_Dir tNormAxis, tMainAxis; |
647 | gp_Ax2 frame; |
648 | gp_Pnt startPoint, endPoint; |
649 | |
650 | if (!GetModeTransfer() && st->HasTransf()) { |
651 | |
652 | tNormAxis = st->TransformedAxis(); |
653 | |
654 | gp_GTrsf loc = st->Location(); |
655 | loc.SetTranslationPart (gp_XYZ(0.,0.,0.)); |
656 | gp_XYZ mainAxis(1., 0., 0.); |
657 | loc.Transforms(mainAxis); |
658 | tMainAxis = gp_Dir(mainAxis); |
659 | |
660 | startPoint = st->TransformedStartPoint(); |
661 | endPoint = st->TransformedEndPoint(); |
662 | |
663 | frame = gp_Ax2(st->TransformedCenter(), tNormAxis, tMainAxis); |
664 | } |
665 | else { |
666 | tNormAxis = st->Axis(); |
667 | tMainAxis.SetCoord(1., 0., 0.); |
668 | |
669 | Standard_Real ZT = st->ZPlane(); |
670 | startPoint.SetCoord(st->StartPoint().X(), st->StartPoint().Y(), ZT); |
671 | endPoint.SetCoord (st->EndPoint().X() , st->EndPoint().Y() , ZT); |
672 | gp_Pnt centerPoint (st->Center().X() , st->Center().Y() , ZT); |
673 | |
674 | frame = gp_Ax2(centerPoint, tNormAxis, tMainAxis); |
675 | } |
676 | |
677 | res = new Geom_Circle(frame, st->Radius()); |
678 | |
679 | gp_Circ circ(frame, st->Radius()); |
680 | |
681 | Standard_Real t1 =0.0, t2 =0.0; |
682 | |
683 | t1 = ElCLib::Parameter(circ, startPoint); |
684 | t2 = ElCLib::Parameter(circ, endPoint); |
685 | |
c6541a0c |
686 | if ( st->IsClosed() && t1>=GetEpsGeom()) t2 = t1 + 2.*M_PI; |
7fd59977 |
687 | if (!st->IsClosed() && fabs(t1 - t2) <=Precision::PConfusion()) { |
688 | // micro-arc |
689 | // cky 27 Aout 1996 : t2-t1 vaut distance(start,end)/rayon |
690 | t2 = t1 + startPoint.Distance(endPoint)/st->Radius(); |
691 | } |
692 | if (!st->IsClosed() || t1>=GetEpsGeom()) { |
c6541a0c |
693 | if (t2 < t1) t2 += 2.*M_PI; |
7fd59977 |
694 | res = new Geom_TrimmedCurve(res, t1, t2); |
695 | } |
696 | |
697 | return res; |
698 | } |
699 | |
700 | //======================================================================= |
701 | //function : Transfer2dCircularArc |
702 | //purpose : |
703 | //======================================================================= |
704 | |
705 | Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dCircularArc |
706 | (const Handle(IGESGeom_CircularArc)& st) |
707 | { |
708 | Handle(Geom2d_Curve) res; |
709 | if (st.IsNull()) { |
710 | Message_Msg msg1005("IGES_1005"); |
711 | SendFail(st,msg1005); |
712 | return res; |
713 | } |
714 | |
715 | gp_XYZ center(st->Center().X(), st->Center().Y(), 0.); |
716 | gp_XYZ mainAxis(1., 0., 0.); |
717 | |
718 | SetEpsilon(1.E-03); |
719 | if (!st->TransformedAxis().IsParallel /*#45 rln 23.11.98 IsEqual*/(st->Axis(), GetEpsilon())) { |
720 | SetModeTransfer(Standard_True); // Only not to use Trsf |
721 | Message_Msg msg1165("IGES_1165"); |
722 | SendWarning(st, msg1165); //"The Trsf is not compatible with a transfer2d, it will not applied." |
723 | } |
724 | |
725 | if (!GetModeTransfer() && st->HasTransf()) { |
726 | gp_GTrsf loc = st->Location(); |
727 | loc.Transforms(center); |
728 | loc.SetTranslationPart (gp_XYZ(0.,0.,0.)); |
729 | loc.Transforms(mainAxis); |
730 | } |
731 | gp_Pnt2d tCenter(center.X(), center.Y()); |
732 | gp_Dir2d tMainAxis(mainAxis.X(), mainAxis.Y()); |
733 | gp_Ax2d frame(tCenter, tMainAxis); |
734 | |
735 | res = new Geom2d_Circle(frame, st->Radius()); |
736 | |
737 | gp_Pnt2d startPoint, endPoint; |
738 | if (!GetModeTransfer() && st->HasTransf()) { |
739 | startPoint.SetCoord(st->TransformedStartPoint().X(), |
740 | st->TransformedStartPoint().Y()); |
741 | endPoint.SetCoord(st->TransformedEndPoint().X(), |
742 | st->TransformedEndPoint().Y()); |
743 | //#45 rln 23.11.98 |
744 | if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon())) |
745 | res->Reverse(); |
746 | } |
747 | else { |
748 | startPoint = st->StartPoint(); |
749 | endPoint = st->EndPoint(); |
750 | } |
751 | |
752 | gp_Circ2d circ = Handle(Geom2d_Circle)::DownCast(res)->Circ2d();//#45 rln (frame, st->Radius()); |
753 | |
754 | Standard_Real t1 =0.0, t2 =0.0; |
755 | |
756 | t1 = ElCLib::Parameter(circ, startPoint); |
757 | t2 = ElCLib::Parameter(circ, endPoint); |
758 | |
c6541a0c |
759 | if ( st->IsClosed() && t1>=GetEpsGeom()) t2 = t1 + 2.*M_PI; |
7fd59977 |
760 | if (!st->IsClosed() && fabs(t1 -t2) <= Precision::PConfusion()) { |
761 | // micro-arc |
762 | // cky 27 Aout 1996 : t2-t1 vaut distance(start,end)/rayon |
763 | t2 = t1 + startPoint.Distance(endPoint)/st->Radius(); |
764 | } |
765 | if (!st->IsClosed() || t1>= GetEpsGeom()) { |
c6541a0c |
766 | if (t2 < t1) t2 += 2.*M_PI; |
7fd59977 |
767 | res = new Geom2d_TrimmedCurve(res, t1, t2); |
768 | } |
769 | return res; |
770 | } |
771 | |
772 | |
773 | |
774 | //======================================================================= |
775 | //function : TransferSplineCurve |
776 | //purpose : |
777 | //======================================================================= |
778 | |
779 | Handle(Geom_BSplineCurve) IGESToBRep_BasicCurve::TransferSplineCurve |
780 | (const Handle(IGESGeom_SplineCurve)& st) |
781 | { |
782 | Handle(Geom_BSplineCurve) resconv; |
783 | if (st.IsNull()) { |
784 | Message_Msg msg1005("IGES_1005"); |
785 | SendFail(st,msg1005); |
786 | return resconv; |
787 | } |
788 | |
789 | Standard_Real epscoef = GetEpsCoeff(); |
790 | Standard_Real epsgeom = GetEpsGeom(); |
791 | |
792 | Standard_Integer result = IGESConvGeom::SplineCurveFromIGES(st, epscoef, epsgeom, resconv); |
793 | |
794 | switch (result) { |
795 | case 5 : { |
796 | Message_Msg msg246("XSTEP_246"); |
797 | SendFail(st, msg246); |
798 | // less than on segment (no result produced) |
799 | return resconv; |
800 | } |
801 | case 4 : { |
802 | Message_Msg msg1170("IGES_1170"); |
803 | SendFail(st, msg1170); |
804 | // Polynomial equation is not correct ( no result produced |
805 | return resconv;} |
806 | case 3 :{ |
807 | Message_Msg msg1175("IGES_1175"); |
808 | SendFail(st, msg1175); |
809 | // Error during creation of control points ( no result produced) |
810 | return resconv;} |
811 | case 2 :{ |
812 | Message_Msg msg1180("IGES_1180"); |
813 | SendFail(st, msg1180); |
814 | //SplineType not processed (allowed : max 3) (no result produced) |
815 | return resconv;} |
816 | default : |
817 | break; |
818 | } |
819 | |
820 | // Checking C2 and C1 continuity : |
821 | // =============================== |
822 | IGESConvGeom::IncreaseCurveContinuity (resconv, Min(Precision::Confusion(),epsgeom), GetContinuity()); |
823 | return resconv; |
824 | } |
825 | |
826 | |
827 | |
828 | //======================================================================= |
829 | //function : Transfer2dSplineCurve |
830 | //purpose : |
831 | //======================================================================= |
832 | |
833 | Handle(Geom2d_BSplineCurve) IGESToBRep_BasicCurve::Transfer2dSplineCurve |
834 | (const Handle(IGESGeom_SplineCurve)& st) |
835 | { |
836 | Handle(Geom2d_BSplineCurve) res; |
837 | if (st.IsNull()) { |
838 | Message_Msg msg1005("IGES_1005"); |
839 | SendFail(st, msg1005); |
840 | return res; |
841 | } |
842 | |
843 | // 3d transfer First |
844 | // ================= |
845 | // The same Presision as in BSpline 2d is used |
846 | Standard_Real epsGeom = GetEpsGeom(); |
847 | SetEpsGeom(Precision::PConfusion()); |
848 | Handle(Geom_BSplineCurve) res3d = TransferSplineCurve(st); |
849 | SetEpsGeom(epsGeom); |
850 | if (res3d.IsNull()) |
851 | return res; // The transfer was not over the top. |
852 | |
853 | |
854 | // 2d |
855 | // == |
856 | Standard_Integer nbPoles = res3d->NbPoles(); |
857 | Standard_Integer nbKnots = res3d->NbKnots(); |
858 | |
859 | TColgp_Array1OfPnt2d bspoles2d(1, nbPoles); |
860 | TColStd_Array1OfReal knots(1, nbKnots); |
861 | TColStd_Array1OfInteger multi(1, nbKnots); |
862 | |
863 | res3d->Knots(knots); |
864 | res3d->Multiplicities(multi); |
865 | |
866 | for (Standard_Integer i = bspoles2d.Lower(); i <= bspoles2d.Upper(); i++) |
867 | bspoles2d.SetValue(i, gp_Pnt2d(res3d->Pole(i).X(), res3d->Pole(i).Y())); |
868 | |
869 | res = new Geom2d_BSplineCurve (bspoles2d, knots, multi, res3d->Degree()); |
870 | return res; |
871 | } |
872 | |
873 | //======================================================================= |
874 | //function : TransferBSplineCurve |
875 | //purpose : |
876 | //======================================================================= |
877 | |
878 | Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferBSplineCurve |
879 | (const Handle(IGESGeom_BSplineCurve)& start) |
880 | |
881 | { |
882 | Handle(Geom_BSplineCurve) BSplineRes; |
883 | Handle(Geom_Curve) res; |
884 | |
885 | if (start.IsNull()) { |
886 | Message_Msg msg1005("IGES_1005"); |
887 | SendFail(start,msg1005); |
888 | return res; |
889 | } |
890 | |
891 | Standard_Integer Degree = start->Degree(); |
892 | |
893 | if (Degree<=0 || Degree>Geom_BSplineCurve::MaxDegree()) { |
894 | Message_Msg msg1190("IGES_1190"); |
895 | SendFail(start, msg1190); |
896 | // Improper degree either lower or equal to 0 or upper to MaxDegree |
897 | return res; |
898 | } |
899 | |
900 | |
901 | // Filling poles array : |
902 | // ===================== |
903 | |
904 | Standard_Integer NbPoles = start->NbPoles(); |
905 | Standard_Integer newNbPoles = NbPoles; |
906 | |
907 | if (NbPoles<2) { |
908 | Message_Msg msg1195("IGES_1195"); |
909 | SendFail(start, msg1195); |
910 | // Transfer aborted for a BSpline Curve : Number of poles lower than 2 |
911 | return res; |
912 | } |
913 | |
914 | TColgp_Array1OfPnt Pole(1,NbPoles); |
915 | Standard_Integer PoleIndex = Pole.Lower(); |
916 | Standard_Integer i; //szv#4:S4163:12Mar99 j unused |
917 | |
918 | if (!GetModeTransfer() && start->HasTransf()) |
919 | for (i=0; i<=start->UpperIndex(); i++) |
920 | Pole.SetValue(PoleIndex++, start->TransformedPole(i)); |
921 | else |
922 | for (i=0; i<=start->UpperIndex(); i++) |
923 | Pole.SetValue(PoleIndex++, start->Pole(i)); |
924 | |
925 | |
926 | // Filling knots & multiplicities arraies : |
927 | // ======================================== |
928 | |
929 | Standard_Integer NbKnots = start->NbKnots(); |
930 | TColStd_Array1OfReal TempKnot(1,NbKnots); |
931 | TColStd_Array1OfInteger TempMult(1,NbKnots); |
932 | TempMult.Init(1); |
933 | Standard_Integer KnotIndex = TempKnot.Lower(); |
934 | |
935 | TempKnot.SetValue(KnotIndex, start->Knot(-Degree)); |
936 | |
937 | // If several identical IGES knots are encountered, corresponding |
938 | // multiplicity is increased |
939 | // ============================================================== |
940 | |
941 | for (i=1-Degree; i<NbKnots-Degree; i++) { |
942 | |
943 | Standard_Real Knot1 = start->Knot(i); |
944 | Standard_Real Knot2 = start->Knot(i-1); |
945 | // Standard_Real ek = Epsilon(Knot1); |
946 | |
947 | if (Abs(Knot1 - Knot2) <= Epsilon(Knot1)) |
948 | TempMult.SetValue(KnotIndex, TempMult.Value(KnotIndex)+1); |
949 | else |
950 | TempKnot.SetValue(++KnotIndex, Knot1); |
951 | } |
952 | |
953 | |
954 | // Final knots & multiplicities arraies are dimensionned so as to be fully |
955 | // filled |
956 | // ======================================================================= |
957 | |
958 | TColStd_Array1OfReal Knot(1,KnotIndex); |
959 | TColStd_Array1OfInteger Mult(1,KnotIndex); |
960 | |
961 | Standard_Integer SumOfMult=0; |
962 | |
963 | TColStd_SequenceOfInteger SeqIndex; |
964 | Standard_Integer DelIndex; |
965 | Standard_Integer OldSumOfMult = 0; |
966 | for (i=1; i <= KnotIndex; i++) { //:k5 abv 25 Dec 98: cycle modified |
967 | Standard_Integer aMult = TempMult.Value(i); |
968 | Standard_Integer maxMult = ( i==1 || i == KnotIndex ? Degree + 1 : Degree ); |
969 | if (aMult > maxMult) { |
970 | Message_Msg msg1200("IGES_1200");//#61 rln 05.01.99 |
971 | const Standard_CString vide (""); |
972 | msg1200.Arg(vide); |
973 | msg1200.Arg(vide); |
974 | msg1200.Arg(vide); |
975 | SendWarning(start, msg1200);//Multiplicity > Degree (or Degree+1 at end); corrected |
976 | for ( DelIndex = OldSumOfMult + 1; aMult > maxMult; DelIndex++, aMult-- ) { |
977 | newNbPoles--; |
978 | SeqIndex.Append(DelIndex); |
979 | } |
980 | } |
981 | OldSumOfMult += TempMult.Value(i); |
982 | Knot.SetValue(i, TempKnot.Value(i)); |
983 | Mult.SetValue(i, aMult); |
984 | SumOfMult += aMult; |
985 | } |
986 | |
987 | // Mise a jour du tableau des poles lors de la correction de la multiplicite |
988 | TColgp_Array1OfPnt Poles(1,newNbPoles); |
989 | TColStd_SequenceOfInteger PoleInd; |
990 | |
991 | if ( newNbPoles < NbPoles) { |
992 | for (i=1; i<=NbPoles; i++) PoleInd.Append(i); |
993 | Standard_Integer Offset = 0; |
994 | for (Standard_Integer itab = 1; itab <= SeqIndex.Length(); itab++) { |
995 | DelIndex = SeqIndex.Value(itab) - Offset; |
996 | PoleInd.Remove(DelIndex); |
997 | Offset++; |
998 | } |
999 | Standard_Integer nbseq = PoleInd.Length(); |
1000 | if ( nbseq == newNbPoles) { |
1001 | Standard_Integer indj = 1; |
1002 | for ( i=1; i<= newNbPoles; i++) { |
1003 | Poles.SetValue(i, Pole.Value(PoleInd.Value(indj++))); |
1004 | } |
1005 | } |
1006 | } |
1007 | |
1008 | else { |
1009 | for ( i=1; i<= newNbPoles; i++) { |
1010 | Poles.SetValue (i, Pole.Value(i)); |
1011 | } |
1012 | } |
1013 | |
1014 | |
1015 | if (! (SumOfMult == newNbPoles + Degree + 1)) { |
1016 | Message_Msg msg1210("IGES_1210"); |
1017 | const Standard_CString vide (""); |
1018 | msg1210.Arg(vide); |
1019 | msg1210.Arg(vide); |
1020 | SendWarning(start, msg1210); |
1021 | //Sum of multiplicities not equal to the sum : Count of poles + Degree + 1 |
1022 | } |
1023 | |
1024 | // Output BSpline curve with the array of pole weights if any : |
1025 | // ============================================================ |
1026 | |
1027 | TColStd_Array1OfReal Weight(1,newNbPoles); |
1028 | |
1029 | if (start->IsPolynomial()) { |
1030 | //:5 BSplineC = new Geom_BSplineCurve(Poles, Knot, Mult, Degree); |
1031 | } |
1032 | else { |
1033 | TColStd_Array1OfReal PoleWeight(1,NbPoles); |
1034 | Standard_Boolean polynomial = Standard_True; |
1035 | Standard_Real WeightReference = start->Weight(0); |
1036 | Standard_Integer WeightIndex = PoleWeight.Lower(); |
1037 | |
1038 | for (i=0; i <= start->UpperIndex(); i++) { |
1039 | polynomial = Abs(start->Weight(i) - WeightReference) <= |
1040 | Epsilon(WeightReference) && polynomial; |
1041 | //:39 by abv 15.12.97 |
1042 | Standard_Real weight = start->Weight(i); |
1043 | if ( weight < Precision::PConfusion() ) { |
1044 | Message_Msg msg1215("IGES_1215"); |
1045 | SendFail(start, msg1215); |
1046 | // Some weights are not positive |
1047 | return res; |
1048 | } |
1049 | PoleWeight.SetValue(WeightIndex++, weight); |
1050 | //:39 PoleWeight.SetValue(WeightIndex++, start->Weight(i)); |
1051 | } |
1052 | if (polynomial) { |
1053 | Message_Msg msg1220("IGES_1220"); |
1054 | msg1220.Arg("curve"); |
1055 | SendWarning(start, msg1220); |
1056 | // Rational curve is polynomial |
1057 | } |
1058 | // Mise a jour du tableau des Weight lors de la correction de la multiplicite |
1059 | if ( newNbPoles < NbPoles) { |
1060 | Standard_Integer indj = 1; |
1061 | for ( i=1; i<= newNbPoles; i++) { |
1062 | Weight.SetValue(i, PoleWeight.Value(PoleInd.Value(indj++))); |
1063 | } |
1064 | } |
1065 | else { |
1066 | for ( i=1; i<= newNbPoles; i++) { |
1067 | Weight.SetValue (i, PoleWeight.Value(i)); |
1068 | } |
1069 | } |
1070 | //:5 BSplineC = new Geom_BSplineCurve(Poles, Weight, Knot, Mult, Degree); |
1071 | } |
1072 | |
1073 | //sln 29.12.2001 OCC90 : If curve can not be created do nothing |
1074 | if(!checkBSplineCurve(this, start, Knot, Weight)) return BSplineRes; |
1075 | |
1076 | { |
1077 | try { |
1078 | OCC_CATCH_SIGNALS |
1079 | if (start->IsPolynomial()) |
1080 | BSplineRes = new Geom_BSplineCurve(Poles, Knot, Mult, Degree); |
1081 | else |
1082 | BSplineRes = new Geom_BSplineCurve(Poles, Weight, Knot, Mult, Degree); |
1083 | } |
9775fa61 |
1084 | catch(Standard_Failure const& anException) { |
0797d9d3 |
1085 | #ifdef OCCT_DEBUG |
04232180 |
1086 | std::cout << "\n** Exception in IGESToBRep_BasicCurve::TransferBSplineCurve during creation of Geom_BSplineCurve : "; |
1087 | anException.Print(std::cout); |
7fd59977 |
1088 | #endif |
9775fa61 |
1089 | (void)anException; |
7fd59977 |
1090 | } |
1091 | } |
1092 | |
1093 | Standard_Real First = BSplineRes->FirstParameter(); |
1094 | Standard_Real Last = BSplineRes->LastParameter(); |
1095 | Standard_Real Udeb = start->UMin(); |
1096 | Standard_Real Ufin = start->UMax(); |
1097 | //%11 pdn 12.01.98 CTS22023 |
1098 | //if ( (Udeb-First) > Precision::PConfusion() || (Last-Ufin) > Precision::PConfusion() ) |
1099 | // BSplineRes->Segment(Udeb, Ufin); |
1100 | //res = BSplineRes; |
1101 | |
1102 | // IGESConvGeom::IncreaseCurveContinuity (BSplineRes,Min(Precision::Confusion(),GetEpsGeom()), GetContinuity()); |
1103 | |
1104 | // skl 21.02.2002 (exception in OCC133 and for file |
1105 | // "/dn04/OS/USINOR/UIdev/src/IsoLim/dat/igs/ps1002-v5.igs") |
1106 | Handle(Geom_BSplineCurve) BSplineRes2 = BSplineRes; |
1107 | if (((Udeb-First)>-Precision::PConfusion() && |
1108 | (Last-Ufin)>-Precision::PConfusion()) && Udeb<=Ufin ) { |
1109 | try { |
1110 | OCC_CATCH_SIGNALS |
fdabc211 |
1111 | if (Abs(Ufin-Udeb) > Precision::PConfusion()) |
1112 | BSplineRes->Segment(Udeb, Ufin); |
7fd59977 |
1113 | res = BSplineRes; |
1114 | } |
a738b534 |
1115 | catch (Standard_Failure const&) { |
7fd59977 |
1116 | Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(BSplineRes2,Udeb,Ufin); |
1117 | res = gtc; |
1118 | } |
1119 | } |
1120 | else |
1121 | res = BSplineRes; |
1122 | |
1123 | return res; |
1124 | } |
1125 | |
1126 | |
1127 | |
1128 | //======================================================================= |
1129 | //function : Transfer2dBSplineCurve |
1130 | //purpose : |
1131 | //======================================================================= |
1132 | |
1133 | Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dBSplineCurve |
1134 | (const Handle(IGESGeom_BSplineCurve)& start) |
1135 | { |
1136 | Handle(Geom2d_Curve) res; |
1137 | if (start.IsNull()) { |
1138 | Message_Msg msg1005("IGES_1005"); |
1139 | SendFail(start, msg1005); |
1140 | return res; |
1141 | } |
1142 | |
1143 | Handle(Geom2d_BSplineCurve) BSplineC; |
1144 | Handle(Geom_BSplineCurve) Bspline; |
1145 | Standard_Boolean IsTrimmed = Standard_False; |
1146 | Standard_Real Deb=0., Fin=0.; |
1147 | |
1148 | // 3d transfer first : |
1149 | // =================== |
1150 | // Standard_Real epsGeom = GetEpsGeom(); |
1151 | // SetEpsGeom(Precision::PConfusion()); |
1152 | Handle(Geom_Curve) res3d = TransferBSplineCurve(start); |
1153 | // SetEpsGeom(epsGeom); |
1154 | if (res3d.IsNull()) { |
1155 | return res; |
1156 | } |
1157 | |
1158 | |
1159 | if (res3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { |
1160 | DeclareAndCast(Geom_TrimmedCurve, TrimC, res3d); |
1161 | Handle(Geom_Curve) BasicCurve = TrimC->BasisCurve(); |
1162 | Deb = TrimC->FirstParameter(); |
1163 | Fin = TrimC->LastParameter(); |
1164 | IsTrimmed = Standard_True; |
1165 | if (BasicCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { |
1166 | DeclareAndCast(Geom_BSplineCurve, BSpline, BasicCurve); |
1167 | Bspline = BSpline; |
1168 | } |
1169 | else { |
1170 | return res; |
1171 | } |
1172 | } |
1173 | else if (res3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { |
1174 | DeclareAndCast(Geom_BSplineCurve, BSpline, res3d); |
1175 | Bspline = BSpline; |
1176 | } |
1177 | |
1178 | |
1179 | // Creating 2d poles : |
1180 | // =================== |
1181 | |
1182 | Standard_Integer NbPoles = Bspline->NbPoles(); |
1183 | TColgp_Array1OfPnt2d Pole(1,NbPoles); |
1184 | |
1185 | for (Standard_Integer i=1; i<=NbPoles; i++){ |
1186 | gp_Pnt2d aPole2d(Bspline->Pole(i).X(),Bspline->Pole(i).Y()); |
1187 | Pole.SetValue(i,aPole2d); |
1188 | } |
1189 | |
1190 | // Knots and multiplicities are the same : |
1191 | // ======================================= |
1192 | |
1193 | Standard_Integer NbKnots = Bspline->NbKnots(); |
1194 | |
1195 | TColStd_Array1OfReal Knot(1,NbKnots); |
1196 | Bspline->Knots(Knot); |
1197 | |
1198 | TColStd_Array1OfInteger Mult(1,NbKnots); |
1199 | Bspline->Multiplicities(Mult); |
1200 | |
1201 | Standard_Integer Degree = Bspline->Degree(); |
1202 | |
1203 | if (Bspline->IsRational()) { |
1204 | TColStd_Array1OfReal Weight(1,NbPoles); |
1205 | Bspline->Weights(Weight); |
1206 | BSplineC = new Geom2d_BSplineCurve(Pole, Weight, Knot, Mult, Degree); |
1207 | } |
1208 | else BSplineC = new Geom2d_BSplineCurve(Pole, Knot, Mult, Degree); |
1209 | |
1210 | res = BSplineC; |
1211 | |
1212 | // cas ou la Bspline est trimmee. |
1213 | if (IsTrimmed) { |
1214 | Handle(Geom2d_TrimmedCurve) TC = new Geom2d_TrimmedCurve |
1215 | (BSplineC, Deb, Fin, Standard_True); |
1216 | res = TC; |
1217 | } |
1218 | |
1219 | return res; |
1220 | } |
1221 | |
1222 | |
1223 | |
1224 | //======================================================================= |
1225 | //function : TransferLine |
1226 | //purpose : |
1227 | //======================================================================= |
1228 | |
1229 | Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferLine |
1230 | (const Handle(IGESGeom_Line)& start) |
1231 | { |
1232 | Handle(Geom_Curve) res; |
1233 | if (start.IsNull()) { |
1234 | Message_Msg msg1005("IGES_1005"); |
1235 | SendFail(start, msg1005); |
1236 | return res; |
1237 | } |
1238 | |
1239 | gp_Pnt Ps,Pe; |
1240 | |
1241 | if (!GetModeTransfer() && start->HasTransf()) { |
1242 | Ps = start->TransformedStartPoint(); |
1243 | Pe = start->TransformedEndPoint(); |
1244 | } |
1245 | else { |
1246 | Ps = start->StartPoint(); |
1247 | Pe = start->EndPoint(); |
1248 | } |
1249 | |
1250 | // modif du 15/10/97 : test moins severe |
1251 | // beaucoup de points confondus a GetEpsGeom()*GetUnitFactor() |
1252 | if (!Ps.IsEqual(Pe,Precision::Confusion())) { //:l3 abv 11 Jan 99: GetEpsGeom()*GetUnitFactor()/10.)) { |
1253 | gp_Lin line(Ps, gp_Dir(gp_Vec(Ps,Pe))); |
1254 | Standard_Real t1 = ElCLib::Parameter(line, Ps); |
1255 | Standard_Real t2 = ElCLib::Parameter(line, Pe); |
1256 | Handle(Geom_Line) Gline = new Geom_Line(line); |
1257 | if (Precision::IsNegativeInfinite(t1)) t1 = -Precision::Infinite(); |
1258 | if (Precision::IsPositiveInfinite(t2)) t2 = Precision::Infinite(); |
1259 | res = new Geom_TrimmedCurve(Gline, t1, t2); |
1260 | } |
1261 | else { |
1262 | Message_Msg msg1225("IGES_1225"); |
1263 | SendFail(start, msg1225); |
1264 | // StartPoint and EndPoint of the line are the same Point |
1265 | } |
1266 | |
1267 | return res; |
1268 | } |
1269 | |
1270 | |
1271 | |
1272 | //======================================================================= |
1273 | //function : Transfer2dLine |
1274 | //purpose : |
1275 | //======================================================================= |
1276 | |
1277 | Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dLine |
1278 | (const Handle(IGESGeom_Line)& start) |
1279 | { |
1280 | Handle(Geom2d_Curve) res; |
1281 | if (start.IsNull()) { |
1282 | Message_Msg msg1005("IGES_1005"); |
1283 | SendFail(start, msg1005); |
1284 | return res; |
1285 | } |
1286 | |
1287 | gp_Pnt2d beg, end; |
1288 | |
1289 | if (!GetModeTransfer() && start->HasTransf()) { |
1290 | beg.SetCoord(start->TransformedStartPoint().X(), |
1291 | start->TransformedStartPoint().Y()); |
1292 | end.SetCoord(start->TransformedEndPoint().X(), |
1293 | start->TransformedEndPoint().Y()); |
1294 | } |
1295 | else { |
1296 | beg.SetCoord(start->StartPoint().X(), |
1297 | start->StartPoint().Y()); |
1298 | end.SetCoord(start->EndPoint().X(), |
1299 | start->EndPoint().Y()); |
1300 | } |
1301 | |
1302 | if (!beg.IsEqual(end,Precision::PConfusion())) { //:l3 abv 11 Jan 99: GetEpsCoeff())) { |
1303 | gp_Lin2d line2d(beg, gp_Dir2d(gp_Vec2d(beg,end))); |
1304 | Standard_Real t1 = ElCLib::Parameter(line2d, beg); |
1305 | Standard_Real t2 = ElCLib::Parameter(line2d, end); |
1306 | Handle(Geom2d_Line) Gline2d = new Geom2d_Line(line2d); |
1307 | if (Precision::IsNegativeInfinite(t1)) t1 = -Precision::Infinite(); |
1308 | if (Precision::IsPositiveInfinite(t2)) t2 = Precision::Infinite(); |
1309 | res = new Geom2d_TrimmedCurve(Gline2d, t1, t2); |
1310 | } |
1311 | //added by rln 18/12/97 CSR# CTS18544 entity 25168 and 31273 |
1312 | //generating fail the same as above |
1313 | else { |
1314 | Message_Msg msg1225("IGES_1225"); |
1315 | SendFail(start, msg1225); // StartPoint and EndPoint of the 2d line are the same Point |
1316 | } |
1317 | return res; |
1318 | } |
1319 | |
1320 | |
1321 | |
1322 | //======================================================================= |
1323 | //function : TransferTransformation |
1324 | //purpose : |
1325 | //======================================================================= |
1326 | |
1327 | Handle(Geom_Transformation) IGESToBRep_BasicCurve::TransferTransformation |
1328 | (const Handle(IGESGeom_TransformationMatrix)& start) |
1329 | |
1330 | { |
1331 | Handle(Geom_Transformation) res; |
1332 | if (start.IsNull()) { |
1333 | Message_Msg msg1005("IGES_1005"); |
1334 | SendFail(start, msg1005); |
1335 | return res; |
1336 | } |
1337 | gp_Trsf resultat; |
1338 | SetEpsilon(1.E-05); |
1339 | if ( IGESData_ToolLocation::ConvertLocation |
1340 | (GetEpsilon(),start->Value(),resultat) ) |
1341 | res = new Geom_Transformation(resultat); |
1342 | else { |
1343 | Message_Msg msg1036("IGES_1036"); |
1344 | SendFail(start, msg1036); // Transformation : not a similarity |
1345 | } |
1346 | return res; |
1347 | } |
1348 | |
1349 | |
1350 | |
1351 | |
1352 | //======================================================================= |
1353 | //function : TransferCopiousData |
1354 | //purpose : |
1355 | //======================================================================= |
1356 | |
1357 | Handle(Geom_BSplineCurve) IGESToBRep_BasicCurve::TransferCopiousData |
1358 | (const Handle(IGESGeom_CopiousData)& start) |
1359 | |
1360 | { |
1361 | Handle(Geom_BSplineCurve) res; |
1362 | if (start.IsNull()) { |
1363 | Message_Msg msg1005("IGES_1005"); |
1364 | SendFail(start, msg1005); |
1365 | return res; |
1366 | } |
1367 | |
1368 | Standard_Integer FormNb = start->FormNumber(); |
1369 | if (!(FormNb==11 || FormNb==12 || FormNb==63)) { |
1370 | Message_Msg msg1240("IGES_1240"); |
1371 | SendWarning( start, msg1240); |
0177fe26 |
1372 | // "Copious Data : Form number is different from 11, 12 or 63 so the vector treatment is skipped"); |
7fd59977 |
1373 | } |
1374 | |
1375 | Standard_Integer NbPoints = start->NbPoints(); |
1376 | if (NbPoints < 2) { |
1377 | Message_Msg msg1195("IGES_1195"); |
1378 | SendFail(start, msg1195); // Count of points lower than 2 |
1379 | return res; |
1380 | } |
1381 | |
1382 | // Filling array of poles : |
1383 | // ======================== |
1384 | |
1385 | TColgp_Array1OfPnt TempPole(1,NbPoints); |
1386 | Standard_Integer TempIndex = TempPole.Lower(); |
1387 | |
1388 | if (!GetModeTransfer() && start->HasTransf()) { |
1389 | TempPole.SetValue(TempIndex,start->TransformedPoint(1)); |
1390 | } |
1391 | else { |
1392 | TempPole.SetValue(TempIndex,start->Point(1)); |
1393 | } |
1394 | |
1395 | TempIndex++; |
1396 | Standard_Integer i;// svv Jan 10 2000 : porting on DEC |
1397 | for (i=2; i <= NbPoints; i++) { |
1398 | gp_Pnt aPole; |
1399 | if (!GetModeTransfer() && start->HasTransf()) |
1400 | aPole = start->TransformedPoint(i); |
1401 | else |
1402 | aPole = start->Point(i); |
1403 | // #2 pdn 7 May 1998 BUC50028 |
1404 | // delete GetUnitFactor() |
1405 | // if (!aPole.IsEqual(TempPole(TempIndex-1),GetEpsGeom())) |
1406 | //S4054: some filter must be kept UKI60556 entity 7 (two equal points) |
1407 | if (!aPole.IsEqual(TempPole(TempIndex-1), gp::Resolution())) |
1408 | TempPole.SetValue(TempIndex++,aPole); |
1409 | } |
1410 | |
1411 | NbPoints = TempIndex - TempPole.Lower(); |
1412 | |
1413 | // #1 pdn 7 May 1998 BUC50028 entity 6307 |
1414 | if ( NbPoints == 1) { |
1415 | Message_Msg msg1235("IGES_1235"); |
1416 | SendFail(start, msg1235); |
1417 | // The curve degenerates to a point"); |
1418 | return res; |
1419 | } |
1420 | TColgp_Array1OfPnt Pole(1,NbPoints); |
1421 | |
1422 | TempIndex = TempPole.Lower(); |
1423 | for (i=Pole.Lower(); i<=Pole.Upper(); i++) |
1424 | Pole.SetValue(i,TempPole.Value(TempIndex++)); |
1425 | |
1426 | |
1427 | // Filling array of knots : |
1428 | // ======================== |
1429 | |
1430 | TColStd_Array1OfReal Knot(1,NbPoints); |
1431 | |
1432 | Knot.SetValue(Knot.Lower(),0.0); |
1433 | |
1434 | for (i=Knot.Lower()+1; i <= Knot.Upper(); i++) { |
1435 | gp_Pnt Pole1 = Pole.Value(i); |
1436 | gp_Pnt Pole2 = Pole.Value(i-1); |
1437 | Standard_Real KnotDist = Pole1.Distance(Pole2); |
1438 | Knot.SetValue(i, Knot.Value(i-1)+KnotDist); |
1439 | } |
1440 | |
1441 | Standard_Integer Degree = 1; |
1442 | |
1443 | TColStd_Array1OfInteger Mult(1, NbPoints); |
1444 | Mult.Init(Degree); |
1445 | Mult.SetValue(Mult.Lower(),Degree+1); |
1446 | Mult.SetValue(Mult.Upper(),Degree+1); |
1447 | |
1448 | res = new Geom_BSplineCurve(Pole, Knot, Mult, Degree); |
1449 | |
1450 | IGESConvGeom::IncreaseCurveContinuity (res, Max(GetEpsGeom()/10.,Precision::Confusion()), GetContinuity()); |
1451 | return res; |
1452 | } |
1453 | |
1454 | |
1455 | // ================================ |
1456 | // == TRANSFER 2D Copious data == |
1457 | // ================================ |
1458 | |
1459 | Handle(Geom2d_BSplineCurve) IGESToBRep_BasicCurve::Transfer2dCopiousData(const Handle(IGESGeom_CopiousData)& start) |
1460 | { |
1461 | Handle(Geom2d_BSplineCurve) res; |
1462 | if (start.IsNull()) { |
1463 | Message_Msg msg1005("IGES_1005"); |
1464 | SendFail(start, msg1005); |
1465 | return res; |
1466 | } |
1467 | |
1468 | Standard_Integer FormNb = start->FormNumber(); |
1469 | if (!(FormNb==11 || FormNb==12 || FormNb==63)) { |
1470 | Message_Msg msg1240("IGES_1240"); |
1471 | SendWarning( start, msg1240); |
0177fe26 |
1472 | // "Copious Data : Form number is different from 11, 12 or 63 so the vector treatment is skipped"); |
7fd59977 |
1473 | } |
1474 | |
1475 | Standard_Integer NbPoints = start->NbPoints(); |
1476 | if (NbPoints < 2) { |
1477 | Message_Msg msg1195("IGES_1195"); |
1478 | SendFail(start, msg1195); // Count of points lower than 2 |
1479 | return res; |
1480 | } |
1481 | |
1482 | // Filling array of poles : |
1483 | // ======================== |
1484 | |
1485 | TColgp_Array1OfPnt2d TempPole(1,NbPoints); |
1486 | Standard_Integer TempIndex = TempPole.Lower(); |
1487 | |
1488 | if (!GetModeTransfer() && start->HasTransf()) |
1489 | TempPole.SetValue(TempIndex,gp_Pnt2d(start->TransformedPoint(1).X(), |
1490 | start->TransformedPoint(1).Y())); |
1491 | else |
1492 | TempPole.SetValue(TempIndex,gp_Pnt2d(start->Point(1).X(), |
1493 | start->Point(1).Y())); |
1494 | |
1495 | |
1496 | TempIndex++; |
1497 | Standard_Integer i;//svv Jan 10 2000 : porting on DEC |
1498 | for (i=2; i <= NbPoints; i++) { |
1499 | gp_Pnt2d aPole; |
1500 | if (!GetModeTransfer() && start->HasTransf()) |
1501 | aPole = gp_Pnt2d(start->TransformedPoint(i).X(), |
1502 | start->TransformedPoint(i).Y()); |
1503 | else |
1504 | aPole = gp_Pnt2d(start->Point(i).X(), |
1505 | start->Point(i).Y()); |
1506 | // if (!aPole.IsEqual(TempPole(TempIndex-1), GetEpsCoeff())) //modified by rln 16/12/97 CSR# PRO11641 entity 46GetEpsGeom()*GetUnitFactor() |
1507 | //S4054: some filter must be kept UKI60556 entity 7 (two equal points) |
1508 | if (!aPole.IsEqual(TempPole(TempIndex-1), gp::Resolution())) |
1509 | TempPole.SetValue(TempIndex++,aPole); |
1510 | } |
1511 | |
1512 | NbPoints = TempIndex - TempPole.Lower(); |
1513 | //added by rln on 26/12/97 to avoid exception when creating Bspline from one point |
1514 | if (NbPoints == 1) { |
1515 | Message_Msg msg1235("IGES_1235"); |
1516 | SendFail(start, msg1235); |
1517 | // The curve degenerates to a point"); |
1518 | return res; |
1519 | } |
1520 | TColgp_Array1OfPnt2d Pole(1,NbPoints); |
1521 | |
1522 | TempIndex = TempPole.Lower(); |
1523 | for (i=Pole.Lower(); i<=Pole.Upper(); i++) |
1524 | Pole.SetValue(i,TempPole.Value(TempIndex++)); |
1525 | |
1526 | |
1527 | // Filling array of knots : |
1528 | // ======================== |
1529 | |
1530 | TColStd_Array1OfReal Knot(1,NbPoints); |
1531 | |
1532 | Knot.SetValue(Knot.Lower(),0.0); |
1533 | |
1534 | for (i=Knot.Lower()+1; i <= Knot.Upper(); i++) { |
1535 | gp_Pnt2d Pole1 = Pole.Value(i); |
1536 | gp_Pnt2d Pole2 = Pole.Value(i-1); |
1537 | Standard_Real KnotDist = Pole1.Distance(Pole2); |
1538 | Knot.SetValue(i, Knot.Value(i-1)+KnotDist); |
1539 | } |
1540 | |
1541 | const Standard_Integer Degree = 1; |
1542 | |
1543 | TColStd_Array1OfInteger Mult(1, NbPoints); |
1544 | Mult.Init(Degree); |
1545 | Mult.SetValue(Mult.Lower(),Degree+1); |
1546 | Mult.SetValue(Mult.Upper(),Degree+1); |
1547 | |
1548 | res = new Geom2d_BSplineCurve(Pole, Knot, Mult, Degree); |
1549 | |
1550 | Standard_Real epsGeom = GetEpsGeom(); |
1551 | Standard_Real anUVResolution = GetUVResolution(); |
1552 | |
1553 | IGESConvGeom::IncreaseCurveContinuity (res, Max(Precision::Confusion(),epsGeom*anUVResolution), GetContinuity()); |
1554 | return res; |
1555 | } |