1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //=======================================================================
16 // Integration to ensure SCCS base integrity
17 // 21.12.98 rln, gka S4054
18 // 28.12.98 dce S3767 New messaging system
19 //#55,#56 rln 25.12.98 UKI60878
20 //:l1 abv 10.01.99: USA60022 7289: fix missing seam
21 //#63 rln 19.01.99 UKI60878 no offset if C0 surface is converted into the grid of C1 surfaces
22 //%13 pdn 15.02.99 USA60293 entities 792, 8604 .. handling of C0 ruled surfaces, tabulated cylindres,
23 // and surfaces of revolution.
24 //:p4 abv, pdn 23.02.99: PRO9234 #15720: call BRepTools::Update() for faces
25 //%14 pdn 24.02.99 implementing of ShapeFix_Face on IGES
26 // pdn 17.04.99 S4181: Implementing of reading IGES elementary surfaces.
27 // pdn 10.05.99 S4137: Using modified ShapeDivide tools
28 //#11 smh 22.12.99 BUC60625 Transform axis.
29 //#12 smh 12.12.99 FRA62468 - Using conversion to B-Spline for Offset surface
30 //=======================================================================
32 #include <BRep_Builder.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <BRepBuilderAPI_GTransform.hxx>
36 #include <BRepBuilderAPI_MakeFace.hxx>
37 #include <BRepFill.hxx>
38 #include <BRepGProp.hxx>
39 #include <BRepLib_MakeFace.hxx>
40 #include <BRepPrimAPI_MakePrism.hxx>
41 #include <BRepPrimAPI_MakeRevol.hxx>
42 #include <BRepTools.hxx>
43 #include <BSplCLib.hxx>
46 #include <Geom2d_Curve.hxx>
47 #include <Geom2d_Line.hxx>
48 #include <Geom_BezierCurve.hxx>
49 #include <Geom_BSplineCurve.hxx>
50 #include <Geom_BSplineSurface.hxx>
51 #include <Geom_ConicalSurface.hxx>
52 #include <Geom_Curve.hxx>
53 #include <Geom_CylindricalSurface.hxx>
54 #include <Geom_Line.hxx>
55 #include <Geom_OffsetSurface.hxx>
56 #include <Geom_Plane.hxx>
57 #include <Geom_RectangularTrimmedSurface.hxx>
58 #include <Geom_SphericalSurface.hxx>
59 #include <Geom_Surface.hxx>
60 #include <Geom_SurfaceOfLinearExtrusion.hxx>
61 #include <Geom_SurfaceOfRevolution.hxx>
62 #include <Geom_ToroidalSurface.hxx>
63 #include <Geom_TrimmedCurve.hxx>
64 #include <GeomAbs_Shape.hxx>
65 #include <GeomConvert.hxx>
66 #include <GeomLib.hxx>
69 #include <gp_Cone.hxx>
70 #include <gp_Cylinder.hxx>
72 #include <gp_Dir2d.hxx>
73 #include <gp_GTrsf.hxx>
76 #include <gp_Sphere.hxx>
77 #include <gp_Torus.hxx>
78 #include <gp_Trsf.hxx>
79 #include <gp_Trsf2d.hxx>
82 #include <GProp_GProps.hxx>
83 #include <IGESBasic_SingleParent.hxx>
84 #include <IGESData_IGESEntity.hxx>
85 #include <IGESData_IGESModel.hxx>
86 #include <IGESData_ToolLocation.hxx>
87 #include <IGESData_TransfEntity.hxx>
88 #include <IGESGeom_BoundedSurface.hxx>
89 #include <IGESGeom_BSplineSurface.hxx>
90 #include <IGESGeom_CircularArc.hxx>
91 #include <IGESGeom_CurveOnSurface.hxx>
92 #include <IGESGeom_Direction.hxx>
93 #include <IGESGeom_Line.hxx>
94 #include <IGESGeom_OffsetSurface.hxx>
95 #include <IGESGeom_Plane.hxx>
96 #include <IGESGeom_Point.hxx>
97 #include <IGESGeom_RuledSurface.hxx>
98 #include <IGESGeom_SurfaceOfRevolution.hxx>
99 #include <IGESGeom_TabulatedCylinder.hxx>
100 #include <IGESGeom_TrimmedSurface.hxx>
101 #include <IGESSolid_ConicalSurface.hxx>
102 #include <IGESSolid_CylindricalSurface.hxx>
103 #include <IGESSolid_PlaneSurface.hxx>
104 #include <IGESSolid_SphericalSurface.hxx>
105 #include <IGESSolid_ToroidalSurface.hxx>
106 #include <IGESToBRep.hxx>
107 #include <IGESToBRep_BasicCurve.hxx>
108 #include <IGESToBRep_BasicSurface.hxx>
109 #include <IGESToBRep_CurveAndSurface.hxx>
110 #include <IGESToBRep_TopoCurve.hxx>
111 #include <IGESToBRep_TopoSurface.hxx>
112 #include <Interface_Macros.hxx>
113 #include <Message_Msg.hxx>
114 #include <Precision.hxx>
115 #include <ShapeAlgo.hxx>
116 #include <ShapeAlgo_AlgoContainer.hxx>
117 #include <ShapeAnalysis.hxx>
118 #include <ShapeExtend_WireData.hxx>
119 #include <ShapeFix_Wire.hxx>
120 #include <Standard_ErrorHandler.hxx>
121 #include <TColgp_Array1OfPnt.hxx>
122 #include <TColStd_Array1OfInteger.hxx>
123 #include <TColStd_Array1OfReal.hxx>
124 #include <TopAbs.hxx>
125 #include <TopExp.hxx>
126 #include <TopExp_Explorer.hxx>
127 #include <TopLoc_Location.hxx>
128 #include <TopoDS.hxx>
129 #include <TopoDS_Edge.hxx>
130 #include <TopoDS_Face.hxx>
131 #include <TopoDS_Iterator.hxx>
132 #include <TopoDS_Shape.hxx>
133 #include <TopoDS_Shell.hxx>
134 #include <TopoDS_Vertex.hxx>
135 #include <TopoDS_Wire.hxx>
138 //S4054: ShapeTool_MakeWire -> ShapeExtend_WireData //:g8: BRepLib_MakeWire -> ShapeTool_MakeWire
143 //=======================================================================
144 //function : IGESToBRep_TopoSurface
146 //=======================================================================
147 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface()
148 :IGESToBRep_CurveAndSurface()
153 //=======================================================================
154 //function : IGESToBRep_TopoSurface
156 //=======================================================================
158 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
159 (const IGESToBRep_CurveAndSurface& CS)
160 :IGESToBRep_CurveAndSurface(CS)
165 //=======================================================================
166 //function : IGESToBRep_TopoSurface
168 //=======================================================================
170 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
171 (const Standard_Real eps,
172 const Standard_Real epsCoeff,
173 const Standard_Real epsGeom,
174 const Standard_Boolean mode,
175 const Standard_Boolean modeapprox,
176 const Standard_Boolean optimized)
177 :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode,
178 modeapprox, optimized)
182 static Standard_Boolean extractCurve3d (const TopoDS_Shape& theEdges,
183 Handle(Geom_Curve)& theCurve)
185 TopExp_Explorer anExp(theEdges, TopAbs_EDGE);
186 Standard_Integer howMuch = 0;
187 Standard_Real f = 0., l = 0.;
188 for (; anExp.More(); anExp.Next()) {
189 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
193 theCurve = BRep_Tool::Curve(anEdge, f, l);
195 if ( howMuch != 1 || theCurve.IsNull() )
196 return Standard_False;
198 if ( f != theCurve->FirstParameter() || l != theCurve->LastParameter() )
199 theCurve = new Geom_TrimmedCurve ( theCurve, f, l );
200 return Standard_True;
204 //=======================================================================
205 //function : TransferTopoSurface
207 //=======================================================================
209 TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoSurface
210 (const Handle(IGESData_IGESEntity)& st)
211 { // Declaration of messages//
213 //Message_Msg msg1005("IGES_1005");
214 ////////////////////////////
220 Message_Msg msg1005("IGES_1005");
221 SendFail(st, msg1005);
223 ////modified by jgv, 20.11.2009 for OCC21487///
224 else if (HasShapeResult(st))
226 res = GetShapeResult(st);
229 ///////////////////////////////////////////////
230 else if (IGESToBRep::IsBasicSurface(st)) {
231 res = TransferTopoBasicSurface(st);
233 else if (st->IsKind(STANDARD_TYPE(IGESGeom_TrimmedSurface))) {
234 DeclareAndCast(IGESGeom_TrimmedSurface, st144, st);
235 res = TransferTrimmedSurface(st144);
237 else if (st->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
238 DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, st);
239 res = TransferSurfaceOfRevolution(st120);
241 else if (st->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
242 DeclareAndCast(IGESGeom_TabulatedCylinder, st122, st);
243 res = TransferTabulatedCylinder(st122);
245 else if (st->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
246 DeclareAndCast(IGESGeom_RuledSurface, st118, st);
247 res = TransferRuledSurface(st118);
249 else if (st->IsKind(STANDARD_TYPE(IGESGeom_Plane))) {
250 DeclareAndCast(IGESGeom_Plane, st108, st);
251 res = TransferPlane(st108);
253 else if (st->IsKind(STANDARD_TYPE(IGESGeom_BoundedSurface))) {
254 DeclareAndCast(IGESGeom_BoundedSurface, st143, st);
255 res = TransferBoundedSurface(st143);
257 else if (st->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))) {
258 DeclareAndCast(IGESGeom_OffsetSurface, st140, st);
259 res = TransferOffsetSurface(st140);
261 //S4181 pdn IGESSolid_PlaneSurface recognized as basic surface
262 else if (st->IsKind(STANDARD_TYPE(IGESBasic_SingleParent))) {
263 DeclareAndCast(IGESBasic_SingleParent,st402_9,st);
264 res = TransferPerforate(st402_9); // limite : Planes seulement
267 // AddFail(st, "The IGESEntity is not a Topologic Surface.");
269 SetShapeResult (st, res);
273 //=======================================================================
274 //function : TransferTopoBasicSurface
276 //=======================================================================
278 TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoBasicSurface
279 (const Handle(IGESData_IGESEntity)& st)
280 { // Declaration of messages//
282 //Message_Msg msg1005("IGES_1005");
283 ////////////////////////////
288 Message_Msg msg1005("IGES_1005");
289 SendFail(st, msg1005);
292 if (!IGESToBRep::IsBasicSurface(st)) {
293 // AddFail(st, "BasicSurface Transfer Error : Not Allowed IGESEntity"); This message can not occur.
297 IGESToBRep_BasicSurface BS(*this);
299 Handle(Geom_Surface) surf = BS.TransferBasicSurface(st);
301 // AddFail(st, "Surface Conversion Error"); Messages have ever been Added in the called function.
305 //#9 rln 26/02/98 UKI60106
306 if (surf->Continuity() < GeomAbs_C1) {
307 Message_Msg msg1250("IGES_1250");
308 SendWarning(st, msg1250);
310 if(surf->IsKind(STANDARD_TYPE(Geom_Plane))){
314 B.UpdateFace(plane, surf, TopLoc_Location(), Precision::Confusion());
318 BRepLib_MakeFace makeFace(surf, Precision::Confusion());
319 res = makeFace.Face();
322 if (st->HasTransf()) {
325 if (IGESData_ToolLocation::ConvertLocation
326 (GetEpsilon(),st->CompoundLocation(),trsf,GetUnitFactor())) {
327 TopLoc_Location locFace(trsf);
331 Message_Msg msg1035("IGES_1035");
332 SendWarning(st, msg1035);
339 //=======================================================================
340 //function : TransferRuledSurface
342 //=======================================================================
343 static void reparamBSpline(Handle(Geom_Curve)& curve,
344 const Standard_Real First,
345 const Standard_Real Last)
347 Handle (Geom_BSplineCurve) bscurve;
348 if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
349 if (curve->FirstParameter() < First || curve->LastParameter() > Last)
350 curve = new Geom_TrimmedCurve (curve, First, Last);
351 bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
354 bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
355 bscurve->Segment (First, Last);
358 if (bscurve.IsNull())
361 TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
362 bscurve->Knots(Knots);
363 BSplCLib::Reparametrize (0., 1., Knots);
364 bscurve->SetKnots(Knots);
368 static void ReparamCurve(TopoDS_Edge& edge)
371 Standard_Real First, Last;
373 Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
374 //if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) return;
375 if(!curve->IsKind(STANDARD_TYPE(Geom_Line))) return;
377 reparamBSpline( curve, First, Last );
380 B.UpdateEdge ( edge, curve, L, Precision::Confusion() );
381 B.Range ( edge, 0., 1 );
385 //=======================================================================
386 //function : TransferRuledSurface
388 //=======================================================================
390 TopoDS_Shape IGESToBRep_TopoSurface::TransferRuledSurface
391 (const Handle(IGESGeom_RuledSurface)& st)
392 { // Declaration of messages//
394 //Message_Msg msg1005("IGES_1005");
395 ////////////////////////////////
399 Message_Msg msg1005("IGES_1005");
400 SendFail(st, msg1005);
404 IGESToBRep_TopoCurve TC(*this);
406 TC.SetContinuity (0);
407 Handle(IGESData_IGESEntity) igesCurve1 = st->FirstCurve();
408 Handle(IGESData_IGESEntity) igesCurve2 = st->SecondCurve();
410 if (igesCurve1.IsNull()) {
411 Message_Msg msg148("XSTEP_148");
412 SendFail(st, msg148); // Curve Reading Error : Null IGESEntity
415 if (igesCurve2.IsNull()) {
416 Message_Msg msg149("XSTEP_149");
417 SendFail(st, msg149); // Curve Reading Error : Null IGESEntity
421 Standard_Integer nbEdges1, nbEdges2;
422 TopoDS_Shape shape1, shape2;
423 TopoDS_Wire wire1, wire2;
424 TopoDS_Wire newWire1, newWire2;
425 //TopoDS_Edge edge1, edge2; // skl
427 if (IGESToBRep::IsTopoCurve(igesCurve1)) {
428 shape1 = TC.TransferTopoCurve(igesCurve1);
429 if (shape1.IsNull()) {
430 Message_Msg msg1156("IGES_1156");
431 const Standard_CString typeName(igesCurve1->DynamicType()->Name());
432 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
433 msg1156.Arg(typeName);
435 SendFail(st, msg1156);
440 //added by rln on 03/12/97
441 //if shape1 is a wire it means that the curve1 in file was of continuity C0
442 //in order to get a face instead of shell when to BRepFill shape1
443 //should be retransfered with contionuity C0 (to get an edge). Once shape1
444 //has been built with C0, it is useless to require C1 from shape2 because
445 //anyway resulting surface was of continuity C0. Thus shape2 is built with C0
446 // if (shape1.ShapeType() != TopAbs_EDGE) {
447 // TC.SetContinuity (0);
448 // shape1 = TC.TransferTopoCurve(igesCurve1);
449 // if (shape1.IsNull()) {
450 // Message_Msg msg1156("IGES_1156");
451 // const Standard_CString typeName(igesCurve1->DynamicType()->Name());
452 // Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
453 // msg1156.Arg(typeName);
454 // msg1156.Arg(label);
455 // SendFail(st, msg1156);
459 // Message_Msg msg1250("IGES_1250");
460 // SendWarning (st, msg1250); // RuledSurface was built with continuity C0
464 TopAbs_ShapeEnum shapeEnum1 = shape1.ShapeType();
465 switch (shapeEnum1) {
468 TopoDS_Edge edge1 = TopoDS::Edge(shape1);
475 wire1 = TopoDS::Wire(shape1);
477 for (TopoDS_Iterator hulot(wire1); hulot.More(); hulot.Next()) {
478 TopoDS_Edge edge1 = TopoDS::Edge(hulot.Value());
486 // AddFail(st, "Curve Conversion Error."); This message can not occur.
489 //break; //szv#4:S4163:12Mar99 unreachable
493 Message_Msg msg148("XSTEP_148");
494 SendFail(st, msg148);
495 // Curve Type not Allowed.
499 if (IGESToBRep::IsTopoCurve(igesCurve2)) {
500 shape2 = TC.TransferTopoCurve(igesCurve2);
501 // dirflg = 0 join first to first, last to last
502 // dirflg = 1 join first to last, last to first
504 if (shape2.IsNull()) {
505 Message_Msg msg1156("IGES_1156");
506 const Standard_CString typeName(igesCurve2->DynamicType()->Name());
507 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve2);
508 msg1156.Arg(typeName);
510 SendFail(st, msg1156);
511 // Curve Conversion Error.
514 Standard_Integer dirflag = st->DirectionFlag ();
515 // if (dirflag == 1){ // gka BUC60685
520 TopAbs_ShapeEnum shapeEnum2 = shape2.ShapeType();
521 switch (shapeEnum2) {
524 TopoDS_Edge edge2 = TopoDS::Edge(shape2);
533 wire2 = TopoDS::Wire(shape2);
535 for (TopoDS_Iterator cousto(wire2); cousto.More(); cousto.Next()) {
536 TopoDS_Edge edge2 = TopoDS::Edge(cousto.Value());
540 if (dirflag == 1) { //gka BUC60685
541 Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
544 wire2 = sewd2->Wire();
550 // AddFail(st, "Curve Conversion Error.");
553 //break; //szv#4:S4163:12Mar99 unreachable
557 Message_Msg msg149("XSTEP_149");
558 SendFail(st, msg149);
559 // Curve Type not Allowed
564 if (nbEdges1 != nbEdges2) {
566 Handle(ShapeExtend_WireData) sewd1 = new ShapeExtend_WireData;
568 wire1 = sewd1->Wire();
570 else if (nbEdges2 == 1) {
571 Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
573 wire2 = sewd2->Wire();
576 if (!st->IsRuledByParameter()) {
577 // AddWarning (st,"Compute by parametric constant ratio");
579 if (!ShapeAlgo::AlgoContainer()->HomoWires
580 (wire1, wire2, newWire1, newWire2, st->IsRuledByParameter())) {
581 Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
582 SendFail(st, msg1255);
585 nbEdges1 = 2; // a number > 1
588 else if (nbEdges1 != 1) {
596 //:e3 abv 31 Mar 98: UK4.igs 3170: ruled surface with directixes - line
597 // In IGES, line is parametrised [0;1] - this should have been kept !
598 // Let us detect the case and remake curve as bspline [0;1]
599 for ( Standard_Integer i=1; i <=2; i++ ) {
600 //#43 rln 20.11.98 S4054 BUC50047 entity D463 (circles as generatrices [0, 2*PI])
601 //reparameterisation should be for all curves not with range [0, 1] (see IGES)
602 TopoDS_Edge edge = TopoDS::Edge ( i==1 ? shape1 : shape2 );
603 //ReparamCurve(edge);
605 Standard_Real First, Last;
606 Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
607 if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) continue;
609 Handle (Geom_BSplineCurve) bscurve;
610 if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
611 if (curve->FirstParameter() < First || curve->LastParameter() > Last)
612 curve = new Geom_TrimmedCurve (curve, First, Last);
613 bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
616 bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
617 bscurve->Segment (First, Last);
619 TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
620 bscurve->Knots(Knots);
621 BSplCLib::Reparametrize (0., 1., Knots);
622 bscurve->SetKnots(Knots);
625 B.UpdateEdge ( edge, bscurve, L, Precision::Confusion() );
626 B.Range ( edge, 0., 1 );
627 if ( i ==1 ) shape1 = edge;
631 res = BRepFill::Face(TopoDS::Edge(shape1), TopoDS::Edge(shape2));
632 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
633 if(surf->Continuity()==GeomAbs_C0) {
634 Message_Msg msg1250("IGES_1250");
635 SendWarning (st, msg1250);
639 res = BRepFill::Shell(newWire1, newWire2);
642 Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
643 SendFail(st, msg1255);
648 if (st->HasTransf()) {
651 if (IGESData_ToolLocation::ConvertLocation
652 (GetEpsilon(),st->CompoundLocation(), trsf,GetUnitFactor())) {
653 TopLoc_Location shapeLoc(trsf);
657 Message_Msg msg1035("IGES_1035");
658 SendWarning(st,msg1035); // Transformation : not a similarity
665 //=======================================================================
666 //function : TransferSurfaceOfRevolution
668 //=======================================================================
670 TopoDS_Shape IGESToBRep_TopoSurface::TransferSurfaceOfRevolution
671 (const Handle(IGESGeom_SurfaceOfRevolution)& st)
672 { // Declaration of messages//
674 //Message_Msg msg1005("IGES_1005");
675 ////////////////////////////////
678 Message_Msg msg1005("IGES_1005");
679 SendFail(st, msg1005);
683 IGESToBRep_TopoCurve TC(*this);
684 IGESToBRep_BasicCurve BC(*this);
685 Handle(IGESData_IGESEntity) igesGeneratrix = st->Generatrix();
686 Handle(IGESGeom_Line) igesAxis = st->AxisOfRevolution();
688 if (igesGeneratrix.IsNull() || !IGESToBRep::IsTopoCurve(igesGeneratrix) ) {
689 Message_Msg msg153("XSTEP_153");
690 SendFail(st, msg153);
691 // Generatrix Reading Error : Null IGESEntity
692 // Generatrix : Not Allowed IGESEntity.
696 DeclareAndCast(IGESGeom_Line,srgen,st->Generatrix());
697 if (!srgen.IsNull()) {
698 gp_Pnt gen1 = srgen->StartPoint();
699 gp_Pnt gen2 = srgen->EndPoint();
700 TheULength = gen1.Distance(gen2)*GetUnitFactor();
703 if (igesAxis.IsNull()) {
704 Message_Msg msg152("XSTEP_152");
705 SendFail(st, msg152);
711 TopoDS_Shape generatrix = TC.TransferTopoCurve(igesGeneratrix);
712 if (generatrix.IsNull()) {
713 Message_Msg msg1156("IGES_1156");
714 const Standard_CString typeName("generatrix");
715 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesGeneratrix);
716 msg1156.Arg(typeName);
718 SendFail(st, msg1156);
719 // Generatrix Conversion Error.
724 gp_Pnt pt1 = igesAxis->TransformedStartPoint(); //smh#11
725 gp_Pnt pt2 = igesAxis->TransformedEndPoint(); //smh#11
726 pt1.Scale(gp_Pnt(0,0,0),GetUnitFactor());
727 pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());
728 //#30 rln 19.10.98 To keep IGES surface normal CAS.CADE axis = reversed IGES axis
729 //CAS.CADE SA = 2*PI - IGES TA
730 //CAS.CADE TA = 2*PI - IGES SA
731 //gp_Ax1 revolAxis(pt1, gp_Dir(gp_Vec(pt1, pt2)));
732 //Standard_Real startAngle = st->StartAngle();
733 //Standard_Real endAngle = st->EndAngle();
734 gp_Ax1 revolAxis(pt1, gp_Dir( gp_Vec (pt2, pt1)));
735 Standard_Real startAngle = 2 * M_PI - st->EndAngle();
736 Standard_Real endAngle = 2 * M_PI - st->StartAngle();
737 Standard_Real deltaAngle = endAngle - startAngle;
738 Standard_Boolean IsFullAngle = ( deltaAngle > 2.*M_PI-Precision::PConfusion() );
739 if (IsFullAngle) deltaAngle = 2.*M_PI; // ** CKY 18-SEP-1996
740 // il faudra translater les courbes 2d de startAngle pour
741 // etre en phase IGES et BRep
742 startLoc.SetRotation(revolAxis, startAngle);
743 generatrix.Move(startLoc);
745 // PTV file D44-11325-6.igs OCC660 depends on OCC450
746 // PTV 29.05.2002 OCC450 create Surface of Revolution by native API
747 // file NIC_file5.igs
748 // (BRepPrimAPI_MakeRevol replace surface of revolution by plane then 3D and 2D curves are inconsistent;
749 // and 3D is ignored. As result shape is rectangle instead circle shape.
750 Handle(Geom_Curve) aBasisCurve;
756 if (extractCurve3d(generatrix, aBasisCurve))
758 BRepBuilderAPI_MakeFace aMakeF;
759 Handle(Geom_Surface) aResultSurf =
760 new Geom_SurfaceOfRevolution(aBasisCurve, revolAxis);
762 if ( !aResultSurf.IsNull())
766 const Standard_Real VF = aBasisCurve->FirstParameter();
767 const Standard_Real VL = aBasisCurve->LastParameter();
769 // PTV 29.08.2002 begin of OCC663 Trim surface by correct parameters
770 const Standard_Real UF = 0;
771 const Standard_Real UL = endAngle - startAngle;
772 // PTV 29.08.2002 end of OCC663
774 aMakeF.Init(aResultSurf, UF, UL, VF, VL, Precision::Confusion());
778 aMakeF.Init(aResultSurf, Standard_True, Precision::Confusion());
783 }//if ( !aResultSurf.IsNull())
784 }//if (extractCurve3d(generatrix, aBasisCurve))
786 catch (Standard_Failure const& anException) {
788 std::cout << "Warning: IgesToBRep_TopoSurface::"
789 "TransferSurfaceOfRevolution(): exception by Geom: ";
790 anException.Print ( std::cout ); std::cout << std::endl;
793 }//catch (Standard_Failure)
796 if ( res.IsNull() ) {
799 BRepPrimAPI_MakeRevol revol(generatrix, revolAxis, deltaAngle);
800 //mjm: si debug IsDone()est fait :
801 // if (!revol.IsDone()) {
802 // AddFail(st, "Revol Construction Error.");
808 if (res.ShapeType() == TopAbs_FACE) {
809 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
810 if(surf->Continuity()==GeomAbs_C0) {
811 Message_Msg msg1250("IGES_1250");
812 SendWarning (st, msg1250);
816 if (st->HasTransf()) {
819 if (IGESData_ToolLocation::ConvertLocation
820 (GetEpsilon(), st->CompoundLocation(), trsf, GetUnitFactor())) {
821 TopLoc_Location shapeLoc(trsf);
825 Message_Msg msg1035("IGES_1035");
826 SendWarning(st,msg1035); // Transformation : not a similarity
834 //=======================================================================
835 //function : TransferTabulatedCylinder
837 //=======================================================================
839 TopoDS_Shape IGESToBRep_TopoSurface::TransferTabulatedCylinder
840 (const Handle(IGESGeom_TabulatedCylinder)& st)
841 { // Declaration of messages//
843 //Message_Msg msg1005("IGES_1005");
844 ////////////////////////////////
847 Message_Msg msg1005("IGES_1005");
848 SendFail(st, msg1005);
852 IGESToBRep_TopoCurve TC(*this);
853 // TopoDS_Edge firstEdge;//commented by rln on 02/12/97
855 Handle(IGESData_IGESEntity) igesDirectrix = st->Directrix();
856 if (igesDirectrix.IsNull() || !IGESToBRep::IsTopoCurve(igesDirectrix) ) {
857 Message_Msg msg153("XSTEP_153");
858 SendFail(st, msg153);
859 // Directrix Reading Error : Null IGESEntity
860 //Directrix, not allowed IGESEntity
866 TopoDS_Shape directrix = TC.TransferTopoCurve(igesDirectrix);
867 if (directrix.IsNull()) {
868 Message_Msg msg1156("IGES_1156");
869 const Standard_CString typeName("directrix");
870 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesDirectrix);
871 msg1156.Arg(typeName);
873 SendFail(st, msg1156);
874 // Directrix Conversion Error.
878 //modified by rln on 03/12/97
879 //TopoDS_Vertex firstVertex = TopExp::FirstVertex(firstEdge);
880 TopoDS_Vertex firstVertex, lastVertex;
881 ShapeAnalysis::FindBounds (directrix, firstVertex, lastVertex);
882 gp_Pnt pt1 = BRep_Tool::Pnt(firstVertex);
883 gp_Pnt pt2 = st->EndPoint();
884 pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());
886 TheULength = pt1.Distance(pt2);
887 if(TheULength < Precision::Confusion()) {
888 Message_Msg msg("Tabulated cylinder with zero length");
889 SendFail (st, msg); // TabulatedCylinder was built with continuity C0
893 // PTV file D44-11325-6.igs OCC660 depends on OCC450
894 // PTV 29.05.2002 OCC450 create Surface of LinearExtrusion by native API
895 // see description about problem in Surface of Revolution
896 Handle(Geom_Curve) aBasisCurve;
900 if (extractCurve3d(directrix, aBasisCurve)) {
901 gp_Vec dir (pt1, pt2);
902 Handle(Geom_Surface) aResultSurf =
903 new Geom_SurfaceOfLinearExtrusion(aBasisCurve, dir);
904 if (!aResultSurf.IsNull()) {
906 // new Geom_RectangularTrimmedSurface(aResultSurf,
907 // aBasisCurve->FirstParameter(),
908 // aBasisCurve->LastParameter(),
909 // 0., dir.Magnitude() );
910 BRepBuilderAPI_MakeFace aMakeF(aResultSurf, aBasisCurve->FirstParameter(),
911 aBasisCurve->LastParameter(),
913 Precision::Confusion());
919 catch (Standard_Failure const& anException) {
921 std::cout << "Warning: IgesToBRep_TopoSurface::TransferTabulatedCylinder(): exception by Geom: ";
922 anException.Print ( std::cout ); std::cout << std::endl;
928 if ( res.IsNull() ) {
930 BRepPrimAPI_MakePrism prism(directrix, gp_Vec(pt1, pt2));
931 //mjm: si debug IsDone() est fait
932 // if (!prism.IsDone()) {
933 // AddFail(st, "Prism Construction Error.");
938 //#16 rln 08/04/98 coq-inf-support.igs entity 2105
939 //CAS.CADE can parametrize SurfaceOfLinearExtrusion with generatrix opposite to Vec(pt1, pt2)
940 //and with parametrization V > 0, while in IGES TabulatedCylinder is parametrized with positive V
941 //direction exactly in the direction Vec(pt1, pt2)
942 if (res.ShapeType() == TopAbs_FACE) {
943 Standard_Real UMin, UMax, VMin, VMax;
944 BRepTools::UVBounds (TopoDS::Face (res), UMin, UMax, VMin, VMax);
945 if (VMax <= Precision::PConfusion() && VMin < -Precision::PConfusion()) {
949 Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
950 if(surf->Continuity()==GeomAbs_C0) {
951 Message_Msg msg1250("IGES_1250");
952 SendWarning (st, msg1250);
956 if (st->HasTransf()) {
959 if (IGESData_ToolLocation::ConvertLocation
960 (GetEpsilon(),st->CompoundLocation(), trsf, GetUnitFactor())) {
961 TopLoc_Location shapeLoc(trsf);
965 Message_Msg msg1035("IGES_1035");
966 SendWarning(st,msg1035); // Transformation : not a similarity
973 //=======================================================================
974 //function : TransferOffsetSurface
976 //=======================================================================
978 TopoDS_Shape IGESToBRep_TopoSurface::TransferOffsetSurface
979 (const Handle(IGESGeom_OffsetSurface)& st)
980 { // Declaration of messages//
982 //Message_Msg msg1005("IGES_1005");
983 ////////////////////////////////
986 Message_Msg msg1005("IGES_1005");
987 SendFail(st, msg1005);
991 TopoDS_Shape igesShape;
993 TopLoc_Location basisLoc;
995 Handle (IGESData_IGESEntity) igesSrf = st->Surface();
996 if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
997 Message_Msg msg164("XSTEP_164");
998 SendFail(st, msg164);
999 // Basis Surface Reading Error : Null IGESEntity
1000 // Basis Surface Transfer Error : Not Allowed IGESEntity
1004 igesShape = TransferTopoSurface(igesSrf);
1005 if (igesShape.IsNull()) {
1006 Message_Msg msg1156("IGES_1156");
1007 const Standard_CString typeName("basis surface");
1008 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1009 msg1156.Arg(typeName);
1011 SendFail(st, msg1156); // Basis Surface Conversion Error.
1015 TopAbs_ShapeEnum shapeEnum = igesShape.ShapeType();
1016 switch (shapeEnum) {
1019 face = TopoDS::Face(igesShape);
1024 TopoDS_Iterator dabovil(igesShape);
1025 if (dabovil.More()) {
1026 SendWarning(st, "The First Surface only will be transfered.");
1027 face = TopoDS::Face(dabovil.Value());
1030 /* else AddF("... */
1032 Standard_FALLTHROUGH
1035 Message_Msg msg1156("IGES_1156");
1036 const Standard_CString typeName("basis surface");
1037 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1038 msg1156.Arg(typeName);
1040 SendFail(st, msg1156); // Basis Surface Conversion Error.
1046 //Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face, basisLoc);
1047 // attention on ne peut construire une Geom_OffsetSurface que
1048 // si la surface de base est au moins C1, sinon on plante !
1049 //#56 rln 25.12.98 UKI60878 entity D593 (Offset surface on C0 B-Spline)
1050 //Trying to eliminate previous limitation on processing only C1 surfaces
1051 Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face);
1052 Handle(Geom_OffsetSurface) basisSrf;
1054 if (geomSupport->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
1055 DeclareAndCast(Geom_OffsetSurface, geom140, geomSupport);
1056 geom140->SetOffsetValue(basisSrf->Offset() +
1057 st->Distance()*GetUnitFactor());
1061 if (geomSupport->Continuity() == GeomAbs_C0) {
1062 res = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape (face, Abs (st->Distance()) * GetUnitFactor());
1063 if(res.ShapeType()!=TopAbs_FACE) {
1064 Message_Msg msg1266("IGES_1266");
1065 SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
1069 geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
1070 if (geomSupport->Continuity() == GeomAbs_C0) {
1071 Message_Msg msg1266("IGES_1266");
1072 SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
1077 Message_Msg msg1267("IGES_1267");
1078 SendWarning(st, msg1267);//Basis surface is C0-continuous but was corrected to C1-continuous
1081 if (res.IsNull()) res = face;
1082 geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
1083 Standard_Real umin, umax, vmin, vmax;
1084 geomSupport->Bounds (umin, umax, vmin, vmax);
1085 if (Precision::IsInfinite (umin) || Precision::IsInfinite (umax) ||
1086 Precision::IsInfinite (vmin) || Precision::IsInfinite (vmax)) {
1087 // convert to C1 B-Spline
1088 BRepTools::UVBounds (face, umin, umax, vmin, vmax);
1089 Handle(Geom_RectangularTrimmedSurface) TS = new Geom_RectangularTrimmedSurface (geomSupport, umin, umax, vmin, vmax);
1090 Handle (Geom_BSplineSurface) BS = ShapeAlgo::AlgoContainer()->ConvertSurfaceToBSpline(TS, umin, umax, vmin, vmax);
1091 if (BS.IsNull() || BS->Continuity() == GeomAbs_C0) {
1092 Message_Msg msg1265("IGES_1265");
1093 SendFail(st, msg1265); // OffsetSurface Construction Error.
1100 basisSrf = new Geom_OffsetSurface(geomSupport, st->Distance()*GetUnitFactor());
1103 BRepLib_MakeFace MF(basisSrf, Precision::Confusion());
1105 Message_Msg msg1265("IGES_1265");
1106 SendFail(st, msg1265); // OffsetSurface Construction Error.
1112 if (st->HasTransf()) {
1115 if (IGESData_ToolLocation::ConvertLocation
1116 (GetEpsilon(),st->CompoundLocation(),trsf, GetUnitFactor())) {
1117 TopLoc_Location loc2(trsf);
1121 Message_Msg msg1035("IGES_1035");
1122 SendWarning(st,msg1035); // Transformation : not a similarity
1129 //=======================================================================
1130 //function : TransferTrimmedSurface
1132 //=======================================================================
1134 TopoDS_Shape IGESToBRep_TopoSurface::TransferTrimmedSurface
1135 (const Handle(IGESGeom_TrimmedSurface)& st)
1136 { // Declaration of messages//
1138 //Message_Msg msg1005("IGES_1005");
1139 ////////////////////////////////
1142 Message_Msg msg1005("IGES_1005");
1143 SendFail(st, msg1005);
1147 TopAbs_ShapeEnum shapeEnum;
1148 IGESToBRep_TopoCurve TC(*this);
1150 Handle (IGESData_IGESEntity) igesSurface = st->Surface();
1151 if (igesSurface.IsNull() || !IGESToBRep::IsTopoSurface(igesSurface) ) {
1152 Message_Msg msg169("XSTEP_169");
1153 SendFail(st, msg169);
1154 // BasicSurface Transfer Error : Null IGESEntity
1155 // Basis Surface, not Allowed IGESEntity.
1159 Standard_Real uFact;
1160 TopoDS_Face face, faceres;
1162 TopoDS_Shape myshape = ParamSurface(igesSurface, trans, uFact);
1164 if (!myshape.IsNull()) {
1165 shapeEnum = myshape.ShapeType();
1166 switch (shapeEnum) {
1169 face = TopoDS::Face(myshape);
1175 TopoDS_Iterator IT(myshape);
1176 Standard_Integer nbfaces = 0;
1177 for (; IT.More(); IT.Next()) {
1179 face = TopoDS::Face(IT.Value());
1182 //szv#4:S4163:12Mar99 optimized
1184 Message_Msg msg1156("IGES_1156");
1185 const Standard_CString typeName("basis surface");
1186 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
1187 msg1156.Arg(typeName);
1189 SendFail(st, msg1156); // Not Implemented Trimmed Composite Surface.
1196 Message_Msg msg1156("IGES_1156");
1197 const Standard_CString typeName("basis surface");
1198 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
1199 msg1156.Arg(typeName);
1201 SendFail(st, msg1156); // Basis Surface Conversion Error.
1210 //obtaining a surface
1212 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(face, L);
1213 TC.SetSurface(aSurf);
1215 if (st->HasOuterContour()) {
1217 TopoDS_Shape myshape1 = TC.TransferCurveOnFace (face, st->OuterContour(), trans, uFact, Standard_False);
1218 // si ca se passe mal , on recupere au moins la face avec NaturalRestriction
1219 if (myshape1 .IsNull()) {
1222 B.NaturalRestriction(face,Standard_False);
1225 for (Standard_Integer i = 1; i <= st->NbInnerContours(); i++) {
1226 TopoDS_Shape myshape2 = TC.TransferCurveOnFace (face, st->InnerContour(i), trans, uFact, Standard_False);
1229 Handle(IGESData_TransfEntity) aTransf = st->Transf();
1230 if (!aTransf.IsNull()) {
1231 // make transformation
1232 gp_GTrsf aGT = aTransf->Value();
1233 gp_XYZ aTrans = aGT.TranslationPart();
1234 gp_Mat aMat = aGT.VectorialPart();
1235 Standard_Real s1 = aMat.Value(1, 1)*aMat.Value(1, 1) + aMat.Value(2, 1)*aMat.Value(2, 1) + aMat.Value(3, 1)*aMat.Value(3, 1);
1236 Standard_Real s2 = aMat.Value(1, 2)*aMat.Value(1, 2) + aMat.Value(2, 2)*aMat.Value(2, 2) + aMat.Value(3, 2)*aMat.Value(3, 2);
1237 Standard_Real s3 = aMat.Value(1, 3)*aMat.Value(1, 3) + aMat.Value(2, 3)*aMat.Value(2, 3) + aMat.Value(3, 3)*aMat.Value(3, 3);
1238 if (fabs(s1 - s2) > Precision::Confusion() || fabs(s1 - s3) > Precision::Confusion()) {
1239 BRepBuilderAPI_GTransform aTransform(aGT);
1240 aTransform.Perform(face, Standard_True);
1241 if (aTransform.IsDone()) {
1242 if (aTransform.Shape().ShapeType() == TopAbs_FACE) {
1243 face = TopoDS::Face(aTransform.Shape());
1248 Standard_Real tmpVal = fabs(aMat.Value(1, 1) - 1.) + fabs(aMat.Value(1, 2)) + fabs(aMat.Value(1, 3)) +
1249 fabs(aMat.Value(2, 1)) + fabs(aMat.Value(2, 2) - 1.) + fabs(aMat.Value(2, 3)) +
1250 fabs(aMat.Value(3, 1)) + fabs(aMat.Value(3, 2)) + fabs(aMat.Value(3, 3) - 1.);
1251 if ((tmpVal + aTrans.Modulus()) > Precision::Confusion()) {
1255 aMat.Value(1, 1), aMat.Value(1, 2), aMat.Value(1, 3), aTrans.X(),
1256 aMat.Value(2, 1), aMat.Value(2, 2), aMat.Value(2, 3), aTrans.Y(),
1257 aMat.Value(3, 1), aMat.Value(3, 2), aMat.Value(3, 3), aTrans.Z());
1258 TopLoc_Location aLoc(aT);
1264 BRepTools::Update ( face ); //:p4
1270 //=======================================================================
1271 //function : TransferBoundedSurface
1273 //=======================================================================
1275 TopoDS_Shape IGESToBRep_TopoSurface::TransferBoundedSurface
1276 (const Handle(IGESGeom_BoundedSurface)& st)
1277 { // Declaration of messages//
1279 //Message_Msg msg1005("IGES_1005");
1280 ////////////////////////////////
1283 Message_Msg msg1005("IGES_1005");
1284 SendFail(st, msg1005);
1288 if (st->RepresentationType()==0) {
1289 Message_Msg msg1275("IGES_1275");
1290 SendWarning(st, msg1275);
1291 // Model Space Representation Not Implemented : the result will be the basis surface
1294 TopAbs_ShapeEnum shapeEnum;
1295 IGESToBRep_TopoCurve TC(*this);
1296 Handle (IGESData_IGESEntity) igesSrf = st->Surface();
1297 if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
1298 Message_Msg msg166("XSTEP_166");
1299 SendFail( st, msg166);
1300 // Basis Surface Transfer Error : Null IGESEntity.
1301 // Basis Surface Transfer Error : Not Allowed IGESEntity.
1305 Standard_Real uFact;
1308 TopoDS_Shape myshape = ParamSurface(igesSrf, trans, uFact);
1310 if (myshape.IsNull()) {
1311 //#55 rln 24.12.98 UKI60878 entity D593
1313 std::cout << "Fail: IGESToBRep_TopoSurface::TransferBoundedSurface UntrimmedSurface is translated into Null" << std::endl;
1318 shapeEnum = myshape.ShapeType();
1319 switch (shapeEnum) {
1322 face = TopoDS::Face(myshape);
1327 TopoDS_Iterator IT(myshape);
1328 Standard_Integer nbfaces = 0;
1329 for (; IT.More(); IT.Next()) {
1331 face = TopoDS::Face(IT.Value());
1333 //szv#4:S4163:12Mar99 optimized
1335 Message_Msg msg1156("IGES_1156");
1336 const Standard_CString typeName("basis surface");
1337 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1338 msg1156.Arg(typeName);
1340 SendFail(st, msg1156);
1341 // Not Implemented Trimmed Composite Surface.
1348 Message_Msg msg1156("IGES_1156");
1349 const Standard_CString typeName("basis surface");
1350 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1351 msg1156.Arg(typeName);
1353 SendFail(st, msg1156);
1360 for (Standard_Integer i = 1; i <= st->NbBoundaries(); i++)
1361 TC.TransferBoundaryOnFace(face, st->Boundary(i), trans, uFact);
1363 BRepTools::Update ( face ); //:p4
1364 //#22 rln 01.06.98 UK3.igs entity 1279
1365 // ShapeFix_Face sff ( face );
1366 // sff.FixMissingSeam(); //:l1 abv 10 Jan 99: USA60022 7289: fix missing seam
1367 // if(sff.FixSmallAreaWire()) { //%14 pdn 24.02,99: USA60293: fix small area wires.
1368 // AddFail(st, "Small area wire detected, dropped");
1370 // sff.FixOrientation();
1371 // face = sff.Face();
1377 //=======================================================================
1378 //function : TransferPlane
1380 //=======================================================================
1382 TopoDS_Shape IGESToBRep_TopoSurface::TransferPlane
1383 (const Handle(IGESGeom_Plane)& st)
1384 { // Declaration of messages//
1386 //Message_Msg msg1005("IGES_1005");
1387 ////////////////////////////////
1390 Message_Msg msg1005("IGES_1005");
1391 SendFail(st, msg1005);
1397 res = TransferPlaneParts (st, pln,trsf,Standard_True);
1398 // res contient (en principe ...) une Face avec eventuellement un Wire
1399 // il reste a la mettre en position
1400 if (trsf.Form() != gp_Identity) {
1401 TopLoc_Location loc(trsf);
1408 //=======================================================================
1409 //function : TransferPlaneSurface
1410 //purpose : this function transferred into IGESToBRep_BasicSurface
1411 //=======================================================================
1414 //=======================================================================
1415 //function : TransferPerforate
1417 //=======================================================================
1419 TopoDS_Shape IGESToBRep_TopoSurface::TransferPerforate
1420 (const Handle(IGESBasic_SingleParent)& st)
1421 { // Declaration of messages//
1423 //Message_Msg msg1005("IGES_1005");
1424 ////////////////////////////////
1427 Message_Msg msg1005("IGES_1005");
1428 SendFail(st, msg1005);
1435 DeclareAndCast(IGESGeom_Plane,p0,st->SingleParent());
1438 Message_Msg msg206("XSTEP_206");
1439 SendFail(st, msg206);
1440 // SingleParent does not describe a holed face
1443 res = TransferPlaneParts (p0,pln,trsf,Standard_True);
1444 //res demarre avec la face et son contour externe
1445 Standard_Integer nb = st->NbChildren();
1446 for (Standard_Integer i = 1; i <= nb; i ++) {
1447 DeclareAndCast(IGESGeom_Plane,pi,st->Child(i));
1449 Message_Msg msg1285("IGES_1285");
1451 // A child is not a Plane, skipped, n0 %d
1452 SendWarning(st,msg1285);
1457 TopoDS_Shape wire = TransferPlaneParts (pi,pli,trsi,Standard_False);
1458 // si ce n est pas un Wire, sauter
1459 if (wire.ShapeType() != TopAbs_WIRE) {
1460 Message_Msg msg1156("IGES_1156");
1461 const Standard_CString typeName("hole");
1462 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(pi);
1463 msg1156.Arg(typeName);
1465 SendWarning(st, msg1156);
1466 // A hole could not be transferred, skipped, n0 %d
1469 // coplanaires ? verifier
1470 if (!pln.Position().IsCoplanar(pli.Position(),GetEpsGeom(),GetEpsilon())) {
1471 Message_Msg msg1295("IGES_1295");
1473 SendWarning(st,msg1295);
1474 // "A hole is not well coplanar to the face, n0 %d",i);
1476 // Ne pas oublier de composer la transformation locale a ce Wire
1477 if (trsi.Form() != gp_Identity) {
1478 TopLoc_Location locw(trsi);
1479 wire.Location(locw);
1483 // Enfin, appliquer la trsf globale
1484 if (trsf.Form() != gp_Identity) {
1485 TopLoc_Location loc(trsf);
1492 //=======================================================================
1493 //function : TransferPlaneParts
1495 //=======================================================================
1496 TopoDS_Shape IGESToBRep_TopoSurface::TransferPlaneParts(const Handle(IGESGeom_Plane)& st,
1499 const Standard_Boolean first)
1500 { // Declaration of messages//
1502 //Message_Msg msg1005("IGES_1005");
1503 ////////////////////////////////
1506 Message_Msg msg1005("IGES_1005");
1507 SendFail(st, msg1005);
1511 Standard_Real a, b, c, d;
1512 // equation de Geom : ax + by + cz + d = 0.0;
1513 // equation de IGES : ax + by + cz = d;
1514 st->Equation(a, b, c, d);
1515 pln = gp_Pln(a, b, c, -d);
1521 B.MakeFace(plane); // Just to create a empty Plane with a Tshape.
1522 Handle (Geom_Plane) geomPln = new Geom_Plane(pln);
1523 geomPln->Scale(gp_Pnt(0,0,0),GetUnitFactor());
1524 // ATTENTION, ici on CALCULE la trsf, on ne l`applique pas ...
1525 //S4054: B.UpdateFace (plane, geomPln, TopLoc_Location(),
1526 //GetEpsGeom()*GetUnitFactor());
1527 B.UpdateFace (plane, geomPln, TopLoc_Location(), Precision::Confusion());
1528 //:3 by ABV 5 Nov 97: set Infinite() flag (see below for unsetting)
1529 plane.Infinite ( Standard_True ); //:3
1532 // ATTENTION, ici on CALCULE la trsf, on ne l'appliquera qu'a la fin !
1533 if (st->HasTransf()) {
1535 if (!IGESData_ToolLocation::ConvertLocation
1536 (GetEpsilon(), st->CompoundLocation(),trsf,GetUnitFactor())) {
1537 Message_Msg msg1035("IGES_1035");
1538 SendWarning(st,msg1035); // Transformation : not a similarity
1542 if (st->HasBoundingCurve()) {
1543 IGESToBRep_TopoCurve TC(*this);
1544 Handle(IGESData_IGESEntity) crv = st->BoundingCurve();
1547 Message_Msg msg1300("IGES_1300");
1548 SendWarning(st,msg1300);
1549 //:4 by ABV 5 Nov 97: plane cannot be trimmed - let it be infinite
1550 //:4 NOTE: NB "else"
1555 if (IGESToBRep::IsTopoCurve(crv)) {
1557 if (crv->IsKind(STANDARD_TYPE(IGESGeom_CurveOnSurface))) {
1558 DeclareAndCast(IGESGeom_CurveOnSurface, crv142, crv);
1559 TopoDS_Shape myshape = TC.TransferCurveOnFace (plane, crv142, trans, TheULength, Standard_False);
1561 //:3 by ABV 5 Nov 97: set plane to be finite
1563 TopExp_Explorer ws ( plane, TopAbs_WIRE );
1564 if ( ws.More() ) plane.Infinite ( Standard_False );
1568 TopoDS_Shape shape = TC.TransferTopoCurve(crv);
1569 TopAbs_ShapeEnum shapeEnum = shape.ShapeType();
1570 switch (shapeEnum) {
1573 TopoDS_Edge edge = TopoDS::Edge(shape);
1574 Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData;
1576 wire = sewd->Wire();
1581 wire = TopoDS::Wire(shape);
1586 Message_Msg msg1156("IGES_1156");
1587 const Standard_CString typeName("Bounding curve");
1588 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
1589 msg1156.Arg(typeName);
1591 SendWarning(st, msg1156);
1592 if (first) res = plane;
1597 //S4054 CTS18953 entity 14
1598 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1600 sfw->FixConnected (GetMaxTol());
1602 BRepLib_MakeFace MF(pln, wire, Standard_False);
1604 // AddFail(st, "Plane Construction Error.");
1608 TopoDS_Face F = MF.Face();
1610 BRepGProp::SurfaceProperties(F,G);
1612 if(!st->HasBoundingCurveHole())
1616 if( st->HasBoundingCurveHole())
1618 //:3 by ABV 5 Nov 97: set plane to be finite
1619 //:3 if (first) B.Add (plane,wire);
1621 B.Add ( plane, wire );
1622 plane.Infinite ( Standard_False );
1624 //BRepLib_MakeFace MP(pln, wire);
1625 //plane = MP.Face();
1629 Message_Msg msg1156("IGES_1156");
1630 const Standard_CString typeName("Bounding curve");
1631 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
1632 msg1156.Arg(typeName);
1634 SendWarning(st, msg1156);
1635 // Plane Cannot Be Trimmed.
1639 if (first) res = plane;
1645 //=======================================================================
1646 //function : ParamSurface
1648 //=======================================================================
1649 TopoDS_Shape IGESToBRep_TopoSurface::ParamSurface(const Handle(IGESData_IGESEntity)& st,
1651 Standard_Real& uFact)
1652 { // Declaration of messages//
1654 //Message_Msg msg1005("IGES_1005");
1655 ////////////////////////////////
1659 TopoDS_Shape basisSurface = TransferTopoSurface(st);
1660 Standard_Real uscale = 1.;
1661 Standard_Real cscale = TheULength;
1662 if (basisSurface.IsNull()) {
1663 Message_Msg msg1005("IGES_1005");
1664 SendFail(st, msg1005);
1668 TopAbs_ShapeEnum shapeEnum;
1669 shapeEnum = basisSurface.ShapeType();
1671 switch (shapeEnum) {
1674 face = TopoDS::Face(basisSurface);
1679 TopoDS_Iterator IT(basisSurface);
1680 Standard_Integer nbfaces = 0;
1681 for (; IT.More(); IT.Next()) {
1683 face = TopoDS::Face(IT.Value());
1685 //szv#4:S4163:12Mar99 optimized
1687 Message_Msg msg1156("IGES_1156");
1688 const Standard_CString typeName("basis surface");
1689 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st);
1690 msg1156.Arg(typeName);
1692 SendWarning(st, msg1156);
1693 return basisSurface;
1699 //AddFail(st, "Basis Surface Transfer Error.");
1704 //S4181 pdn 19.04.99 defining shift of parametric space on base
1705 // of CAS.CADE type of surface
1706 Standard_Real paramu = 0., paramv = 0.;
1708 TopoDS_Edge theedge;
1709 Handle(Geom_Surface) Surf = BRep_Tool::Surface(face);
1711 if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1712 DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf);
1713 Surf = rectang->BasisSurface();
1716 if ((Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) ||
1717 (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) ||
1718 (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) ||
1719 (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)))) {
1721 for ( TE.Init(face,TopAbs_EDGE); TE.More(); TE.Next()){
1722 TopoDS_Edge myedge = TopoDS::Edge(TE.Current());
1723 Standard_Real First, Last;
1724 Handle(Geom2d_Curve) Curve2d = BRep_Tool::CurveOnSurface
1725 (myedge, face, First, Last);
1726 if ( Curve2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
1727 DeclareAndCast(Geom2d_Line, Line2d, Curve2d);
1728 if (Line2d->Direction().IsParallel(gp::DY2d(),Precision::Angular())){
1735 Standard_Real First, Last;
1736 Handle(Geom_Curve) Curve3d = BRep_Tool::Curve(theedge, First, Last);
1737 if (Precision::IsNegativeInfinite(First)) First = 0.;
1739 if (Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))){
1740 DeclareAndCast(Geom_CylindricalSurface, Cyl, Surf);
1741 gp_Cylinder TheCyl = Cyl->Cylinder();
1742 ElSLib::CylinderParameters(TheCyl.Position(),
1744 Curve3d->Value(First), paramu , paramv );
1747 else if (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))){
1748 DeclareAndCast(Geom_ConicalSurface, Cone, Surf);
1749 gp_Cone TheCone = Cone->Cone();
1750 ElSLib::ConeParameters(TheCone.Position(),
1751 TheCone.RefRadius(),
1752 TheCone.SemiAngle(),
1753 Curve3d->Value(First), paramu , paramv );
1756 else if (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))){
1757 DeclareAndCast(Geom_ToroidalSurface, Tore, Surf);
1758 gp_Torus TheTore = Tore->Torus();
1759 ElSLib::TorusParameters(TheTore.Position(),
1760 TheTore.MajorRadius(),
1761 TheTore.MinorRadius(),
1762 Curve3d->Value(First), paramu , paramv );
1764 else if (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) &&
1765 //: abv 18.06.02: loopback on s1.brep BRep mode, face 32 - the spherical surface (192)
1766 //: in IGES is from [-90,90] by V, i.e. similar to OCC, thus only scaling is enough
1767 ! st->IsKind (STANDARD_TYPE(IGESSolid_SphericalSurface)) ) {
1768 DeclareAndCast(Geom_SphericalSurface, Sphere, Surf);
1769 gp_Sphere TheSphere = Sphere->Sphere();
1770 ElSLib::SphereParameters(TheSphere.Position(),
1772 Curve3d->Value(First), paramu , paramv );
1775 //#88 rln 06.04.99 CTS60168, BLEND.IGS entity 68
1776 //Generatrix is Transformed Circular Arc. When creating CAS.CADE surface parameterization
1778 if (st->IsKind (STANDARD_TYPE (IGESGeom_SurfaceOfRevolution))) {
1779 DeclareAndCast (IGESGeom_SurfaceOfRevolution, revol, st);
1780 Handle(IGESData_IGESEntity) generatrix = revol->Generatrix();
1781 if (generatrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
1782 DeclareAndCast (IGESGeom_CircularArc, circ, generatrix);
1783 gp_Pnt2d startpoint = circ->StartPoint();
1784 paramv -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
1785 if (Surf->IsKind (STANDARD_TYPE(Geom_SphericalSurface)))
1786 paramv += ShapeAnalysis::AdjustToPeriod(paramv, - M_PI, M_PI);
1787 else if (Surf->IsKind (STANDARD_TYPE(Geom_ToroidalSurface)))
1788 paramv += ShapeAnalysis::AdjustToPeriod(paramv, 0, M_PI * 2);
1791 else if (st->IsKind (STANDARD_TYPE (IGESGeom_TabulatedCylinder))) {
1792 DeclareAndCast (IGESGeom_TabulatedCylinder, cylinder, st);
1793 Handle(IGESData_IGESEntity) directrix = cylinder->Directrix();
1794 if (directrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
1795 DeclareAndCast (IGESGeom_CircularArc, circ, directrix);
1796 gp_Pnt2d startpoint = circ->StartPoint();
1797 paramu -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
1798 paramu += ShapeAnalysis::AdjustToPeriod(paramu, 0, M_PI * 2);
1804 if ( Abs(paramu) <= Precision::Confusion()) paramu = 0.;
1805 if ( Abs(paramv) <= Precision::Confusion()) paramv = 0.;
1807 //S4181 pdn 16.04.99 computation of transformation depending on
1808 //IGES Type of surface
1809 Handle(IGESData_IGESEntity) isrf = st;
1810 if (isrf->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))){
1811 DeclareAndCast(IGESGeom_OffsetSurface, offsurf, isrf);
1812 isrf = offsurf->Surface();
1814 if (isrf->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
1815 DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, isrf);
1816 //S4181 pdn 19.04.99 defining transformation matrix
1818 tmp.SetTranslation(gp_Vec2d (0, -2 * M_PI));
1819 trans.PreMultiply(tmp);
1820 tmp.SetMirror(gp::OX2d());
1821 trans.PreMultiply(tmp);
1822 tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
1823 trans.PreMultiply(tmp);
1826 //CAS.CADE SA = 2*PI - IGES TA
1827 //paramu = st120->StartAngle();
1828 paramu = -(2 * M_PI - st120->EndAngle());
1833 if (isrf->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
1837 // corrected skl 13.11.2001 for BUC61054
1838 if (isrf->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
1839 Handle(IGESGeom_TabulatedCylinder) igtc = Handle(IGESGeom_TabulatedCylinder)::DownCast(isrf);
1840 Handle(IGESData_IGESEntity) idie = igtc->Directrix();
1841 Standard_Real uln=1;
1842 Standard_Real Umin,Umax,Vmin,Vmax;
1843 //scaling parameterization from [0,1]
1844 Surf->Bounds(Umin,Umax,Vmin,Vmax);
1845 uln = Abs(Umax-Umin);
1846 //computing shift of pcurves
1847 uscale = uln/cscale;
1851 if (isrf->IsKind(STANDARD_TYPE(IGESSolid_CylindricalSurface))||
1852 isrf->IsKind(STANDARD_TYPE(IGESSolid_ConicalSurface))) {
1856 if (isrf->IsKind(STANDARD_TYPE(IGESSolid_SphericalSurface))) {
1861 if (isrf->IsKind(STANDARD_TYPE(IGESSolid_ToroidalSurface))) {
1863 tmp.SetTranslation(gp_Vec2d (0, -360.)); // in IGES terms
1864 trans.PreMultiply(tmp);
1865 tmp.SetMirror(gp::OX2d());
1866 trans.PreMultiply(tmp);
1867 tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
1868 trans.PreMultiply(tmp);
1870 paramv = paramv*180./M_PI;
1876 tmp.SetTranslation(gp_Pnt2d(0.,0.), gp_Pnt2d(paramu,paramv));
1877 trans.PreMultiply(tmp);
1879 tmp.SetScale(gp_Pnt2d(0,0),cscale);
1880 trans.PreMultiply(tmp);