1 // Created on: 1993-06-15
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <StepToGeom.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepBuilderAPI_MakeFace.hxx>
23 #include <Geom_Axis1Placement.hxx>
24 #include <Geom_Axis2Placement.hxx>
25 #include <Geom_BoundedCurve.hxx>
26 #include <Geom_BoundedSurface.hxx>
27 #include <Geom_BSplineCurve.hxx>
28 #include <Geom_BSplineSurface.hxx>
29 #include <Geom_CartesianPoint.hxx>
30 #include <Geom_Circle.hxx>
31 #include <Geom_Conic.hxx>
32 #include <Geom_ConicalSurface.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_CylindricalSurface.hxx>
35 #include <Geom_Direction.hxx>
36 #include <Geom_ElementarySurface.hxx>
37 #include <Geom_Ellipse.hxx>
38 #include <Geom_Hyperbola.hxx>
39 #include <Geom_Line.hxx>
40 #include <Geom_OffsetCurve.hxx>
41 #include <Geom_OffsetSurface.hxx>
42 #include <Geom_Parabola.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_RectangularTrimmedSurface.hxx>
45 #include <Geom_SphericalSurface.hxx>
46 #include <Geom_Surface.hxx>
47 #include <Geom_SurfaceOfLinearExtrusion.hxx>
48 #include <Geom_SurfaceOfRevolution.hxx>
49 #include <Geom_SweptSurface.hxx>
50 #include <Geom_ToroidalSurface.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <Geom_VectorWithMagnitude.hxx>
54 #include <Geom2d_AxisPlacement.hxx>
55 #include <Geom2d_BoundedCurve.hxx>
56 #include <Geom2d_BSplineCurve.hxx>
57 #include <Geom2d_CartesianPoint.hxx>
58 #include <Geom2d_Circle.hxx>
59 #include <Geom2d_Conic.hxx>
60 #include <Geom2d_Curve.hxx>
61 #include <Geom2d_Direction.hxx>
62 #include <Geom2d_Ellipse.hxx>
63 #include <Geom2d_Hyperbola.hxx>
64 #include <Geom2d_Line.hxx>
65 #include <Geom2d_Parabola.hxx>
66 #include <Geom2d_TrimmedCurve.hxx>
67 #include <Geom2d_VectorWithMagnitude.hxx>
68 #include <Geom2dConvert.hxx>
70 #include <gp_Trsf.hxx>
71 #include <gp_Trsf2d.hxx>
73 #include <gp_Lin2d.hxx>
75 #include <ShapeAlgo.hxx>
76 #include <ShapeAlgo_AlgoContainer.hxx>
77 #include <ShapeAnalysis_Curve.hxx>
79 #include <StepGeom_Axis1Placement.hxx>
80 #include <StepGeom_Axis2Placement2d.hxx>
81 #include <StepGeom_Axis2Placement3d.hxx>
82 #include <StepGeom_BoundedCurve.hxx>
83 #include <StepGeom_BoundedSurface.hxx>
84 #include <StepGeom_BSplineCurve.hxx>
85 #include <StepGeom_CartesianPoint.hxx>
86 #include <StepGeom_Direction.hxx>
88 #include <Standard_ErrorHandler.hxx>
89 #include <Standard_Failure.hxx>
91 #include <StepGeom_BezierCurve.hxx>
92 #include <StepGeom_BezierSurface.hxx>
93 #include <StepGeom_BSplineSurface.hxx>
94 #include <StepGeom_BSplineCurveWithKnots.hxx>
95 #include <StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve.hxx>
96 #include <StepGeom_BSplineSurfaceWithKnots.hxx>
97 #include <StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface.hxx>
98 #include <StepGeom_Circle.hxx>
99 #include <StepGeom_Conic.hxx>
100 #include <StepGeom_ConicalSurface.hxx>
101 #include <StepGeom_Curve.hxx>
102 #include <StepGeom_CurveReplica.hxx>
103 #include <StepGeom_CylindricalSurface.hxx>
104 #include <StepGeom_ElementarySurface.hxx>
105 #include <StepGeom_Ellipse.hxx>
106 #include <StepGeom_Hyperbola.hxx>
107 #include <StepGeom_Line.hxx>
108 #include <StepGeom_OffsetCurve3d.hxx>
109 #include <StepGeom_OffsetSurface.hxx>
110 #include <StepGeom_Parabola.hxx>
111 #include <StepGeom_Plane.hxx>
112 #include <StepGeom_Polyline.hxx>
113 #include <StepGeom_QuasiUniformCurve.hxx>
114 #include <StepGeom_QuasiUniformCurveAndRationalBSplineCurve.hxx>
115 #include <StepGeom_QuasiUniformSurface.hxx>
116 #include <StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface.hxx>
117 #include <StepGeom_RectangularTrimmedSurface.hxx>
118 #include <StepGeom_SphericalSurface.hxx>
119 #include <StepGeom_Surface.hxx>
120 #include <StepGeom_SurfaceCurve.hxx>
121 #include <StepGeom_SurfaceOfLinearExtrusion.hxx>
122 #include <StepGeom_SurfaceOfRevolution.hxx>
123 #include <StepGeom_SurfaceReplica.hxx>
124 #include <StepGeom_SweptSurface.hxx>
125 #include <StepGeom_ToroidalSurface.hxx>
126 #include <StepGeom_CartesianTransformationOperator2d.hxx>
127 #include <StepGeom_CartesianTransformationOperator3d.hxx>
128 #include <StepGeom_TrimmedCurve.hxx>
129 #include <StepGeom_UniformCurve.hxx>
130 #include <StepGeom_UniformCurveAndRationalBSplineCurve.hxx>
131 #include <StepGeom_UniformSurface.hxx>
132 #include <StepGeom_UniformSurfaceAndRationalBSplineSurface.hxx>
133 #include <StepGeom_Vector.hxx>
135 #include <TopoDS.hxx>
136 #include <TopoDS_Face.hxx>
138 #include <UnitsMethods.hxx>
140 //=============================================================================
141 // Creation d' un Ax1Placement de Geom a partir d' un axis1_placement de Step
142 //=============================================================================
144 Handle(Geom_Axis1Placement) StepToGeom::MakeAxis1Placement (const Handle(StepGeom_Axis1Placement)& SA)
146 Handle(Geom_CartesianPoint) P = MakeCartesianPoint (SA->Location());
149 // sln 22.10.2001. CTS23496: If problems with creation of axis direction occur default direction is used
153 Handle(Geom_Direction) D1 = MakeDirection (SA->Axis());
157 return new Geom_Axis1Placement(P->Pnt(),D);
162 //=============================================================================
163 // Creation d' un Axis2Placement de Geom a partir d' un axis2_placement_3d de Step
164 //=============================================================================
166 Handle(Geom_Axis2Placement) StepToGeom::MakeAxis2Placement (const Handle(StepGeom_Axis2Placement3d)& SA)
168 Handle(Geom_CartesianPoint) P = MakeCartesianPoint (SA->Location());
171 const gp_Pnt Pgp = P->Pnt();
173 // sln 22.10.2001. CTS23496: If problems with creation of direction occur default direction is used (MakeLine(...) function)
174 gp_Dir Ngp(0.,0.,1.);
177 Handle(Geom_Direction) D = MakeDirection (SA->Axis());
183 Standard_Boolean isDefaultDirectionUsed = Standard_True;
184 if (SA->HasRefDirection())
186 Handle(Geom_Direction) D = MakeDirection (SA->RefDirection());
189 const gp_Dir Vxgp = D->Dir();
190 if (!Ngp.IsParallel(Vxgp,Precision::Angular()))
192 gpAx2 = gp_Ax2(Pgp, Ngp, Vxgp);
193 isDefaultDirectionUsed = Standard_False;
197 if(isDefaultDirectionUsed)
198 gpAx2 = gp_Ax2(Pgp, Ngp);
200 return new Geom_Axis2Placement(gpAx2);
205 //=============================================================================
206 // Creation d' un AxisPlacement de Geom2d a partir d' un axis2_placement_3d de Step
207 //=============================================================================
209 Handle(Geom2d_AxisPlacement) StepToGeom::MakeAxisPlacement (const Handle(StepGeom_Axis2Placement2d)& SA)
211 Handle(Geom2d_CartesianPoint) P = MakeCartesianPoint2d (SA->Location());
214 // sln 23.10.2001. CTS23496: If problems with creation of direction occur default direction is used
215 gp_Dir2d Vxgp(1.,0.);
216 if (SA->HasRefDirection()) {
217 Handle(Geom2d_Direction) Vx = MakeDirection2d (SA->RefDirection());
222 return new Geom2d_AxisPlacement(P->Pnt2d(),Vxgp);
227 //=============================================================================
228 // Creation d' une BoundedCurve de Geom a partir d' une BoundedCurve de Step
229 //=============================================================================
231 Handle(Geom_BoundedCurve) StepToGeom::MakeBoundedCurve (const Handle(StepGeom_BoundedCurve)& SC)
233 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)))
235 return MakeBSplineCurve (Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC));
237 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnots)))
239 return MakeBSplineCurve (Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC));
241 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve)))
243 return MakeTrimmedCurve (Handle(StepGeom_TrimmedCurve)::DownCast(SC));
246 // STEP BezierCurve, UniformCurve and QuasiUniformCurve are transformed into
247 // STEP BSplineCurve before being mapped onto CAS.CADE/SF
248 if (SC->IsKind(STANDARD_TYPE(StepGeom_BezierCurve)))
250 const Handle(StepGeom_BezierCurve) BzC = Handle(StepGeom_BezierCurve)::DownCast(SC);
251 Standard_Integer aDegree = BzC->Degree();
252 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
254 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
255 BSPL->SetDegree(aDegree);
256 BSPL->SetControlPointsList(BzC->ControlPointsList());
257 BSPL->SetCurveForm(BzC->CurveForm());
258 BSPL->SetClosedCurve(BzC->ClosedCurve());
259 BSPL->SetSelfIntersect(BzC->SelfIntersect());
260 // Compute Knots and KnotsMultiplicity
261 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,2);
262 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,2);
263 Kmult->SetValue(1, BzC->Degree() + 1);
264 Kmult->SetValue(2, BzC->Degree() + 1);
265 Knots->SetValue(1, 0.);
266 Knots->SetValue(2, 1.);
267 BSPL->SetKnotMultiplicities(Kmult);
268 BSPL->SetKnots(Knots);
270 return MakeBSplineCurve (BSPL);
273 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurve)))
275 const Handle(StepGeom_UniformCurve) UC = Handle(StepGeom_UniformCurve)::DownCast(SC);
276 Standard_Integer aDegree = UC->Degree();
277 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
279 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
280 BSPL->SetDegree(aDegree);
281 BSPL->SetControlPointsList(UC->ControlPointsList());
282 BSPL->SetCurveForm(UC->CurveForm());
283 BSPL->SetClosedCurve(UC->ClosedCurve());
284 BSPL->SetSelfIntersect(UC->SelfIntersect());
286 // Compute Knots and KnotsMultiplicity
287 const Standard_Integer nbK = BSPL->NbControlPointsList() + BSPL->Degree() + 1;
288 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
289 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
290 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
291 Kmult->SetValue(iUC, 1);
292 Knots->SetValue(iUC, iUC - 1.);
294 BSPL->SetKnotMultiplicities(Kmult);
295 BSPL->SetKnots(Knots);
297 return MakeBSplineCurve (BSPL);
300 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurve)))
302 const Handle(StepGeom_QuasiUniformCurve) QUC =
303 Handle(StepGeom_QuasiUniformCurve)::DownCast(SC);
304 Standard_Integer aDegree = QUC->Degree();
305 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
307 const Handle(StepGeom_BSplineCurveWithKnots) BSPL = new StepGeom_BSplineCurveWithKnots;
308 BSPL->SetDegree(aDegree);
309 BSPL->SetControlPointsList(QUC->ControlPointsList());
310 BSPL->SetCurveForm(QUC->CurveForm());
311 BSPL->SetClosedCurve(QUC->ClosedCurve());
312 BSPL->SetSelfIntersect(QUC->SelfIntersect());
314 // Compute Knots and KnotsMultiplicity
315 const Standard_Integer nbK = BSPL->NbControlPointsList() - BSPL->Degree() + 1;
316 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
317 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
318 for (Standard_Integer iQUC = 1 ; iQUC <= nbK ; iQUC ++) {
319 Kmult->SetValue(iQUC, 1);
320 Knots->SetValue(iQUC, iQUC - 1.);
322 Kmult->SetValue(1, BSPL->Degree() + 1);
323 Kmult->SetValue(nbK, BSPL->Degree() + 1);
324 BSPL->SetKnotMultiplicities(Kmult);
325 BSPL->SetKnots(Knots);
327 return MakeBSplineCurve (BSPL);
330 if (SC->IsKind(STANDARD_TYPE(StepGeom_UniformCurveAndRationalBSplineCurve)))
332 const Handle(StepGeom_UniformCurveAndRationalBSplineCurve) RUC =
333 Handle(StepGeom_UniformCurveAndRationalBSplineCurve)::DownCast(SC);
334 Standard_Integer aDegree = RUC->Degree();
335 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
337 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
338 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
340 // Compute Knots and KnotsMultiplicity
341 const Standard_Integer nbK = RUC->NbControlPointsList() + aDegree + 1;
342 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
343 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
344 for (Standard_Integer iUC = 1 ; iUC <= nbK ; iUC ++) {
345 Kmult->SetValue(iUC, 1);
346 Knots->SetValue(iUC, iUC - 1.);
349 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
350 RBSPL->Init(RUC->Name(), aDegree, RUC->ControlPointsList(), RUC->CurveForm(),
351 RUC->ClosedCurve(), RUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
354 return MakeBSplineCurve (RBSPL);
357 if (SC->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformCurveAndRationalBSplineCurve)))
359 const Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve) RQUC =
360 Handle(StepGeom_QuasiUniformCurveAndRationalBSplineCurve)::DownCast(SC);
361 Standard_Integer aDegree = RQUC->Degree();
362 if (aDegree < 1 || aDegree > Geom_BSplineCurve::MaxDegree())
364 const Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve) RBSPL =
365 new StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve;
367 // Compute Knots and KnotsMultiplicity
368 const Standard_Integer nbK = RQUC->NbControlPointsList() - aDegree + 1;
369 const Handle(TColStd_HArray1OfInteger) Kmult = new TColStd_HArray1OfInteger(1,nbK);
370 const Handle(TColStd_HArray1OfReal) Knots = new TColStd_HArray1OfReal(1,nbK);
371 for (Standard_Integer iRQUC = 1 ; iRQUC <= nbK ; iRQUC ++) {
372 Kmult->SetValue(iRQUC, 1);
373 Knots->SetValue(iRQUC, iRQUC - 1.);
375 Kmult->SetValue(1, aDegree + 1);
376 Kmult->SetValue(nbK, aDegree + 1);
377 // Initialize the BSplineCurveWithKnotsAndRationalBSplineCurve
378 RBSPL->Init(RQUC->Name(), aDegree, RQUC->ControlPointsList(), RQUC->CurveForm(),
379 RQUC->ClosedCurve(), RQUC->SelfIntersect(), Kmult, Knots, StepGeom_ktUnspecified,
380 RQUC->WeightsData());
382 return MakeBSplineCurve (RBSPL);
385 if (SC->IsKind(STANDARD_TYPE(StepGeom_Polyline)))
386 { //:n6 abv 15 Feb 99
387 return MakePolyline (Handle(StepGeom_Polyline)::DownCast (SC));
393 //=============================================================================
394 // Creation d' une BoundedCurve de Geom a partir d' une BoundedCurve de Step
395 //=============================================================================
397 Handle(Geom2d_BoundedCurve) StepToGeom::MakeBoundedCurve2d (const Handle(StepGeom_BoundedCurve)& SC)
399 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)))
401 return MakeBSplineCurve2d (Handle(StepGeom_BSplineCurveWithKnotsAndRationalBSplineCurve)::DownCast(SC));
403 if (SC->IsKind(STANDARD_TYPE(StepGeom_BSplineCurveWithKnots)))
405 return MakeBSplineCurve2d (Handle(StepGeom_BSplineCurveWithKnots)::DownCast(SC));
407 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve)))
409 return MakeTrimmedCurve2d (Handle(StepGeom_TrimmedCurve)::DownCast(SC));
411 if (SC->IsKind(STANDARD_TYPE(StepGeom_Polyline)))
412 { //:n6 abv 15 Feb 99
413 return MakePolyline2d (Handle(StepGeom_Polyline)::DownCast(SC));
415 return Handle(Geom2d_BoundedCurve)();
418 //=============================================================================
419 // Creation d' une BoundedSurface de Geom a partir d' une BoundedSurface de Step
420 //=============================================================================
422 Handle(Geom_BoundedSurface) StepToGeom::MakeBoundedSurface (const Handle(StepGeom_BoundedSurface)& SS)
424 if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)))
426 return MakeBSplineSurface (Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)::DownCast(SS));
428 if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnots)))
430 return MakeBSplineSurface (Handle(StepGeom_BSplineSurfaceWithKnots)::DownCast(SS));
432 if (SS->IsKind(STANDARD_TYPE(StepGeom_RectangularTrimmedSurface)))
434 return MakeRectangularTrimmedSurface (Handle(StepGeom_RectangularTrimmedSurface)::DownCast(SS));
437 // STEP BezierSurface, UniformSurface and QuasiUniformSurface are transformed
438 // into STEP BSplineSurface before being mapped onto CAS.CADE/SF
439 if (SS->IsKind(STANDARD_TYPE(StepGeom_BezierSurface))) {
440 const Handle(StepGeom_BezierSurface) BzS = Handle(StepGeom_BezierSurface)::DownCast(SS);
441 const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
442 BSPL->SetUDegree(BzS->UDegree());
443 BSPL->SetVDegree(BzS->VDegree());
444 BSPL->SetControlPointsList(BzS->ControlPointsList());
445 BSPL->SetSurfaceForm(BzS->SurfaceForm());
446 BSPL->SetUClosed(BzS->UClosed());
447 BSPL->SetVClosed(BzS->VClosed());
448 BSPL->SetSelfIntersect(BzS->SelfIntersect());
450 // Compute Knots and KnotsMultiplicity
451 const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,2);
452 const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,2);
453 const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,2);
454 const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,2);
455 UKmult->SetValue(1, BzS->UDegree() + 1);
456 UKmult->SetValue(2, BzS->UDegree() + 1);
457 VKmult->SetValue(1, BzS->VDegree() + 1);
458 VKmult->SetValue(2, BzS->VDegree() + 1);
459 UKnots->SetValue(1, 0.);
460 UKnots->SetValue(2, 1.);
461 VKnots->SetValue(1, 0.);
462 VKnots->SetValue(2, 1.);
463 BSPL->SetUMultiplicities(UKmult);
464 BSPL->SetVMultiplicities(VKmult);
465 BSPL->SetUKnots(UKnots);
466 BSPL->SetVKnots(VKnots);
468 return MakeBSplineSurface (BSPL);
471 if (SS->IsKind(STANDARD_TYPE(StepGeom_UniformSurface)))
473 const Handle(StepGeom_UniformSurface) US = Handle(StepGeom_UniformSurface)::DownCast(SS);
474 const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
475 BSPL->SetUDegree(US->UDegree());
476 BSPL->SetVDegree(US->VDegree());
477 BSPL->SetControlPointsList(US->ControlPointsList());
478 BSPL->SetSurfaceForm(US->SurfaceForm());
479 BSPL->SetUClosed(US->UClosed());
480 BSPL->SetVClosed(US->VClosed());
481 BSPL->SetSelfIntersect(US->SelfIntersect());
483 // Compute Knots and KnotsMultiplicity for U Direction
484 const Standard_Integer nbKU = BSPL->NbControlPointsListI() + BSPL->UDegree() + 1;
485 const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
486 const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
487 for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
488 UKmult->SetValue(iU, 1);
489 UKnots->SetValue(iU, iU - 1.);
491 BSPL->SetUMultiplicities(UKmult);
492 BSPL->SetUKnots(UKnots);
494 // Compute Knots and KnotsMultiplicity for V Direction
495 const Standard_Integer nbKV = BSPL->NbControlPointsListJ() + BSPL->VDegree() + 1;
496 const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
497 const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
498 for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
499 VKmult->SetValue(iV, 1);
500 VKnots->SetValue(iV, iV - 1.);
502 BSPL->SetVMultiplicities(VKmult);
503 BSPL->SetVKnots(VKnots);
505 return MakeBSplineSurface (BSPL);
508 if (SS->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformSurface)))
510 const Handle(StepGeom_QuasiUniformSurface) QUS =
511 Handle(StepGeom_QuasiUniformSurface)::DownCast(SS);
512 const Handle(StepGeom_BSplineSurfaceWithKnots) BSPL = new StepGeom_BSplineSurfaceWithKnots;
513 BSPL->SetUDegree(QUS->UDegree());
514 BSPL->SetVDegree(QUS->VDegree());
515 BSPL->SetControlPointsList(QUS->ControlPointsList());
516 BSPL->SetSurfaceForm(QUS->SurfaceForm());
517 BSPL->SetUClosed(QUS->UClosed());
518 BSPL->SetVClosed(QUS->VClosed());
519 BSPL->SetSelfIntersect(QUS->SelfIntersect());
521 // Compute Knots and KnotsMultiplicity for U Direction
522 const Standard_Integer nbKU = BSPL->NbControlPointsListI() - BSPL->UDegree() + 1;
523 const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
524 const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
525 for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
526 UKmult->SetValue(iU, 1);
527 UKnots->SetValue(iU, iU - 1.);
529 UKmult->SetValue(1, BSPL->UDegree() + 1);
530 UKmult->SetValue(nbKU, BSPL->UDegree() + 1);
531 BSPL->SetUMultiplicities(UKmult);
532 BSPL->SetUKnots(UKnots);
534 // Compute Knots and KnotsMultiplicity for V Direction
535 const Standard_Integer nbKV = BSPL->NbControlPointsListJ() - BSPL->VDegree() + 1;
536 const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
537 const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
538 for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
539 VKmult->SetValue(iV, 1);
540 VKnots->SetValue(iV, iV - 1.);
542 VKmult->SetValue(1, BSPL->VDegree() + 1);
543 VKmult->SetValue(nbKV, BSPL->VDegree() + 1);
544 BSPL->SetVMultiplicities(VKmult);
545 BSPL->SetVKnots(VKnots);
547 return MakeBSplineSurface (BSPL);
550 if (SS->IsKind(STANDARD_TYPE(StepGeom_UniformSurfaceAndRationalBSplineSurface)))
552 const Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface) RUS =
553 Handle(StepGeom_UniformSurfaceAndRationalBSplineSurface)::DownCast(SS);
554 const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) RBSPL =
555 new StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface;
557 // Compute Knots and KnotsMultiplicity for U Direction
558 const Standard_Integer nbKU = RUS->NbControlPointsListI() + RUS->UDegree() + 1;
559 const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
560 const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
561 for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
562 UKmult->SetValue(iU, 1);
563 UKnots->SetValue(iU, iU - 1.);
566 // Compute Knots and KnotsMultiplicity for V Direction
567 const Standard_Integer nbKV = RUS->NbControlPointsListJ() + RUS->VDegree() + 1;
568 const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
569 const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
570 for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
571 VKmult->SetValue(iV, 1);
572 VKnots->SetValue(iV, iV - 1.);
575 // Initialize the BSplineSurfaceWithKnotsAndRationalBSplineSurface
576 RBSPL->Init(RUS->Name(), RUS->UDegree(), RUS->VDegree(),
577 RUS->ControlPointsList(), RUS->SurfaceForm(),
578 RUS->UClosed(), RUS->VClosed(), RUS->SelfIntersect(),
579 UKmult, VKmult, UKnots, VKnots, StepGeom_ktUnspecified,
582 return MakeBSplineSurface (RBSPL);
585 if (SS->IsKind(STANDARD_TYPE(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface)))
587 const Handle(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface) RQUS =
588 Handle(StepGeom_QuasiUniformSurfaceAndRationalBSplineSurface)::DownCast(SS);
589 const Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) RBSPL =
590 new StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface;
592 // Compute Knots and KnotsMultiplicity for U Direction
593 const Standard_Integer nbKU = RQUS->NbControlPointsListI() - RQUS->UDegree() + 1;
594 const Handle(TColStd_HArray1OfInteger) UKmult = new TColStd_HArray1OfInteger(1,nbKU);
595 const Handle(TColStd_HArray1OfReal) UKnots = new TColStd_HArray1OfReal(1,nbKU);
596 for (Standard_Integer iU = 1 ; iU <= nbKU ; iU ++) {
597 UKmult->SetValue(iU, 1);
598 UKnots->SetValue(iU, iU - 1.);
600 UKmult->SetValue(1, RQUS->UDegree() + 1);
601 UKmult->SetValue(nbKU, RQUS->UDegree() + 1);
603 // Compute Knots and KnotsMultiplicity for V Direction
604 const Standard_Integer nbKV = RQUS->NbControlPointsListJ() - RQUS->VDegree() + 1;
605 const Handle(TColStd_HArray1OfInteger) VKmult = new TColStd_HArray1OfInteger(1,nbKV);
606 const Handle(TColStd_HArray1OfReal) VKnots = new TColStd_HArray1OfReal(1,nbKV);
607 for (Standard_Integer iV = 1 ; iV <= nbKV ; iV ++) {
608 VKmult->SetValue(iV, 1);
609 VKnots->SetValue(iV, iV - 1.);
611 VKmult->SetValue(1, RQUS->VDegree() + 1);
612 VKmult->SetValue(nbKV, RQUS->VDegree() + 1);
614 // Initialize the BSplineSurfaceWithKnotsAndRationalBSplineSurface
615 RBSPL->Init(RQUS->Name(), RQUS->UDegree(), RQUS->VDegree(), RQUS->ControlPointsList(),
616 RQUS->SurfaceForm(), RQUS->UClosed(), RQUS->VClosed(),
617 RQUS->SelfIntersect(), UKmult, VKmult, UKnots, VKnots, StepGeom_ktUnspecified,
618 RQUS->WeightsData());
619 return MakeBSplineSurface (RBSPL);
625 //=============================================================================
626 // Creation d' une BSplineCurve de Geom a partir d' une BSplineCurve de Step
627 //=============================================================================
629 Handle(Geom_BSplineCurve) StepToGeom::MakeBSplineCurve (const Handle(StepGeom_BSplineCurve)& SC)
631 #define Array1OfPnt_gen TColgp_Array1OfPnt
632 #define Pnt_gen gp_Pnt
634 #define CartesianPoint_gen Handle(Geom_CartesianPoint)
635 #define MakeCartesianPoint_gen MakeCartesianPoint
636 #define BSplineCurve_gen Geom_BSplineCurve
637 #define BSplineCurve_retour Handle(Geom_BSplineCurve)
638 #define MakeBSplineCurve_gen MakeBSplineCurve
639 #include "StepToGeom_MakeBSplineCurve.pxx"
640 #undef Array1OfPnt_gen
643 #undef CartesianPoint_gen
644 #undef MakeCartesianPoint_gen
645 #undef BSplineCurve_gen
646 #undef MakeBSplineCurve_gen
647 #undef BSplineCurve_retour
650 //=============================================================================
651 // Creation d' une BSplineCurve de Geom2d a partir d' une
652 // BSplineCurveWithKnotsAndRationalBSplineCurve de Step
653 //=============================================================================
655 Handle(Geom2d_BSplineCurve) StepToGeom::MakeBSplineCurve2d (const Handle(StepGeom_BSplineCurve)& SC)
657 #define Array1OfPnt_gen TColgp_Array1OfPnt2d
658 #define Pnt_gen gp_Pnt2d
659 #define CartesianPoint_gen Handle(Geom2d_CartesianPoint)
660 #define MakeCartesianPoint_gen MakeCartesianPoint2d
661 #define Pnt_fonc Pnt2d
662 #define BSplineCurve_gen Geom2d_BSplineCurve
663 #define BSplineCurve_retour Handle(Geom2d_BSplineCurve)
664 #define MakeBSplineCurve_gen MakeBSplineCurve2d
665 #include "StepToGeom_MakeBSplineCurve.pxx"
666 #undef Array1OfPnt_gen
668 #undef CartesianPoint_gen
669 #undef MakeCartesianPoint_gen
671 #undef BSplineCurve_gen
672 #undef MakeBSplineCurve_gen
673 #undef BSplineCurve_retour
676 //=============================================================================
677 // Creation d' une BSplineSurface de Geom a partir d' une
678 // BSplineSurface de Step
679 //=============================================================================
681 Handle(Geom_BSplineSurface) StepToGeom::MakeBSplineSurface (const Handle(StepGeom_BSplineSurface)& SS)
683 Standard_Integer i, j;
684 Handle(StepGeom_BSplineSurfaceWithKnots) BS;
685 Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface) BSR;
688 IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
690 Handle(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface)
692 BS = BSR->BSplineSurfaceWithKnots();
695 BS = Handle(StepGeom_BSplineSurfaceWithKnots)::DownCast(SS);
697 const Standard_Integer UDeg = BS->UDegree();
698 const Standard_Integer VDeg = BS->VDegree();
699 const Standard_Integer NUPoles = BS->NbControlPointsListI();
700 const Standard_Integer NVPoles = BS->NbControlPointsListJ();
701 const Handle(StepGeom_HArray2OfCartesianPoint)& aControlPointsList = BS->ControlPointsList();
702 TColgp_Array2OfPnt Poles(1,NUPoles,1,NVPoles);
703 for (i=1; i<=NUPoles; i++) {
704 for (j=1; j<=NVPoles; j++) {
705 Handle(Geom_CartesianPoint) P = MakeCartesianPoint (aControlPointsList->Value(i,j));
707 Poles.SetValue(i,j,P->Pnt());
712 const Standard_Integer NUKnots = BS->NbUMultiplicities();
713 const Handle(TColStd_HArray1OfInteger)& aUMultiplicities = BS->UMultiplicities();
714 const Handle(TColStd_HArray1OfReal)& aUKnots = BS->UKnots();
716 // count number of unique uknots
717 Standard_Real lastKnot = RealFirst();
718 Standard_Integer NUKnotsUnique = 0;
719 for (i=1; i<=NUKnots; i++) {
720 if (aUKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
722 lastKnot = aUKnots->Value(i);
726 // set umultiplicities and uknots
727 TColStd_Array1OfInteger UMult(1,NUKnotsUnique);
728 TColStd_Array1OfReal KUn(1,NUKnotsUnique);
729 Standard_Integer pos = 1;
730 lastKnot = aUKnots->Value(1);
731 KUn.SetValue(1, aUKnots->Value(1));
732 UMult.SetValue(1, aUMultiplicities->Value(1));
733 for (i=2; i<=NUKnots; i++) {
734 if (aUKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
736 KUn.SetValue(pos, aUKnots->Value(i));
737 UMult.SetValue(pos, aUMultiplicities->Value(i));
738 lastKnot = aUKnots->Value(i);
741 // Knot not unique, increase multiplicity
742 Standard_Integer curMult = UMult.Value(pos);
743 UMult.SetValue(pos, curMult + aUMultiplicities->Value(i));
746 const Standard_Integer NVKnots = BS->NbVMultiplicities();
747 const Handle(TColStd_HArray1OfInteger)& aVMultiplicities = BS->VMultiplicities();
748 const Handle(TColStd_HArray1OfReal)& aVKnots = BS->VKnots();
750 // count number of unique vknots
751 lastKnot = RealFirst();
752 Standard_Integer NVKnotsUnique = 0;
753 for (i=1; i<=NVKnots; i++) {
754 if (aVKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
756 lastKnot = aVKnots->Value(i);
760 // set vmultiplicities and vknots
761 TColStd_Array1OfInteger VMult(1,NVKnotsUnique);
762 TColStd_Array1OfReal KVn(1,NVKnotsUnique);
764 lastKnot = aVKnots->Value(1);
765 KVn.SetValue(1, aVKnots->Value(1));
766 VMult.SetValue(1, aVMultiplicities->Value(1));
767 for (i=2; i<=NVKnots; i++) {
768 if (aVKnots->Value(i) - lastKnot > Epsilon (Abs(lastKnot))) {
770 KVn.SetValue(pos, aVKnots->Value(i));
771 VMult.SetValue(pos, aVMultiplicities->Value(i));
772 lastKnot = aVKnots->Value(i);
775 // Knot not unique, increase multiplicity
776 Standard_Integer curMult = VMult.Value(pos);
777 VMult.SetValue(pos, curMult + aVMultiplicities->Value(i));
781 // --- Does the Surface Descriptor LOOKS like a U and/or V Periodic ---
782 // --- Descriptor ? ---
784 // --- U Periodic ? ---
786 Standard_Integer SumMult = 0;
787 for (i=1; i<=NUKnotsUnique; i++) {
788 SumMult += UMult.Value(i);
791 Standard_Boolean shouldBeUPeriodic = Standard_False;
792 if (SumMult == (NUPoles + UDeg + 1)) {
793 //shouldBeUPeriodic = Standard_False;
795 else if ((UMult.Value(1) ==
796 UMult.Value(NUKnotsUnique)) &&
797 ((SumMult - UMult.Value(1))== NUPoles)) {
798 shouldBeUPeriodic = Standard_True;
801 // --- V Periodic ? ---
804 for (i=1; i<=NVKnotsUnique; i++) {
805 SumMult += VMult.Value(i);
808 Standard_Boolean shouldBeVPeriodic = Standard_False;
809 if (SumMult == (NVPoles + VDeg + 1)) {
810 //shouldBeVPeriodic = Standard_False;
812 else if ((VMult.Value(1) ==
813 VMult.Value(NVKnotsUnique)) &&
814 ((SumMult - VMult.Value(1)) == NVPoles)) {
815 shouldBeVPeriodic = Standard_True;
818 Handle(Geom_BSplineSurface) CS;
819 if (SS->IsKind(STANDARD_TYPE(StepGeom_BSplineSurfaceWithKnotsAndRationalBSplineSurface))) {
820 const Handle(TColStd_HArray2OfReal)& aWeight = BSR->WeightsData();
821 TColStd_Array2OfReal W(1,NUPoles,1,NVPoles);
822 for (i=1; i<=NUPoles; i++) {
823 for (j=1; j<=NVPoles; j++) {
824 W.SetValue(i,j,aWeight->Value(i,j));
827 CS = new Geom_BSplineSurface(Poles, W, KUn, KVn, UMult,
833 CS = new Geom_BSplineSurface(Poles, KUn, KVn, UMult,
840 //=============================================================================
841 // Creation d' un CartesianPoint de Geom a partir d' un CartesianPoint de Step
842 //=============================================================================
844 Handle(Geom_CartesianPoint) StepToGeom::MakeCartesianPoint (const Handle(StepGeom_CartesianPoint)& SP)
846 if (SP->NbCoordinates() == 3)
848 const Standard_Real LF = UnitsMethods::LengthFactor();
849 const Standard_Real X = SP->CoordinatesValue(1) * LF;
850 const Standard_Real Y = SP->CoordinatesValue(2) * LF;
851 const Standard_Real Z = SP->CoordinatesValue(3) * LF;
852 return new Geom_CartesianPoint(X, Y, Z);
857 //=============================================================================
858 // Creation d' un CartesianPoint de Geom2d a partir d' un CartesianPoint de
860 //=============================================================================
862 Handle(Geom2d_CartesianPoint) StepToGeom::MakeCartesianPoint2d (const Handle(StepGeom_CartesianPoint)& SP)
864 if (SP->NbCoordinates() == 2)
866 const Standard_Real X = SP->CoordinatesValue(1);
867 const Standard_Real Y = SP->CoordinatesValue(2);
868 return new Geom2d_CartesianPoint(X, Y);
873 //=============================================================================
874 // Creation d' un Circle de Geom a partir d' un Circle de Step
875 //=============================================================================
877 Handle(Geom_Circle) StepToGeom::MakeCircle (const Handle(StepGeom_Circle)& SC)
879 const StepGeom_Axis2Placement AxisSelect = SC->Position();
880 if (AxisSelect.CaseNum(AxisSelect.Value()) == 2)
882 Handle(Geom_Axis2Placement) A =
883 MakeAxis2Placement (Handle(StepGeom_Axis2Placement3d)::DownCast(AxisSelect.Value()));
886 return new Geom_Circle(A->Ax2(),SC->Radius() * UnitsMethods::LengthFactor());
892 //=============================================================================
893 // Creation d' un Circle de Geom2d a partir d' un Circle de Step
894 //=============================================================================
896 Handle(Geom2d_Circle) StepToGeom::MakeCircle2d (const Handle(StepGeom_Circle)& SC)
898 const StepGeom_Axis2Placement AxisSelect = SC->Position();
899 if (AxisSelect.CaseNum(AxisSelect.Value()) == 1) {
900 Handle(Geom2d_AxisPlacement) A1 =
901 MakeAxisPlacement (Handle(StepGeom_Axis2Placement2d)::DownCast(AxisSelect.Value()));
904 return new Geom2d_Circle (A1->Ax2d(), SC->Radius());
910 //=============================================================================
911 // Creation d' une Conic de Geom a partir d' une Conic de Step
912 //=============================================================================
914 Handle(Geom_Conic) StepToGeom::MakeConic (const Handle(StepGeom_Conic)& SC)
916 if (SC->IsKind(STANDARD_TYPE(StepGeom_Circle))) {
917 return MakeCircle (Handle(StepGeom_Circle)::DownCast(SC));
919 if (SC->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
920 return MakeEllipse (Handle(StepGeom_Ellipse)::DownCast(SC));
922 if (SC->IsKind(STANDARD_TYPE(StepGeom_Hyperbola))) {
923 return MakeHyperbola (Handle(StepGeom_Hyperbola)::DownCast(SC));
925 if (SC->IsKind(STANDARD_TYPE(StepGeom_Parabola))) {
926 return MakeParabola (Handle(StepGeom_Parabola)::DownCast(SC));
928 // Attention : Other conic shall be implemented !
932 //=============================================================================
933 // Creation d' une Conic de Geom2d a partir d' une Conic de Step
934 //=============================================================================
936 Handle(Geom2d_Conic) StepToGeom::MakeConic2d (const Handle(StepGeom_Conic)& SC)
938 if (SC->IsKind(STANDARD_TYPE(StepGeom_Circle))) {
939 return MakeCircle2d (Handle(StepGeom_Circle)::DownCast(SC));
941 if (SC->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
942 return MakeEllipse2d (Handle(StepGeom_Ellipse)::DownCast(SC));
944 if (SC->IsKind(STANDARD_TYPE(StepGeom_Hyperbola))) {
945 return MakeHyperbola2d (Handle(StepGeom_Hyperbola)::DownCast(SC));
947 if (SC->IsKind(STANDARD_TYPE(StepGeom_Parabola))) {
948 return MakeParabola2d (Handle(StepGeom_Parabola)::DownCast(SC));
950 // Attention : Other conic shall be implemented !
951 return Handle(Geom2d_Conic)();
954 //=============================================================================
955 // Creation d' une ConicalSurface de Geom a partir d' une ConicalSurface de
957 //=============================================================================
959 Handle(Geom_ConicalSurface) StepToGeom::MakeConicalSurface (const Handle(StepGeom_ConicalSurface)& SS)
961 Handle(Geom_Axis2Placement) A = MakeAxis2Placement (SS->Position());
964 const Standard_Real R = SS->Radius() * UnitsMethods::LengthFactor();
965 const Standard_Real Ang = SS->SemiAngle() * UnitsMethods::PlaneAngleFactor();
966 //#2(K3-3) rln 12/02/98 ProSTEP ct_turbine-A.stp entity #518, #3571 (gp::Resolution() is too little)
967 return new Geom_ConicalSurface(A->Ax2(), Max(Ang, Precision::Angular()), R);
972 //=============================================================================
973 // Creation d' une Curve de Geom a partir d' une Curve de Step
974 //=============================================================================
976 Handle(Geom_Curve) StepToGeom::MakeCurve (const Handle(StepGeom_Curve)& SC)
979 return Handle(Geom_Curve)();
981 if (SC->IsKind(STANDARD_TYPE(StepGeom_Line))) {
982 return MakeLine (Handle(StepGeom_Line)::DownCast(SC));
984 if (SC->IsKind(STANDARD_TYPE(StepGeom_TrimmedCurve))) {
985 return MakeTrimmedCurve (Handle(StepGeom_TrimmedCurve)::DownCast(SC));
987 if (SC->IsKind(STANDARD_TYPE(StepGeom_Conic))) {
988 return MakeConic (Handle(StepGeom_Conic)::DownCast(SC));
990 if (SC->IsKind(STANDARD_TYPE(StepGeom_BoundedCurve))) {
991 return MakeBoundedCurve (Handle(StepGeom_BoundedCurve)::DownCast(SC));
993 if (SC->IsKind(STANDARD_TYPE(StepGeom_CurveReplica))) { //:n7 abv 16 Feb 99
994 const Handle(StepGeom_CurveReplica) CR = Handle(StepGeom_CurveReplica)::DownCast(SC);
995 const Handle(StepGeom_Curve) PC = CR->ParentCurve();
996 const Handle(StepGeom_CartesianTransformationOperator3d) T =
997 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(CR->Transformation());
998 // protect against cyclic references and wrong type of cartop
999 if ( !T.IsNull() && PC != SC )
1001 Handle(Geom_Curve) C1 = MakeCurve (PC);
1005 if (MakeTransformation3d(T,T1))
1007 C1->Transform ( T1 );
1013 else if (SC->IsKind(STANDARD_TYPE(StepGeom_OffsetCurve3d))) { //:o2 abv 17 Feb 99
1014 const Handle(StepGeom_OffsetCurve3d) OC = Handle(StepGeom_OffsetCurve3d)::DownCast(SC);
1015 const Handle(StepGeom_Curve) BC = OC->BasisCurve();
1016 if ( BC != SC ) { // protect against loop
1017 Handle(Geom_Curve) C1 = MakeCurve (BC);
1020 Handle(Geom_Direction) RD = MakeDirection(OC->RefDirection());
1023 return new Geom_OffsetCurve ( C1, -OC->Distance(), RD->Dir() );
1028 else if (SC->IsKind(STANDARD_TYPE(StepGeom_SurfaceCurve))) { //:o5 abv 17 Feb 99
1029 const Handle(StepGeom_SurfaceCurve) SurfC = Handle(StepGeom_SurfaceCurve)::DownCast(SC);
1030 return MakeCurve (SurfC->Curve3d());
1035 //=============================================================================
1036 // Creation d' une Curve de Geom2d a partir d' une Curve de Step
1037 //=============================================================================
1039 Handle(Geom2d_Curve) StepToGeom::MakeCurve2d (const Handle(StepGeom_Curve)& SC)
1041 if (SC->IsKind(STANDARD_TYPE(StepGeom_Line))) {
1042 return MakeLine2d (Handle(StepGeom_Line)::DownCast(SC));
1044 if (SC->IsKind(STANDARD_TYPE(StepGeom_Conic))) {
1045 return MakeConic2d (Handle(StepGeom_Conic)::DownCast(SC));
1047 if (SC->IsKind(STANDARD_TYPE(StepGeom_BoundedCurve))) {
1048 return MakeBoundedCurve2d (Handle(StepGeom_BoundedCurve)::DownCast(SC));
1050 if (SC->IsKind(STANDARD_TYPE(StepGeom_CurveReplica))) { //:n7 abv 16 Feb 99
1051 const Handle(StepGeom_CurveReplica) CR = Handle(StepGeom_CurveReplica)::DownCast(SC);
1052 const Handle(StepGeom_Curve) PC = CR->ParentCurve();
1053 const Handle(StepGeom_CartesianTransformationOperator2d) T =
1054 Handle(StepGeom_CartesianTransformationOperator2d)::DownCast(CR->Transformation());
1055 // protect against cyclic references and wrong type of cartop
1056 if ( !T.IsNull() && PC != SC )
1058 Handle(Geom2d_Curve) C1 = MakeCurve2d (PC);
1062 if (MakeTransformation2d(T,T1))
1064 C1->Transform ( T1 );
1073 //=============================================================================
1074 // Creation d' une CylindricalSurface de Geom a partir d' une
1075 // CylindricalSurface de Step
1076 //=============================================================================
1078 Handle(Geom_CylindricalSurface) StepToGeom::MakeCylindricalSurface (const Handle(StepGeom_CylindricalSurface)& SS)
1080 Handle(Geom_Axis2Placement) A = MakeAxis2Placement(SS->Position());
1083 return new Geom_CylindricalSurface(A->Ax2(), SS->Radius() * UnitsMethods::LengthFactor());
1088 //=============================================================================
1089 // Creation d' un Direction de Geom a partir d' un Direction de Step
1090 //=============================================================================
1092 Handle(Geom_Direction) StepToGeom::MakeDirection (const Handle(StepGeom_Direction)& SD)
1094 if (SD->NbDirectionRatios() >= 3)
1096 const Standard_Real X = SD->DirectionRatiosValue(1);
1097 const Standard_Real Y = SD->DirectionRatiosValue(2);
1098 const Standard_Real Z = SD->DirectionRatiosValue(3);
1099 // sln 22.10.2001. CTS23496: Direction is not created if it has null magnitude
1100 if (gp_XYZ(X, Y, Z).SquareModulus() > gp::Resolution()*gp::Resolution())
1102 return new Geom_Direction(X, Y, Z);
1108 //=============================================================================
1109 // Creation d' un Direction de Geom2d a partir d' un Direction de Step
1110 //=============================================================================
1112 Handle(Geom2d_Direction) StepToGeom::MakeDirection2d (const Handle(StepGeom_Direction)& SD)
1114 if (SD->NbDirectionRatios() >= 2)
1116 const Standard_Real X = SD->DirectionRatiosValue(1);
1117 const Standard_Real Y = SD->DirectionRatiosValue(2);
1118 // sln 23.10.2001. CTS23496: Direction is not created if it has null magnitude
1119 if(gp_XY(X,Y).SquareModulus() > gp::Resolution()*gp::Resolution())
1121 return new Geom2d_Direction(X, Y);
1127 //=============================================================================
1128 // Creation d' une ElementarySurface de Geom a partir d' une
1129 // ElementarySurface de Step
1130 //=============================================================================
1132 Handle(Geom_ElementarySurface) StepToGeom::MakeElementarySurface (const Handle(StepGeom_ElementarySurface)& SS)
1134 if (SS->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
1135 return MakePlane (Handle(StepGeom_Plane)::DownCast(SS));
1137 if (SS->IsKind(STANDARD_TYPE(StepGeom_CylindricalSurface))) {
1138 return MakeCylindricalSurface (Handle(StepGeom_CylindricalSurface)::DownCast(SS));
1140 if (SS->IsKind(STANDARD_TYPE(StepGeom_ConicalSurface))) {
1141 return MakeConicalSurface (Handle(StepGeom_ConicalSurface)::DownCast(SS));
1143 if (SS->IsKind(STANDARD_TYPE(StepGeom_SphericalSurface))) {
1144 return MakeSphericalSurface (Handle(StepGeom_SphericalSurface)::DownCast(SS));
1146 if (SS->IsKind(STANDARD_TYPE(StepGeom_ToroidalSurface))) {
1147 return MakeToroidalSurface (Handle(StepGeom_ToroidalSurface)::DownCast(SS));
1152 //=============================================================================
1153 // Creation d' un Ellipse de Geom a partir d' un Ellipse de Step
1154 //=============================================================================
1156 Handle(Geom_Ellipse) StepToGeom::MakeEllipse (const Handle(StepGeom_Ellipse)& SC)
1158 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1159 if (AxisSelect.CaseNum(AxisSelect.Value()) == 2) {
1160 Handle(Geom_Axis2Placement) A1 = MakeAxis2Placement (Handle(StepGeom_Axis2Placement3d)::DownCast(AxisSelect.Value()));
1163 gp_Ax2 A( A1->Ax2() );
1164 const Standard_Real LF = UnitsMethods::LengthFactor();
1165 const Standard_Real majorR = SC->SemiAxis1() * LF;
1166 const Standard_Real minorR = SC->SemiAxis2() * LF;
1167 if ( majorR - minorR >= 0. ) { //:o9 abv 19 Feb 99
1168 return new Geom_Ellipse(A, majorR, minorR);
1172 A.SetXDirection ( A.XDirection() ^ A.Direction() );
1173 return new Geom_Ellipse(A, minorR, majorR);
1180 //=============================================================================
1181 // Creation d' un Ellipse de Geom2d a partir d' un Ellipse de Step
1182 //=============================================================================
1184 Handle(Geom2d_Ellipse) StepToGeom::MakeEllipse2d (const Handle(StepGeom_Ellipse)& SC)
1186 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1187 if (AxisSelect.CaseNum(AxisSelect.Value()) == 1) {
1188 Handle(Geom2d_AxisPlacement) A1 = MakeAxisPlacement (Handle(StepGeom_Axis2Placement2d)::DownCast(AxisSelect.Value()));
1191 gp_Ax22d A( A1->Ax2d() );
1192 const Standard_Real majorR = SC->SemiAxis1();
1193 const Standard_Real minorR = SC->SemiAxis2();
1194 if ( majorR - minorR >= 0. ) { //:o9 abv 19 Feb 99: bm4_id_punch_b.stp #678: protection
1195 return new Geom2d_Ellipse(A, majorR, minorR);
1198 const gp_Dir2d X = A.XDirection();
1199 A.SetXDirection ( gp_Dir2d ( X.X(), -X.Y() ) );
1200 return new Geom2d_Ellipse(A, minorR, majorR);
1207 //=============================================================================
1208 // Creation d' un Hyperbola de Geom a partir d' un Hyperbola de Step
1209 //=============================================================================
1211 Handle(Geom_Hyperbola) StepToGeom::MakeHyperbola (const Handle(StepGeom_Hyperbola)& SC)
1213 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1214 if (AxisSelect.CaseNum(AxisSelect.Value()) == 2)
1216 Handle(Geom_Axis2Placement) A1 = MakeAxis2Placement (Handle(StepGeom_Axis2Placement3d)::DownCast(AxisSelect.Value()));
1219 const gp_Ax2 A( A1->Ax2() );
1220 const Standard_Real LF = UnitsMethods::LengthFactor();
1221 return new Geom_Hyperbola(A, SC->SemiAxis() * LF, SC->SemiImagAxis() * LF);
1227 //=============================================================================
1228 // Creation d' un Hyperbola de Geom2d a partir d' un Hyperbola de Step
1229 //=============================================================================
1231 Handle(Geom2d_Hyperbola) StepToGeom::MakeHyperbola2d (const Handle(StepGeom_Hyperbola)& SC)
1233 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1234 if (AxisSelect.CaseNum(AxisSelect.Value()) == 1)
1236 Handle(Geom2d_AxisPlacement) A1 = MakeAxisPlacement (Handle(StepGeom_Axis2Placement2d)::DownCast(AxisSelect.Value()));
1239 const gp_Ax22d A( A1->Ax2d() );
1240 return new Geom2d_Hyperbola(A, SC->SemiAxis(), SC->SemiImagAxis());
1246 //=============================================================================
1247 // Creation d' une Line de Geom a partir d' une Line de Step
1248 //=============================================================================
1250 Handle(Geom_Line) StepToGeom::MakeLine (const Handle(StepGeom_Line)& SC)
1252 Handle(Geom_CartesianPoint) P = MakeCartesianPoint(SC->Pnt());
1255 // sln 22.10.2001. CTS23496: Line is not created if direction have not been succesfully created
1256 Handle(Geom_VectorWithMagnitude) D = MakeVectorWithMagnitude (SC->Dir());
1259 if( D->Vec().SquareMagnitude() < Precision::Confusion() * Precision::Confusion())
1261 const gp_Dir V(D->Vec());
1262 return new Geom_Line(P->Pnt(), V);
1268 //=============================================================================
1269 // Creation d' une Line de Geom2d a partir d' une Line de Step
1270 //=============================================================================
1272 Handle(Geom2d_Line) StepToGeom::MakeLine2d (const Handle(StepGeom_Line)& SC)
1274 Handle(Geom2d_CartesianPoint) P = MakeCartesianPoint2d(SC->Pnt());
1277 // sln 23.10.2001. CTS23496: Line is not created if direction have not been succesfully created
1278 Handle(Geom2d_VectorWithMagnitude) D = MakeVectorWithMagnitude2d (SC->Dir());
1281 const gp_Dir2d D1(D->Vec2d());
1282 return new Geom2d_Line(P->Pnt2d(), D1);
1288 //=============================================================================
1289 // Creation d' un Parabola de Geom a partir d' un Parabola de Step
1290 //=============================================================================
1292 Handle(Geom_Parabola) StepToGeom::MakeParabola (const Handle(StepGeom_Parabola)& SC)
1294 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1295 if (AxisSelect.CaseNum(AxisSelect.Value()) == 2)
1297 Handle(Geom_Axis2Placement) A = MakeAxis2Placement (Handle(StepGeom_Axis2Placement3d)::DownCast(AxisSelect.Value()));
1300 return new Geom_Parabola(A->Ax2(), SC->FocalDist() * UnitsMethods::LengthFactor());
1306 //=============================================================================
1307 // Creation d' un Parabola de Geom2d a partir d' un Parabola de Step
1308 //=============================================================================
1310 Handle(Geom2d_Parabola) StepToGeom::MakeParabola2d (const Handle(StepGeom_Parabola)& SC)
1312 const StepGeom_Axis2Placement AxisSelect = SC->Position();
1313 if (AxisSelect.CaseNum(AxisSelect.Value()) == 1) {
1314 Handle(Geom2d_AxisPlacement) A1 = MakeAxisPlacement (Handle(StepGeom_Axis2Placement2d)::DownCast(AxisSelect.Value()));
1317 const gp_Ax22d A( A1->Ax2d() );
1318 return new Geom2d_Parabola(A, SC->FocalDist());
1324 //=============================================================================
1325 // Creation d' un Plane de Geom a partir d' un plane de Step
1326 //=============================================================================
1328 Handle(Geom_Plane) StepToGeom::MakePlane (const Handle(StepGeom_Plane)& SP)
1330 Handle(Geom_Axis2Placement) A = MakeAxis2Placement (SP->Position());
1333 return new Geom_Plane(A->Ax2());
1338 //=======================================================================
1339 //function : MakePolyline
1341 //=======================================================================
1343 Handle(Geom_BSplineCurve) StepToGeom::MakePolyline (const Handle(StepGeom_Polyline)& SPL)
1346 return Handle(Geom_BSplineCurve)();
1348 const Standard_Integer nbp = SPL->NbPoints();
1351 TColgp_Array1OfPnt Poles ( 1, nbp );
1352 TColStd_Array1OfReal Knots ( 1, nbp );
1353 TColStd_Array1OfInteger Mults ( 1, nbp );
1355 for ( Standard_Integer i=1; i <= nbp; i++ )
1357 Handle(Geom_CartesianPoint) P = MakeCartesianPoint (SPL->PointsValue(i));
1359 Poles.SetValue ( i, P->Pnt() );
1362 Knots.SetValue ( i, Standard_Real(i-1) );
1363 Mults.SetValue ( i, 1 );
1365 Mults.SetValue ( 1, 2 );
1366 Mults.SetValue ( nbp, 2 );
1368 return new Geom_BSplineCurve ( Poles, Knots, Mults, 1 );
1373 //=======================================================================
1374 //function : MakePolyline2d
1376 //=======================================================================
1378 Handle(Geom2d_BSplineCurve) StepToGeom::MakePolyline2d (const Handle(StepGeom_Polyline)& SPL)
1381 return Handle(Geom2d_BSplineCurve)();
1383 const Standard_Integer nbp = SPL->NbPoints();
1386 TColgp_Array1OfPnt2d Poles ( 1, nbp );
1387 TColStd_Array1OfReal Knots ( 1, nbp );
1388 TColStd_Array1OfInteger Mults ( 1, nbp );
1390 for ( Standard_Integer i=1; i <= nbp; i++ )
1392 Handle(Geom2d_CartesianPoint) P = MakeCartesianPoint2d (SPL->PointsValue(i));
1394 Poles.SetValue ( i, P->Pnt2d() );
1397 Knots.SetValue ( i, Standard_Real(i-1) );
1398 Mults.SetValue ( i, 1 );
1400 Mults.SetValue ( 1, 2 );
1401 Mults.SetValue ( nbp, 2 );
1403 return new Geom2d_BSplineCurve ( Poles, Knots, Mults, 1 );
1408 //=============================================================================
1409 // Creation d' une RectangularTrimmedSurface de Geom a partir d' une
1410 // RectangularTrimmedSurface de Step
1411 //=============================================================================
1413 Handle(Geom_RectangularTrimmedSurface) StepToGeom::MakeRectangularTrimmedSurface (const Handle(StepGeom_RectangularTrimmedSurface)& SS)
1415 Handle(Geom_Surface) theBasis = MakeSurface (SS->BasisSurface());
1416 if (! theBasis.IsNull())
1418 // -----------------------------------------
1419 // Modification of the Trimming Parameters ?
1420 // -----------------------------------------
1422 Standard_Real uFact = 1.;
1423 Standard_Real vFact = 1.;
1424 const Standard_Real LengthFact = UnitsMethods::LengthFactor();
1425 const Standard_Real AngleFact = UnitsMethods::PlaneAngleFactor(); // abv 30.06.00 trj4_k1_geo-tc-214.stp #1477: PI/180.;
1427 if (theBasis->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1428 theBasis->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) {
1429 uFact = vFact = AngleFact;
1431 else if (theBasis->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
1435 else if ( theBasis->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
1438 else if (theBasis->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
1439 const Handle(Geom_ConicalSurface) conicS = Handle(Geom_ConicalSurface)::DownCast(theBasis);
1441 vFact = LengthFact / Cos(conicS->SemiAngle());
1443 else if (theBasis->IsKind(STANDARD_TYPE(Geom_Plane))) {
1444 uFact = vFact = LengthFact;
1447 const Standard_Real U1 = SS->U1() * uFact;
1448 const Standard_Real U2 = SS->U2() * uFact;
1449 const Standard_Real V1 = SS->V1() * vFact;
1450 const Standard_Real V2 = SS->V2() * vFact;
1452 return new Geom_RectangularTrimmedSurface(theBasis, U1, U2, V1, V2, SS->Usense(), SS->Vsense());
1457 //=============================================================================
1458 // Creation d' une SphericalSurface de Geom a partir d' une
1459 // SphericalSurface de Step
1460 //=============================================================================
1462 Handle(Geom_SphericalSurface) StepToGeom::MakeSphericalSurface (const Handle(StepGeom_SphericalSurface)& SS)
1464 Handle(Geom_Axis2Placement) A = MakeAxis2Placement (SS->Position());
1467 return new Geom_SphericalSurface(A->Ax2(), SS->Radius() * UnitsMethods::LengthFactor());
1472 //=============================================================================
1473 // Creation d' une Surface de Geom a partir d' une Surface de Step
1474 //=============================================================================
1476 Handle(Geom_Surface) StepToGeom::MakeSurface (const Handle(StepGeom_Surface)& SS)
1478 // sln 01.10.2001 BUC61003. If entry shell is NULL do nothing
1480 return Handle(Geom_Surface)();
1485 if (SS->IsKind(STANDARD_TYPE(StepGeom_BoundedSurface))) {
1486 return MakeBoundedSurface (Handle(StepGeom_BoundedSurface)::DownCast(SS));
1488 if (SS->IsKind(STANDARD_TYPE(StepGeom_ElementarySurface))) {
1489 const Handle(StepGeom_ElementarySurface) S1 = Handle(StepGeom_ElementarySurface)::DownCast(SS);
1490 if(S1->Position().IsNull())
1491 return Handle(Geom_Surface)();
1493 return MakeElementarySurface (S1);
1495 if (SS->IsKind(STANDARD_TYPE(StepGeom_SweptSurface))) {
1496 return MakeSweptSurface (Handle(StepGeom_SweptSurface)::DownCast(SS));
1498 if (SS->IsKind(STANDARD_TYPE(StepGeom_OffsetSurface))) { //:d4 abv 12 Mar 98
1499 const Handle(StepGeom_OffsetSurface) OS = Handle(StepGeom_OffsetSurface)::DownCast(SS);
1501 Handle(Geom_Surface) aBasisSurface = MakeSurface (OS->BasisSurface());
1502 if (! aBasisSurface.IsNull())
1504 // sln 03.10.01. BUC61003. creation of offset surface is corrected
1505 const Standard_Real anOffset = OS->Distance() * UnitsMethods::LengthFactor();
1506 if (aBasisSurface->Continuity() == GeomAbs_C0)
1508 const BRepBuilderAPI_MakeFace aBFace(aBasisSurface, Precision::Confusion());
1509 if (aBFace.IsDone())
1511 const TopoDS_Shape aResult = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape(aBFace.Face(), Abs(anOffset));
1512 if (aResult.ShapeType() == TopAbs_FACE)
1514 aBasisSurface = BRep_Tool::Surface(TopoDS::Face(aResult));
1518 if(aBasisSurface->Continuity() != GeomAbs_C0)
1520 return new Geom_OffsetSurface ( aBasisSurface, anOffset );
1524 else if (SS->IsKind(STANDARD_TYPE(StepGeom_SurfaceReplica))) { //:n7 abv 16 Feb 99
1525 const Handle(StepGeom_SurfaceReplica) SR = Handle(StepGeom_SurfaceReplica)::DownCast(SS);
1526 const Handle(StepGeom_Surface) PS = SR->ParentSurface();
1527 const Handle(StepGeom_CartesianTransformationOperator3d) T = SR->Transformation();
1528 // protect against cyclic references and wrong type of cartop
1529 if ( !T.IsNull() && PS != SS ) {
1530 Handle(Geom_Surface) S1 = MakeSurface (PS);
1534 if (MakeTransformation3d(T,T1))
1536 S1->Transform ( T1 );
1543 catch(Standard_Failure const& anException) {
1547 std::cout<<"Warning: MakeSurface: Exception:";
1548 anException.Print(std::cout); std::cout << std::endl;
1555 //=============================================================================
1556 // Creation d' une SurfaceOfLinearExtrusion de Geom a partir d' une
1557 // SurfaceOfLinearExtrusion de Step
1558 //=============================================================================
1560 Handle(Geom_SurfaceOfLinearExtrusion) StepToGeom::MakeSurfaceOfLinearExtrusion (const Handle(StepGeom_SurfaceOfLinearExtrusion)& SS)
1562 Handle(Geom_Curve) C = MakeCurve (SS->SweptCurve());
1565 // sln 23.10.2001. CTS23496: Surface is not created if extrusion axis have not been succesfully created
1566 Handle(Geom_VectorWithMagnitude) V = MakeVectorWithMagnitude (SS->ExtrusionAxis());
1569 const gp_Dir D(V->Vec());
1570 Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(C);
1571 if (!aLine.IsNull() && aLine->Lin().Direction().IsParallel(D, Precision::Angular()))
1572 return Handle(Geom_SurfaceOfLinearExtrusion)();
1573 return new Geom_SurfaceOfLinearExtrusion(C,D);
1579 //=============================================================================
1580 // Creation d' une SurfaceOfRevolution de Geom a partir d' une
1581 // SurfaceOfRevolution de Step
1582 //=============================================================================
1584 Handle(Geom_SurfaceOfRevolution) StepToGeom::MakeSurfaceOfRevolution (const Handle(StepGeom_SurfaceOfRevolution)& SS)
1586 Handle(Geom_Curve) C = MakeCurve (SS->SweptCurve());
1589 Handle(Geom_Axis1Placement) A1 = MakeAxis1Placement (SS->AxisPosition());
1592 const gp_Ax1 A( A1->Ax1() );
1593 //skl for OCC952 (one bad case revolution of circle)
1594 if ( C->IsKind(STANDARD_TYPE(Geom_Circle)) || C->IsKind(STANDARD_TYPE(Geom_Ellipse)) )
1596 const Handle(Geom_Conic) conic = Handle(Geom_Conic)::DownCast(C);
1597 const gp_Pnt pc = conic->Location();
1598 const gp_Lin rl (A);
1599 if (rl.Distance(pc) < Precision::Confusion()) { //pc lies on A2
1600 const gp_Dir dirline = A.Direction();
1601 const gp_Dir norm = conic->Axis().Direction();
1602 const gp_Dir xAxis = conic->XAxis().Direction();
1603 //checking A2 lies on plane of circle
1604 if( dirline.IsNormal(norm,Precision::Angular()) && (dirline.IsParallel(xAxis,Precision::Angular()) || C->IsKind(STANDARD_TYPE(Geom_Circle)))) {
1605 //change parametrization for trimming
1606 gp_Ax2 axnew(pc,norm,dirline.Reversed());
1607 conic->SetPosition(axnew);
1608 C = new Geom_TrimmedCurve(conic, 0., M_PI);
1612 return new Geom_SurfaceOfRevolution(C, A);
1618 //=============================================================================
1619 // Creation d' une SweptSurface de prostep a partir d' une
1620 // SweptSurface de Geom
1621 //=============================================================================
1623 Handle(Geom_SweptSurface) StepToGeom::MakeSweptSurface (const Handle(StepGeom_SweptSurface)& SS)
1625 if (SS->IsKind(STANDARD_TYPE(StepGeom_SurfaceOfLinearExtrusion))) {
1626 return MakeSurfaceOfLinearExtrusion (Handle(StepGeom_SurfaceOfLinearExtrusion)::DownCast(SS));
1628 if (SS->IsKind(STANDARD_TYPE(StepGeom_SurfaceOfRevolution))) {
1629 return MakeSurfaceOfRevolution (Handle(StepGeom_SurfaceOfRevolution)::DownCast(SS));
1631 return Handle(Geom_SweptSurface)();
1634 //=============================================================================
1635 // Creation d' une ToroidalSurface de Geom a partir d' une
1636 // ToroidalSurface de Step
1637 //=============================================================================
1639 Handle(Geom_ToroidalSurface) StepToGeom::MakeToroidalSurface (const Handle(StepGeom_ToroidalSurface)& SS)
1641 Handle(Geom_Axis2Placement) A = MakeAxis2Placement (SS->Position());
1644 const Standard_Real LF = UnitsMethods::LengthFactor();
1645 return new Geom_ToroidalSurface(A->Ax2(), Abs(SS->MajorRadius() * LF), Abs(SS->MinorRadius() * LF));
1650 //=======================================================================
1651 //function : MakeTransformation2d
1653 //=======================================================================
1654 Standard_Boolean StepToGeom::MakeTransformation2d (const Handle(StepGeom_CartesianTransformationOperator2d)& SCTO, gp_Trsf2d& CT)
1656 // NB : on ne s interesse ici qu au deplacement rigide
1657 Handle(Geom2d_CartesianPoint) CP = MakeCartesianPoint2d (SCTO->LocalOrigin());
1661 // sln 23.10.2001. CTS23496: If problems with creation of direction occur default direction is used
1662 const Handle(StepGeom_Direction) A = SCTO->Axis1();
1665 Handle(Geom2d_Direction) D = MakeDirection2d (A);
1669 const gp_Ax2d result(CP->Pnt2d(),D1);
1670 CT.SetTransformation(result);
1672 return Standard_True;
1674 return Standard_False;
1677 //=======================================================================
1678 //function : MakeTransformation3d
1680 //=======================================================================
1682 Standard_Boolean StepToGeom::MakeTransformation3d (const Handle(StepGeom_CartesianTransformationOperator3d)& SCTO, gp_Trsf& CT)
1684 Handle(Geom_CartesianPoint) CP = MakeCartesianPoint (SCTO->LocalOrigin());
1687 const gp_Pnt Pgp = CP->Pnt();
1689 // sln 23.10.2001. CTS23496: If problems with creation of direction occur default direction is used
1690 gp_Dir D1(1.,0.,0.);
1691 const Handle(StepGeom_Direction) A1 = SCTO->Axis1();
1693 Handle(Geom_Direction) D = MakeDirection (A1);
1698 gp_Dir D2(0.,1.,0.);
1699 const Handle(StepGeom_Direction) A2 = SCTO->Axis2();
1701 Handle(Geom_Direction) D = MakeDirection (A2);
1706 Standard_Boolean isDefaultDirectionUsed = Standard_True;
1708 const Handle(StepGeom_Direction) A3 = SCTO->Axis3();
1710 Handle(Geom_Direction) D = MakeDirection (A3);
1714 isDefaultDirectionUsed = Standard_False;
1717 if(isDefaultDirectionUsed)
1718 D3 = D1.Crossed(D2);
1720 const gp_Ax3 result(Pgp,D3,D1);
1721 CT.SetTransformation(result);
1722 CT = CT.Inverted(); //:n8 abv 16 Feb 99: tr8_as2_db.stp: reverse for accordance with LV tool
1723 return Standard_True;
1725 return Standard_False;
1728 // ----------------------------------------------------------------
1730 // ----------------------------------------------------------------
1731 //:o6 abv 18 Feb 99: parameter Factor added
1732 //:p3 abv 23 Feb 99: parameter Shift added
1733 static Standard_Boolean ExtractParameter
1734 (const Handle(Geom_Curve) & aGeomCurve,
1735 const Handle(StepGeom_HArray1OfTrimmingSelect) & TS,
1736 const Standard_Integer nbSel,
1737 const Standard_Integer MasterRep,
1738 const Standard_Real Factor,
1739 const Standard_Real Shift,
1740 Standard_Real & aParam)
1742 Handle(StepGeom_CartesianPoint) aPoint;
1744 //:S4136 Standard_Real precBrep = BRepAPI::Precision();
1745 for ( i = 1 ; i <= nbSel ; i++) {
1746 StepGeom_TrimmingSelect theSel = TS->Value(i);
1747 if (MasterRep == 2 && theSel.CaseMember() > 0) {
1748 aParam = Shift + Factor * theSel.ParameterValue();
1749 return Standard_True;
1751 else if (MasterRep == 1 && theSel.CaseNumber() > 0) {
1752 aPoint = theSel.CartesianPoint();
1753 Handle(Geom_CartesianPoint) theGeomPnt = StepToGeom::MakeCartesianPoint (aPoint);
1754 gp_Pnt thegpPnt = theGeomPnt->Pnt();
1756 //:S4136: use advanced algorithm
1757 ShapeAnalysis_Curve sac;
1759 sac.Project ( aGeomCurve, thegpPnt, Precision::Confusion(), p, aParam );
1761 //Trim == natural boundary ?
1762 if(aGeomCurve->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
1763 Standard_Real frstPar = aGeomCurve->FirstParameter();
1764 Standard_Real lstPar = aGeomCurve->LastParameter();
1765 gp_Pnt frstPnt = aGeomCurve->Value(frstPar);
1766 gp_Pnt lstPnt = aGeomCurve->Value(lstPar);
1767 if(frstPnt.IsEqual(thegpPnt,precBrep)) {
1769 return Standard_True;
1771 if(lstPnt.IsEqual(thegpPnt,precBrep)) {
1773 return Standard_True;
1776 // Project Point On Curve
1777 GeomAPI_ProjectPointOnCurve PPOC(thegpPnt, aGeomCurve);
1778 if (PPOC.NbPoints() == 0) {
1779 return Standard_False;
1781 aParam = PPOC.LowerDistanceParameter();
1783 return Standard_True;
1786 // if the MasterRepresentation is unspecified:
1787 // if a ParameterValue exists, it is prefered
1789 for ( i = 1 ; i <= nbSel ; i++) {
1790 StepGeom_TrimmingSelect theSel = TS->Value(i);
1791 if (theSel.CaseMember() > 0) {
1792 aParam = Shift + Factor * theSel.ParameterValue();
1794 return Standard_True;
1797 // if no ParameterValue exists, it is created from the CartesianPointValue
1799 for ( i = 1 ; i <= nbSel ; i++) {
1800 StepGeom_TrimmingSelect theSel = TS->Value(i);
1801 if (theSel.CaseNumber() > 0) {
1802 aPoint = theSel.CartesianPoint();
1803 Handle(Geom_CartesianPoint) theGeomPnt = StepToGeom::MakeCartesianPoint (aPoint);
1804 gp_Pnt thegpPnt = theGeomPnt->Pnt();
1805 // Project Point On Curve
1806 ShapeAnalysis_Curve sac;
1808 sac.Project ( aGeomCurve, thegpPnt, Precision::Confusion(), p, aParam );
1810 GeomAPI_ProjectPointOnCurve PPOC(thegpPnt, aGeomCurve);
1811 if (PPOC.NbPoints() == 0) {
1812 return Standard_False;
1814 aParam = PPOC.LowerDistanceParameter();
1816 return Standard_True;
1819 return Standard_False; // I suppose
1823 //=============================================================================
1824 // Creation d' une Trimmed Curve de Geom a partir d' une Trimmed Curve de Step
1825 //=============================================================================
1827 Handle(Geom_TrimmedCurve) StepToGeom::MakeTrimmedCurve (const Handle(StepGeom_TrimmedCurve)& SC)
1829 const Handle(StepGeom_Curve) theSTEPCurve = SC->BasisCurve();
1830 Handle(Geom_Curve) theCurve = MakeCurve (theSTEPCurve);
1831 if (theCurve.IsNull())
1832 return Handle(Geom_TrimmedCurve)();
1834 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel1 = SC->Trim1();
1835 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel2 = SC->Trim2();
1836 const Standard_Integer nbSel1 = SC->NbTrim1();
1837 const Standard_Integer nbSel2 = SC->NbTrim2();
1839 Standard_Integer MasterRep;
1840 switch (SC->MasterRepresentation())
1842 case StepGeom_tpCartesian: MasterRep = 1; break;
1843 case StepGeom_tpParameter: MasterRep = 2; break;
1844 default: MasterRep = 0;
1847 //gka 18.02.04 analysis for case when MasterRep = .Unspecified
1848 //and parameters are specified as CARTESIAN_POINT
1849 Standard_Boolean isPoint = Standard_False;
1850 if(MasterRep == 0 || (MasterRep == 2 && nbSel1 >1 && nbSel2 > 1)) {
1851 Standard_Integer ii;
1852 for(ii = 1; ii <= nbSel1; ii++)
1854 if (!(theTrimSel1->Value(ii).CartesianPoint().IsNull()))
1856 for(ii = 1; ii <= nbSel2; ii++)
1858 if (!(theTrimSel2->Value(ii).CartesianPoint().IsNull()))
1860 isPoint = Standard_True;
1869 //:o6 abv 18 Feb 99: computation of factor moved
1870 Standard_Real fact = 1., shift = 0.;
1871 if (theSTEPCurve->IsKind(STANDARD_TYPE(StepGeom_Line))) {
1872 const Handle(StepGeom_Line) theLine =
1873 Handle(StepGeom_Line)::DownCast(theSTEPCurve);
1874 fact = theLine->Dir()->Magnitude() * UnitsMethods::LengthFactor();
1876 else if (theSTEPCurve->IsKind(STANDARD_TYPE(StepGeom_Circle)) ||
1877 theSTEPCurve->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
1878 // if (trim1 > 2.1*M_PI || trim2 > 2.1*M_PI) fact = M_PI / 180.;
1879 fact = UnitsMethods::PlaneAngleFactor();
1880 //:p3 abv 23 Feb 99: shift on pi/2 on ellipse with R1 < R2
1881 const Handle(StepGeom_Ellipse) ellipse = Handle(StepGeom_Ellipse)::DownCast(theSTEPCurve);
1882 if ( !ellipse.IsNull() && ellipse->SemiAxis1() - ellipse->SemiAxis2() < 0. )
1885 // skl 04.02.2002 for OCC133: we can not make TrimmedCurve if
1886 // there is no X-direction in StepGeom_Axis2Placement3d
1887 const Handle(StepGeom_Conic) conic = Handle(StepGeom_Conic)::DownCast(theSTEPCurve);
1888 // CKY 6-FEB-2004 for Airbus-MedialAxis :
1889 // this restriction does not apply for trimming by POINTS
1890 if(!conic.IsNull() && MasterRep != 1) {
1891 const StepGeom_Axis2Placement a2p = conic->Position();
1892 if(a2p.CaseNum(a2p.Value())==2) {
1893 if( !a2p.Axis2Placement3d()->HasRefDirection() ) {
1894 ////gka 18.02.04 analysis for case when MasterRep = .Unspecified
1895 //and parameters are specified as CARTESIAN_POINT
1896 if(isPoint /*&& !MasterRep*/)
1899 if ( SC->SenseAgreement() )
1900 return new Geom_TrimmedCurve(theCurve, 0., 2.*M_PI, Standard_True);
1902 return new Geom_TrimmedCurve(theCurve, 2.*M_PI, 0., Standard_False);
1909 Standard_Real trim1 = 0.;
1910 Standard_Real trim2 = 0.;
1911 Handle(StepGeom_CartesianPoint) TrimCP1, TrimCP2;
1912 const Standard_Boolean FoundParam1 = ExtractParameter(theCurve, theTrimSel1, nbSel1, MasterRep, fact, shift, trim1);
1913 const Standard_Boolean FoundParam2 = ExtractParameter(theCurve, theTrimSel2, nbSel2, MasterRep, fact, shift, trim2);
1915 if (FoundParam1 && FoundParam2) {
1916 const Standard_Real cf = theCurve->FirstParameter();
1917 const Standard_Real cl = theCurve->LastParameter();
1918 //: abv 09.04.99: S4136: bm2_ug_t4-B.stp #70610: protect against OutOfRange
1919 if ( !theCurve->IsPeriodic() ) {
1920 if ( trim1 < cf ) trim1 = cf;
1921 else if ( trim1 > cl ) trim1 = cl;
1922 if ( trim2 < cf ) trim2 = cf;
1923 else if ( trim2 > cl ) trim2 = cl;
1925 if (Abs(trim1 - trim2) < Precision::PConfusion()) {
1926 if (theCurve->IsPeriodic()) {
1927 ElCLib::AdjustPeriodic(cf,cl,Precision::PConfusion(),trim1,trim2);
1929 else if (theCurve->IsClosed()) {
1930 if (Abs(trim1 - cf) < Precision::PConfusion()) {
1941 // CKY 16-DEC-1997 : USA60035 le texte de Part42 parle de degres
1942 // mais des systemes ecrivent en radians. Exploiter UnitsMethods
1943 //:o6 trim1 = trim1 * fact;
1944 //:o6 trim2 = trim2 * fact;
1945 if ( SC->SenseAgreement() )
1946 return new Geom_TrimmedCurve(theCurve, trim1, trim2, Standard_True);
1947 else //:abv 29.09.00 PRO20362: reverse parameters in case of reversed curve
1948 return new Geom_TrimmedCurve(theCurve, trim2, trim1, Standard_False);
1953 //=============================================================================
1954 // Creation d'une Trimmed Curve de Geom2d a partir d' une Trimmed Curve de Step
1955 //=============================================================================
1956 // Shall be completed to treat trimming with points
1958 Handle(Geom2d_BSplineCurve) StepToGeom::MakeTrimmedCurve2d (const Handle(StepGeom_TrimmedCurve)& SC)
1960 const Handle(StepGeom_Curve) BasisCurve = SC->BasisCurve();
1961 Handle(Geom2d_Curve) theGeomBasis = MakeCurve2d (BasisCurve);
1962 if (theGeomBasis.IsNull())
1963 return Handle(Geom2d_BSplineCurve)();
1965 if (theGeomBasis->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
1966 return Handle(Geom2d_BSplineCurve)::DownCast(theGeomBasis);
1969 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel1 = SC->Trim1();
1970 const Handle(StepGeom_HArray1OfTrimmingSelect)& theTrimSel2 = SC->Trim2();
1971 const Standard_Integer nbSel1 = SC->NbTrim1();
1972 const Standard_Integer nbSel2 = SC->NbTrim2();
1973 if ((nbSel1 == 1) && (nbSel2 == 1) &&
1974 (theTrimSel1->Value(1).CaseMember() > 0) &&
1975 (theTrimSel2->Value(1).CaseMember() > 0))
1977 const Standard_Real u1 = theTrimSel1->Value(1).ParameterValue();
1978 const Standard_Real u2 = theTrimSel2->Value(1).ParameterValue();
1979 Standard_Real fact = 1., shift = 0.;
1981 if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Line))) {
1982 const Handle(StepGeom_Line) theLine = Handle(StepGeom_Line)::DownCast(BasisCurve);
1983 fact = theLine->Dir()->Magnitude();
1985 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Circle)) ||
1986 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Ellipse))) {
1987 // if (u1 > 2.1*M_PI || u2 > 2.1*M_PI) fact = M_PI / 180.;
1988 fact = UnitsMethods::PlaneAngleFactor();
1989 //:p3 abv 23 Feb 99: shift on pi/2 on ellipse with R1 < R2
1990 const Handle(StepGeom_Ellipse) ellipse = Handle(StepGeom_Ellipse)::DownCast(BasisCurve);
1991 if ( !ellipse.IsNull() && ellipse->SemiAxis1() - ellipse->SemiAxis2() < 0. )
1994 else if (BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Parabola)) ||
1995 BasisCurve->IsKind(STANDARD_TYPE(StepGeom_Hyperbola))) {
1998 // CKY 16-DEC-1997 : USA60035 le texte de Part42 parle de degres
1999 // mais des systemes ecrivent en radians. Exploiter UnitsMethods
2001 const Standard_Real newU1 = shift + u1 * fact;
2002 const Standard_Real newU2 = shift + u2 * fact;
2004 const Handle(Geom2d_TrimmedCurve) theTrimmed =
2005 new Geom2d_TrimmedCurve(theGeomBasis, newU1, newU2, SC->SenseAgreement());
2006 return Geom2dConvert::CurveToBSplineCurve(theTrimmed);
2011 //=============================================================================
2012 // Creation d' un VectorWithMagnitude de Geom a partir d' un Vector de Step
2013 //=============================================================================
2015 Handle(Geom_VectorWithMagnitude) StepToGeom::MakeVectorWithMagnitude (const Handle(StepGeom_Vector)& SV)
2017 // sln 22.10.2001. CTS23496: Vector is not created if direction have not been succesfully created
2018 Handle(Geom_Direction) D = MakeDirection (SV->Orientation());
2021 const gp_Vec V(D->Dir().XYZ() * SV->Magnitude() * UnitsMethods::LengthFactor());
2022 return new Geom_VectorWithMagnitude(V);
2027 //=============================================================================
2028 // Creation d' un VectorWithMagnitude de Geom2d a partir d' un Vector de Step
2029 //=============================================================================
2031 Handle(Geom2d_VectorWithMagnitude) StepToGeom::MakeVectorWithMagnitude2d (const Handle(StepGeom_Vector)& SV)
2033 // sln 23.10.2001. CTS23496: Vector is not created if direction have not been succesfully created (MakeVectorWithMagnitude2d(...) function)
2034 Handle(Geom2d_Direction) D = MakeDirection2d (SV->Orientation());
2037 const gp_Vec2d V(D->Dir2d().XY() * SV->Magnitude());
2038 return new Geom2d_VectorWithMagnitude(V);