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