48c365ccd53ffd4aeee5de4fcf14a8355bf4e23c
[occt.git] / src / BRepToIGESBRep / BRepToIGESBRep_Entity.cxx
1 // Created on: 1995-04-25
2 // Created by: Marie Jose MARTZ
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // modif le 25/03/96 mjm
18 // implement ShapeCustom::DirectModification for indirect surfaces (out of norm IGES)
19 //:l4 abv 12 Jan 99: CTS22022-2: correct writing reversed shells
20 //:n3 abv 8 Feb 99: PRO17820: BRepTools::OuterWire() -> ShapeAnalysis::OuterWire
21 //szv#4 S4163
22 //S4181 pdn 20.04.99 implementing of writing IGES elementary surfaces.
23 //      abv 31.01.00 inheriting from BRepToIGES_BREntity to remove code duplication
24 //eap: Tue Aug 29 11:02:56 2000: Shape Processing moved to upper levels
25
26 #include <BRep_Tool.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepToIGES_BRWire.hxx>
29 #include <BRepToIGESBRep_Entity.hxx>
30 #include <BRepTools.hxx>
31 #include <BRepTools_WireExplorer.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom2dToIGES_Geom2dCurve.hxx>
34 #include <Geom_BezierCurve.hxx>
35 #include <Geom_BSplineCurve.hxx>
36 #include <Geom_CartesianPoint.hxx>
37 #include <Geom_Circle.hxx>
38 #include <Geom_ConicalSurface.hxx>
39 #include <Geom_Curve.hxx>
40 #include <Geom_CylindricalSurface.hxx>
41 #include <Geom_Ellipse.hxx>
42 #include <Geom_Hyperbola.hxx>
43 #include <Geom_Parabola.hxx>
44 #include <Geom_Plane.hxx>
45 #include <Geom_RectangularTrimmedSurface.hxx>
46 #include <Geom_SphericalSurface.hxx>
47 #include <Geom_Surface.hxx>
48 #include <Geom_SurfaceOfLinearExtrusion.hxx>
49 #include <Geom_SurfaceOfRevolution.hxx>
50 #include <Geom_ToroidalSurface.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <GeomToIGES_GeomCurve.hxx>
53 #include <GeomToIGES_GeomSurface.hxx>
54 #include <gp.hxx>
55 #include <gp_Circ2d.hxx>
56 #include <gp_Elips2d.hxx>
57 #include <gp_Pnt.hxx>
58 #include <gp_Pnt2d.hxx>
59 #include <gp_Trsf.hxx>
60 #include <gp_Trsf2d.hxx>
61 #include <gp_XYZ.hxx>
62 #include <IGESBasic_Group.hxx>
63 #include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx>
64 #include <IGESBasic_HArray1OfHArray1OfInteger.hxx>
65 #include <IGESData_HArray1OfIGESEntity.hxx>
66 #include <IGESData_IGESEntity.hxx>
67 #include <IGESData_IGESModel.hxx>
68 #include <IGESGeom_CompositeCurve.hxx>
69 #include <IGESGeom_Point.hxx>
70 #include <IGESSolid_EdgeList.hxx>
71 #include <IGESSolid_Face.hxx>
72 #include <IGESSolid_HArray1OfFace.hxx>
73 #include <IGESSolid_HArray1OfLoop.hxx>
74 #include <IGESSolid_HArray1OfShell.hxx>
75 #include <IGESSolid_HArray1OfVertexList.hxx>
76 #include <IGESSolid_Loop.hxx>
77 #include <IGESSolid_ManifoldSolid.hxx>
78 #include <IGESSolid_Shell.hxx>
79 #include <IGESSolid_VertexList.hxx>
80 #include <Interface_Macros.hxx>
81 #include <Interface_Static.hxx>
82 #include <Message_ProgressIndicator.hxx>
83 #include <ShapeAlgo.hxx>
84 #include <ShapeAlgo_AlgoContainer.hxx>
85 #include <TColgp_HArray1OfXYZ.hxx>
86 #include <TColStd_HArray1OfInteger.hxx>
87 #include <TColStd_HSequenceOfTransient.hxx>
88 #include <TColStd_SequenceOfInteger.hxx>
89 #include <TopAbs_Orientation.hxx>
90 #include <TopAbs_ShapeEnum.hxx>
91 #include <TopExp.hxx>
92 #include <TopExp_Explorer.hxx>
93 #include <TopLoc_Location.hxx>
94 #include <TopoDS.hxx>
95 #include <TopoDS_Compound.hxx>
96 #include <TopoDS_CompSolid.hxx>
97 #include <TopoDS_Edge.hxx>
98 #include <TopoDS_Face.hxx>
99 #include <TopoDS_Shape.hxx>
100 #include <TopoDS_Shell.hxx>
101 #include <TopoDS_Solid.hxx>
102 #include <TopoDS_Vertex.hxx>
103 #include <TopoDS_Wire.hxx>
104 #include <Transfer_FinderProcess.hxx>
105 #include <Transfer_SimpleBinderOfTransient.hxx>
106 #include <Transfer_TransientMapper.hxx>
107 #include <TransferBRep_OrientedShapeMapper.hxx>
108 #include <TransferBRep_ShapeMapper.hxx>
109
110 //#include <GeomConvert.hxx>
111 //#include <Geom2dConvert.hxx>
112 //#include <ShapeAnalysis.hxx>
113 //#include <ShapeCustom.hxx>
114 //=======================================================================
115 //function : BRepToIGESBRep_Entity
116 //purpose  : 
117 //=======================================================================
118 BRepToIGESBRep_Entity::BRepToIGESBRep_Entity()
119 {  
120   Init();
121   if (myEdgeList.IsNull()) 
122     myEdgeList = new IGESSolid_EdgeList;
123   if (myVertexList.IsNull())
124     myVertexList = new IGESSolid_VertexList;
125 }
126
127
128 //=======================================================================
129 //function : Clear
130 //purpose  : 
131 //=======================================================================
132
133 void BRepToIGESBRep_Entity::Clear()
134 {
135   myVertices.Clear();
136   myEdges.Clear();
137   myCurves.Clear();
138 }
139
140
141 //=============================================================================
142 // TransferVertexList
143 // 
144 //=============================================================================
145
146 void BRepToIGESBRep_Entity::TransferVertexList()
147 {
148
149   Standard_Integer nbvertices = myVertices.Extent();
150   if(!nbvertices)
151     return;
152   Handle(TColgp_HArray1OfXYZ) vertices= new TColgp_HArray1OfXYZ(1,nbvertices);
153   Standard_Real Unit = GetUnit();
154   Standard_Real X,Y,Z;
155
156   for (Standard_Integer ivertex = 1; ivertex <= nbvertices; ivertex++) {
157     TopoDS_Shape myshape = myVertices(ivertex);
158     TopoDS_Vertex myvertex = TopoDS::Vertex(myshape);
159     gp_Pnt Point = BRep_Tool::Pnt(myvertex);
160     Point.Coord(X,Y,Z);
161     vertices->SetValue(ivertex, gp_XYZ(X/Unit,Y/Unit,Z/Unit));
162   }
163
164   myVertexList->Init(vertices);
165 }
166
167
168 //=============================================================================
169 // IndexVertex
170 //=============================================================================
171 Standard_Integer BRepToIGESBRep_Entity::IndexVertex(const TopoDS_Vertex& myvertex) const
172 {
173   TopoDS_Shape V = myvertex;
174   return myVertices.FindIndex(V);
175 }
176
177
178 //=============================================================================
179 // AddVertex
180 // 
181 //=============================================================================
182
183 Standard_Integer BRepToIGESBRep_Entity::AddVertex(const TopoDS_Vertex& myvertex) 
184 {
185   if ( myvertex.IsNull()) return 0;
186   
187   TopoDS_Shape V = myvertex;
188   Standard_Integer index = myVertices.FindIndex(V);
189   if (index == 0) {
190     index = myVertices.Add(V);
191   }
192   
193   return index;
194 }
195
196
197 //=============================================================================
198 // TransferEdgeList
199 // 
200 //=============================================================================
201
202 void BRepToIGESBRep_Entity::TransferEdgeList()
203 {
204
205   Handle(IGESSolid_VertexList) TheVertexList = myVertexList;
206
207   Handle(IGESData_IGESEntity) mycurve;
208   Standard_Integer mystartindex, myendindex;
209   Handle(IGESSolid_VertexList) mystartlist;
210   Handle(IGESSolid_VertexList) myendlist;
211
212   Standard_Integer nbedges = myEdges.Extent();
213   if(!nbedges)
214     return;
215   Handle(IGESData_HArray1OfIGESEntity) Curves= 
216     new IGESData_HArray1OfIGESEntity(1,nbedges);
217   Handle(IGESSolid_HArray1OfVertexList) startVertexList = 
218     new IGESSolid_HArray1OfVertexList(1,nbedges);
219   Handle(TColStd_HArray1OfInteger) startVertexIndex = 
220     new TColStd_HArray1OfInteger(1,nbedges);
221   Handle(IGESSolid_HArray1OfVertexList) endVertexList = 
222     new IGESSolid_HArray1OfVertexList(1,nbedges);
223   Handle(TColStd_HArray1OfInteger) endVertexIndex = 
224     new TColStd_HArray1OfInteger(1,nbedges);
225
226   for (Standard_Integer iedge = 1; iedge <= nbedges; iedge++) {
227     TopoDS_Shape myshape = myEdges(iedge);
228     TopoDS_Edge myedge = TopoDS::Edge(myshape);
229     //  the curve 3D
230     DeclareAndCast(IGESData_IGESEntity, amycurve, myCurves(iedge));
231     Curves->SetValue(iedge, amycurve);
232     TopoDS_Vertex V1, V2;
233     TopExp::Vertices(myedge, V1, V2);
234     //  vertices follow the orientation of curve 3d
235     mystartindex = IndexVertex(V1);
236     myendindex = IndexVertex(V2);
237     startVertexIndex->SetValue(iedge, mystartindex);
238     endVertexIndex->SetValue(iedge, myendindex);
239     startVertexList->SetValue(iedge, TheVertexList);
240     endVertexList->SetValue(iedge, TheVertexList);
241   }
242
243   myEdgeList->Init
244     (Curves, startVertexList, startVertexIndex, endVertexList, endVertexIndex);
245 }
246
247
248 //=============================================================================
249 // IndexEdge
250 //=============================================================================
251 Standard_Integer BRepToIGESBRep_Entity::IndexEdge(const TopoDS_Edge& myedge) const
252 {
253   TopoDS_Shape E = myedge;
254   return myEdges.FindIndex(E);
255 }
256
257
258 //=============================================================================
259 // AddEdge
260 // 
261 //=============================================================================
262
263 Standard_Integer BRepToIGESBRep_Entity::AddEdge(const TopoDS_Edge& myedge,
264                                                 const Handle(IGESData_IGESEntity)& mycurve3d)
265 {
266   if ( myedge.IsNull()) return 0;
267   
268   TopoDS_Shape E = myedge;
269   Handle(IGESData_IGESEntity) C = mycurve3d;
270   Standard_Integer index = myEdges.FindIndex(E);
271   if (index == 0) {
272     index = myEdges.Add(E);
273     myCurves.Add(C);
274   }
275   
276   return index;
277 }
278
279
280 //=======================================================================
281 //function : TransferShape
282 //purpose  : 
283 //=======================================================================
284 Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferShape
285 (const TopoDS_Shape& start)
286 {
287   Handle(IGESData_IGESEntity) res;
288   //TopoDS_Shape theShape;
289
290   if (start.IsNull()) return res;
291
292   if (start.ShapeType() == TopAbs_VERTEX) {
293     AddWarning (start, " A Vertex alone is not a IGESBRep Entity");
294     TopoDS_Vertex V = TopoDS::Vertex(start);
295     BRepToIGES_BRWire BW(*this);
296     BW.SetModel(GetModel());
297     res = BW.TransferVertex(V);
298     return res;
299   }  
300   else if (start.ShapeType() == TopAbs_EDGE) {
301     AddWarning (start, " An Edge alone is not a IGESBRep Entity");
302     TopoDS_Edge E =  TopoDS::Edge(start);
303     BRepToIGES_BRWire BW(*this);
304     BW.SetModel(GetModel());
305     res = BW.TransferEdge(E, Standard_False);
306     return res;
307   }  
308   else if (start.ShapeType() == TopAbs_WIRE) {
309     AddWarning (start, " An Wire alone is not a IGESBRep Entity");
310     TopoDS_Wire W =  TopoDS::Wire(start);
311     BRepToIGES_BRWire BW(*this);
312     BW.SetModel(GetModel());
313     res = BW.TransferWire(W);
314     return res;
315   }  
316   else { 
317 //    theShape = ShapeCustom::DirectFaces(start);
318     if (start.ShapeType() == TopAbs_FACE) {
319       TopoDS_Face F =  TopoDS::Face(start);
320       res = TransferFace(F);
321     }  
322     else if (start.ShapeType() == TopAbs_SHELL) {
323       TopoDS_Shell S =  TopoDS::Shell(start);
324       res = TransferShell(S);
325     }  
326     else if (start.ShapeType() == TopAbs_SOLID) {
327       TopoDS_Solid M =  TopoDS::Solid(start);
328       res = TransferSolid(M);
329     }  
330     else if (start.ShapeType() == TopAbs_COMPSOLID) {
331       TopoDS_CompSolid C =  TopoDS::CompSolid(start);
332       res = TransferCompSolid(C);
333     }  
334     else if (start.ShapeType() == TopAbs_COMPOUND) {
335       TopoDS_Compound C =  TopoDS::Compound(start);
336       res = TransferCompound(C);
337     }  
338     else {
339       // error message
340     }  
341   }
342   if(res.IsNull())
343     return res;
344
345   TransferVertexList();
346   TransferEdgeList();
347   return res;
348 }
349
350
351 //=============================================================================
352 // TransferEdge
353 //=============================================================================
354
355 Handle(IGESData_IGESEntity)  BRepToIGESBRep_Entity::TransferEdge (const TopoDS_Edge& myedge)
356 {
357   BRepToIGES_BRWire BR(*this);
358   BR.SetModel(GetModel());
359   return BR.TransferEdge (myedge, Standard_True);
360 }
361
362
363 //=============================================================================
364 // TransferEdge
365 //=============================================================================
366
367 Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferEdge (const TopoDS_Edge& myedge,
368                                                                  const TopoDS_Face& myface,
369                                                                  const Standard_Real Length)
370 {
371   Handle(IGESData_IGESEntity) ICurve3d;
372   Handle(IGESData_IGESEntity) ICurve2d;
373   if ( myedge.IsNull()) return ICurve2d;
374
375   BRepToIGES_BRWire BR(*this);
376   BR.SetModel(GetModel());
377   ICurve2d = BR.TransferEdge (myedge, myface, Length, Standard_True);
378
379   // curve 3d is obligatory. If it does not exist it is created and stored in "myCurves".
380   // If the edge is degenerated, there is no associated 3d. So "edge-tuple" 
381   // will be a Vertex.
382
383   if (!BRep_Tool::Degenerated(myedge)) {
384     ICurve3d = TransferEdge(myedge);
385     if (ICurve3d.IsNull()) {
386       AddFail (myedge, " Transfer Failed : no Curve 3D ");
387     }
388     AddEdge(myedge, ICurve3d);
389   }
390     
391   return ICurve2d;
392 }
393
394
395 //=============================================================================
396 // TransferWire
397 //=============================================================================
398
399 Handle(IGESSolid_Loop) BRepToIGESBRep_Entity::TransferWire (const TopoDS_Wire& mywire,
400                                                             const TopoDS_Face& myface,
401                                                             const Standard_Real Length)
402 {
403   Handle(IGESSolid_Loop) myLoop = new IGESSolid_Loop;
404   if ( mywire.IsNull()) return myLoop;
405   Handle(IGESData_IGESEntity) Pointeur;
406
407   TColStd_SequenceOfInteger Seqindex;
408   TColStd_SequenceOfInteger Seqorient;
409   TColStd_SequenceOfInteger Seqtype;
410   Handle(IGESData_IGESEntity) ent2d ;
411   Handle(IGESData_IGESEntity) ent3d ;
412   Handle(TColStd_HSequenceOfTransient) Seq2d = new TColStd_HSequenceOfTransient();
413
414   BRepTools_WireExplorer WE;
415   //Standard_Integer nbedge = 0; //szv#4:S4163:12Mar99 unused
416   TopExp_Explorer TE(mywire, TopAbs_VERTEX);
417   if ( TE.More()) {
418     for ( WE.Init(mywire,myface); WE.More(); WE.Next()) { 
419       TopoDS_Edge E = WE.Current();
420       if (E.IsNull()) {
421         AddWarning(mywire, "an Edge is a null entity");
422       }
423       else {
424         ent2d = TransferEdge(E, myface, Length);
425         Seq2d->Append(ent2d);
426         Standard_Integer myindex; 
427
428         // add Vertices in the Map "myVertices"
429         TopoDS_Vertex V1, V2;
430         TopExp::Vertices(E, V1, V2);
431         //Standard_Integer Ivertex1, Ivertex2; //szv#4:S4163:12Mar99 not needed
432         if (!BRep_Tool::Degenerated(E)) {
433           if ( !V1.IsNull()) {
434             AddVertex(V1); //szv#4:S4163:12Mar99 `Ivertex1=` not needed
435           }
436           if ( !V2.IsNull()) {
437             AddVertex(V2); //szv#4:S4163:12Mar99 `Ivertex2=` not needed
438           }
439           myindex = IndexEdge(E);
440           Seqtype.Append(0);
441         }
442         else {
443           myindex = AddVertex(V1);
444           Seqtype.Append(1);
445         }
446         Seqindex.Append(myindex);
447         if (E.Orientation() == TopAbs_FORWARD ) Seqorient.Append(1);
448         if (E.Orientation() == TopAbs_REVERSED) Seqorient.Append(0); 
449       }
450     }
451   }
452   else 
453     AddWarning(mywire, " no Vertex associated to the Wire");
454
455   Standard_Integer nbedges = Seq2d->Length();
456   Handle(TColStd_HArray1OfInteger) types = new TColStd_HArray1OfInteger(1,nbedges);
457   Standard_Integer mytype;
458   Handle(IGESData_HArray1OfIGESEntity) edges = new IGESData_HArray1OfIGESEntity(1,nbedges);
459   Handle(IGESData_IGESEntity) myedge;
460   Handle(TColStd_HArray1OfInteger) index = new TColStd_HArray1OfInteger(1,nbedges);
461   Standard_Integer myindex;
462   Handle(TColStd_HArray1OfInteger) orient = new TColStd_HArray1OfInteger(1,nbedges);
463   Standard_Integer myorient;
464   Handle(TColStd_HArray1OfInteger) nbcurves = new TColStd_HArray1OfInteger(1,nbedges);
465   Standard_Integer mynbcurve;
466   Handle(TColStd_HArray1OfInteger) flag;
467   Handle(IGESBasic_HArray1OfHArray1OfInteger) isoflags = 
468     new IGESBasic_HArray1OfHArray1OfInteger(1,nbedges);
469   Standard_Integer myisoflag;
470   Handle(IGESData_HArray1OfIGESEntity) curve;
471   Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) curves = 
472     new IGESBasic_HArray1OfHArray1OfIGESEntity(1,nbedges);
473   Handle(IGESData_IGESEntity) mycurve;
474
475
476   for (Standard_Integer itab = 1; itab <= nbedges; itab++) {
477     mytype = Seqtype.Value(itab);
478     types->SetValue(itab,mytype);
479     if ( mytype == 0) 
480       Pointeur = myEdgeList;
481     else
482       Pointeur = myVertexList;
483     edges->SetValue(itab,Pointeur);
484     myindex = Seqindex.Value(itab);
485     index->SetValue(itab, myindex);
486     myorient = Seqorient.Value(itab);
487     orient->SetValue(itab, myorient);
488     mynbcurve = ( Seq2d->Value(itab).IsNull() ? 0 : 1 ); // abv 31 Jan 00: to be able not to write pcurves: was 1
489     nbcurves->SetValue(itab, mynbcurve);
490     myisoflag = 0;
491     flag = new TColStd_HArray1OfInteger(1,1);  
492     flag->SetValue(1,myisoflag);
493     isoflags->SetValue(itab,flag);
494     mycurve = GetCasted(IGESData_IGESEntity, Seq2d->Value(itab));
495     curve = new IGESData_HArray1OfIGESEntity(1,1);
496     curve->SetValue(1,mycurve);
497     curves->SetValue(itab,curve);
498   }
499   
500   myLoop->Init(types, edges, index, orient, nbcurves, isoflags, curves);
501
502   SetShapeResult ( mywire, myLoop );
503
504   return myLoop;
505 }
506
507
508 //=============================================================================
509 // TransferFace
510 // 
511 //=============================================================================
512
513 Handle(IGESSolid_Face) BRepToIGESBRep_Entity ::TransferFace(const TopoDS_Face& start)
514 {
515   Handle(Message_ProgressIndicator) progress = GetTransferProcess()->GetProgress();
516   if ( ! progress.IsNull() ) {
517     if ( progress->UserBreak() ) return 0;
518     progress->Increment();
519   }
520   
521   Handle(IGESSolid_Face) myent = new IGESSolid_Face;
522   if ( start.IsNull()) return myent;
523   Handle(IGESData_IGESEntity) ISurf;
524   Standard_Real Length = 1.;
525
526   // returns the face surface, the face tolerance, the face natural restriction flag.
527   // --------------------------------------------------------------------------------
528   Handle(Geom_Surface) Surf = BRep_Tool::Surface(start);
529   if (!Surf.IsNull()) {
530     Standard_Real U1, U2, V1, V2;
531     BRepTools::UVBounds(start, U1, U2, V1, V2);  // to limit the base surfaces
532     GeomToIGES_GeomSurface GS;
533     //S4181 pdn 17.04.99 Boolean flags in order to define write of elementary surfaces added.
534     GS.SetBRepMode(Standard_True);
535     GS.SetAnalyticMode ( Interface_Static::IVal("write.convertsurface.mode") ==0 );
536     GS.SetModel(GetModel());
537
538     Handle(Geom_Surface) st;
539     if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { 
540       DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf);
541       st = rectang->BasisSurface();
542     }
543     else 
544       st= Surf;
545
546     //S4181 pdn 17.04.99 Geom_Plane translated into GeomToIGES_GeomSurface
547     ISurf = GS.TransferSurface(st, U1, U2, V1, V2);
548     if (ISurf.IsNull()) {
549       AddWarning (start, "the basic surface is a null entity");
550       return myent;
551     }
552     Length = GS.Length();
553   }
554
555
556   // returns the wires of start
557   // --------------------------
558
559   // to explore the face , it is required to set it FORWARD.
560   TopoDS_Face myface = start;
561   Standard_Boolean IsReversed = Standard_False;
562   if (start.Orientation() == TopAbs_REVERSED) {
563     myface.Reverse();
564     IsReversed = Standard_True;
565   }
566
567   // outer wire
568 //:n3  TopoDS_Wire Outer = BRepTools::OuterWire(myface);
569   TopoDS_Wire Outer = ShapeAlgo::AlgoContainer()->OuterWire(myface); //:n3 
570   Handle(IGESSolid_Loop) OuterLoop = new IGESSolid_Loop;
571   Standard_Boolean OuterLoopFlag = Standard_False;
572   if (!Outer.IsNull()) {
573     OuterLoopFlag = Standard_True;
574     OuterLoop = TransferWire(Outer, myface, Length);
575   }
576
577   // inner wires
578   TopExp_Explorer Ex;
579   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
580
581   for (Ex.Init(myface,TopAbs_WIRE); Ex.More(); Ex.Next()) {
582     TopoDS_Wire W = TopoDS::Wire(Ex.Current());
583     Handle(IGESSolid_Loop) InnerLoop = new IGESSolid_Loop;
584     if (W.IsNull()) {
585       AddWarning(start," a Wire is a null entity");
586     }
587     else if (!W.IsSame(Outer)) {
588       InnerLoop = TransferWire(W, myface, Length);
589       if (!InnerLoop.IsNull()) Seq->Append(InnerLoop);
590     }
591   }
592
593   // all inner edges not in a wire
594   for (Ex.Init(myface,TopAbs_EDGE,TopAbs_WIRE); Ex.More(); Ex.Next()) {
595     TopoDS_Edge E = TopoDS::Edge(Ex.Current());
596     AddWarning ( E, "An edge alone is not transfer as an IGESBRep Entity");
597   }
598
599   Standard_Integer nbent = Seq->Length();
600   Handle(IGESSolid_HArray1OfLoop) TabLoop;
601   TabLoop = new IGESSolid_HArray1OfLoop(1,nbent+1);
602   TabLoop->SetValue(1,OuterLoop);
603   if ( nbent >= 1) {
604     for (Standard_Integer itab = 1; itab <= nbent; itab++) {
605       Handle(IGESSolid_Loop) item = GetCasted(IGESSolid_Loop, Seq->Value(itab));
606       TabLoop->SetValue(itab+1,item);
607     }
608   }
609
610   // returns the Face
611   // ----------------
612   myent-> Init (ISurf, OuterLoopFlag, TabLoop);
613
614   if (IsReversed) myface.Reverse();
615
616   SetShapeResult ( start, myent );
617
618   return myent;
619 }
620
621
622 //=============================================================================
623 // TransferShell
624 //=============================================================================
625
626 Handle(IGESSolid_Shell) BRepToIGESBRep_Entity ::TransferShell(const TopoDS_Shell& start)
627 {
628   Handle(IGESSolid_Shell) myshell = new IGESSolid_Shell;
629   if ( start.IsNull()) return myshell;
630
631   TopExp_Explorer Ex;
632   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
633   TColStd_SequenceOfInteger SeqFlag;
634   Handle(IGESSolid_Face) IFace;
635
636   for (Ex.Init(start,TopAbs_FACE); Ex.More(); Ex.Next()) {
637     TopoDS_Face F = TopoDS::Face(Ex.Current());
638     if ( start.Orientation() == TopAbs_REVERSED ) F.Reverse(); //:l4 abv 12 Jan 99: CTS22022-2: writing reversed shells
639     if (F.IsNull()) {
640       AddWarning(start," a Face is a null entity");
641     }
642     else {
643       IFace = TransferFace(F);
644       if (!IFace.IsNull()) {
645         Seq->Append(IFace);
646         if (F.Orientation() == TopAbs_FORWARD ) SeqFlag.Append(1);
647         if (F.Orientation() == TopAbs_REVERSED) SeqFlag.Append(0); 
648       }
649     }
650   }
651
652
653   Standard_Integer nbfaces = Seq->Length();  
654   Handle(IGESSolid_HArray1OfFace) TabFace = new IGESSolid_HArray1OfFace(1,nbfaces);
655   Handle(TColStd_HArray1OfInteger) TabFlag = new TColStd_HArray1OfInteger(1,nbfaces);
656   for (Standard_Integer itab = 1; itab <= nbfaces; itab++) {
657     Handle(IGESSolid_Face) itemface = GetCasted(IGESSolid_Face, Seq->Value(itab));
658     TabFace->SetValue(itab,itemface);
659     Standard_Integer item = SeqFlag.Value(itab);
660     TabFlag->SetValue(itab, item);
661   }
662
663   myshell->Init(TabFace,TabFlag);
664
665   SetShapeResult ( start, myshell );
666
667   return myshell;
668 }
669
670
671 //=============================================================================
672 // TransferSolid
673 // with a Solid
674 //=============================================================================
675
676 Handle(IGESSolid_ManifoldSolid) BRepToIGESBRep_Entity ::TransferSolid (const TopoDS_Solid& start)
677 {
678   Handle(IGESSolid_ManifoldSolid) mysol = new IGESSolid_ManifoldSolid;
679   if ( start.IsNull()) return mysol;
680
681   TopExp_Explorer Ex;
682   Handle(IGESSolid_Shell) IShell, FirstShell;
683   Standard_Integer ShellFlag = 1;
684   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
685   TColStd_SequenceOfInteger SeqFlag;
686
687   for (Ex.Init(start,TopAbs_SHELL); Ex.More(); Ex.Next()) {
688     TopoDS_Shell S = TopoDS::Shell(Ex.Current());
689     if (S.IsNull()) {
690       AddWarning(start," a Shell is a null entity");
691     }
692     else {
693       IShell = TransferShell(S);
694       if (!IShell.IsNull()) { 
695         Seq->Append(IShell);
696         if (S.Orientation() == TopAbs_FORWARD ) SeqFlag.Append(1);
697         if (S.Orientation() == TopAbs_REVERSED) SeqFlag.Append(0); 
698       }
699     }
700   }
701
702
703   Standard_Integer nbshells = Seq->Length();
704   Handle(IGESSolid_HArray1OfShell) Tab;
705   Handle(TColStd_HArray1OfInteger) TabFlag;
706   if ( nbshells > 1) {
707     Tab     =  new IGESSolid_HArray1OfShell(1,nbshells-1);
708     TabFlag =  new TColStd_HArray1OfInteger(1,nbshells-1);
709     for (Standard_Integer itab = 1; itab <= nbshells; itab++) {
710       Handle(IGESSolid_Shell) itemShell = GetCasted(IGESSolid_Shell, Seq->Value(itab));
711       Standard_Integer item = SeqFlag.Value(itab);
712       if (itab == 1) {
713         FirstShell = itemShell;
714         ShellFlag = item;
715       }
716       else {
717         Tab->SetValue(itab-1,itemShell);
718         TabFlag->SetValue(itab-1, item);
719       }
720     }
721   }
722
723   if (nbshells == 1) {
724     FirstShell = GetCasted(IGESSolid_Shell, Seq->Value(1));
725     ShellFlag = SeqFlag.Value(1);
726     Tab.Nullify();  TabFlag.Nullify();
727     mysol->Init(FirstShell, ShellFlag != 0, Tab, TabFlag);
728   }
729   else if (nbshells >=2 ) {
730     mysol->Init(FirstShell, ShellFlag != 0, Tab, TabFlag);
731   }
732   else
733     AddWarning (start, " no Result ");
734
735   SetShapeResult ( start, mysol );
736
737   return mysol;
738 }
739
740
741 //=============================================================================
742 // TransferCompSolid
743 // with a CompSolid
744 //=============================================================================
745
746 Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferCompSolid (const TopoDS_CompSolid& start)
747 {
748   Handle(IGESData_IGESEntity) myent;
749   if ( start.IsNull()) return myent;
750
751   TopExp_Explorer Ex;
752   Handle(IGESSolid_ManifoldSolid) ISolid = new IGESSolid_ManifoldSolid;
753   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
754
755   for (Ex.Init(start,TopAbs_SOLID); Ex.More(); Ex.Next()) {
756     TopoDS_Solid S = TopoDS::Solid(Ex.Current());
757     if (S.IsNull()) {
758       AddWarning(start," an Solid is a null entity");
759     }
760     else {
761       ISolid = TransferSolid(S);
762       if (!ISolid.IsNull()) Seq->Append(ISolid);
763     }
764   }
765
766
767   Standard_Integer nbsolids = Seq->Length();
768   Handle(IGESData_HArray1OfIGESEntity) Tab;
769   if ( nbsolids > 1) {
770     Tab =  new IGESData_HArray1OfIGESEntity(1,nbsolids);
771     for (Standard_Integer itab = 1; itab <= nbsolids; itab++) {
772       Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
773       Tab->SetValue(itab,item);
774     }
775   }
776
777   if (nbsolids == 1) {
778     myent = ISolid;
779   }
780   else if(nbsolids > 1 ){
781     Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
782     IGroup->Init(Tab);
783     myent = IGroup;
784   }
785
786   SetShapeResult ( start, myent );
787
788   return myent;
789 }
790
791
792 //=============================================================================
793 // TransferCompound
794 // with a Compound
795 //=============================================================================
796
797 Handle(IGESData_IGESEntity) BRepToIGESBRep_Entity::TransferCompound (const TopoDS_Compound& start)
798 {
799   Handle(IGESData_IGESEntity) res;
800   if ( start.IsNull()) return res;
801
802
803   TopExp_Explorer Ex;
804   Handle(IGESData_IGESEntity) IShape;
805   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
806
807   // take all Solids
808   for (Ex.Init(start, TopAbs_SOLID); Ex.More(); Ex.Next()) {
809     TopoDS_Solid S = TopoDS::Solid(Ex.Current());
810     if (S.IsNull()) {
811       AddWarning(start," a Solid is a null entity");
812     }
813     else {
814       IShape = TransferSolid(S);
815       if (!IShape.IsNull()) Seq->Append(IShape);
816     }
817   }
818
819   // take all isolated Shells 
820   for (Ex.Init(start, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next()) {
821     TopoDS_Shell S = TopoDS::Shell(Ex.Current());
822     if (S.IsNull()) {
823       AddWarning(start," a Shell is a null entity");
824     }
825     else {
826       IShape = TransferShell(S);
827       if (!IShape.IsNull()) Seq->Append(IShape);
828     }
829   }
830
831
832   // take all isolated Faces
833   for (Ex.Init(start, TopAbs_FACE, TopAbs_SHELL); Ex.More(); Ex.Next()) {
834     TopoDS_Face S = TopoDS::Face(Ex.Current());
835     if (S.IsNull()) {
836       AddWarning(start," a Face is a null entity");
837     }
838     else {
839       IShape = TransferFace(S);
840       if (!IShape.IsNull()) Seq->Append(IShape);
841     }
842   }
843
844
845   // take all isolated Wires 
846   for (Ex.Init(start, TopAbs_WIRE, TopAbs_FACE); Ex.More(); Ex.Next()) {
847     TopoDS_Wire S = TopoDS::Wire(Ex.Current());
848
849     BRepToIGES_BRWire BW(*this);
850     BW.SetModel(GetModel());
851     IShape = BW.TransferWire(S);
852     if (!IShape.IsNull()) Seq->Append(IShape);
853   }
854
855
856   // take all isolated Edges 
857   for (Ex.Init(start, TopAbs_EDGE, TopAbs_WIRE); Ex.More(); Ex.Next()) {
858     TopoDS_Edge S = TopoDS::Edge(Ex.Current());
859
860     BRepToIGES_BRWire BW(*this);
861     BW.SetModel(GetModel());
862     IShape = BW.TransferEdge(S, Standard_False);
863     if (!IShape.IsNull()) Seq->Append(IShape);
864   }
865
866
867   // take all isolated Vertices 
868   for (Ex.Init(start, TopAbs_VERTEX, TopAbs_EDGE); Ex.More(); Ex.Next()) {
869     TopoDS_Vertex S = TopoDS::Vertex(Ex.Current());
870
871     BRepToIGES_BRWire BW(*this);
872     BW.SetModel(GetModel());
873     IShape = BW.TransferVertex(S);
874     if (!IShape.IsNull()) Seq->Append(IShape);
875   }
876
877   // construct the group
878   Standard_Integer nbshapes = Seq->Length();
879   if (nbshapes > 0) {
880     Handle(IGESData_HArray1OfIGESEntity) Tab =
881       new IGESData_HArray1OfIGESEntity(1,nbshapes);
882     for (Standard_Integer itab = 1; itab <= nbshapes; itab++) {
883       Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
884       Tab->SetValue(itab,item);
885     }
886
887     Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
888     IGroup->Init(Tab);
889     res = IGroup;
890   }  
891
892   SetShapeResult ( start, res );
893
894   return res;
895 }