0030024: Data Exchange - STEP, IGES export support of BRep shapes based on tessellate...
[occt.git] / src / RWStepVisual / RWStepVisual_RWComplexTriangulatedSurfaceSet.cxx
1 // Created on : Thu Mar 24 18:30:11 2022 
2 // Created by: snn
3 // Generator: Express (EXPRESS -> CASCADE/XSTEP Translator) V2.0
4 // Copyright (c) Open CASCADE 2022
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 #include <RWStepVisual_RWComplexTriangulatedSurfaceSet.hxx>
18 #include <StepVisual_ComplexTriangulatedSurfaceSet.hxx>
19 #include <Interface_EntityIterator.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <TCollection_HAsciiString.hxx>
23 #include <StepVisual_CoordinatesList.hxx>
24 #include <Standard_Integer.hxx>
25 #include <TColStd_HArray2OfReal.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <Standard_Real.hxx>
28 #include <TColStd_HArray1OfInteger.hxx>
29 #include <TColStd_HArray2OfInteger.hxx>
30
31 //=======================================================================
32 //function : RWStepVisual_RWComplexTriangulatedSurfaceSet
33 //purpose  : 
34 //=======================================================================
35
36 RWStepVisual_RWComplexTriangulatedSurfaceSet::RWStepVisual_RWComplexTriangulatedSurfaceSet() {}
37
38
39 //=======================================================================
40 //function : ReadStep
41 //purpose  : 
42 //=======================================================================
43
44 void RWStepVisual_RWComplexTriangulatedSurfaceSet::ReadStep(
45   const Handle(StepData_StepReaderData)& theData,
46   const Standard_Integer theNum,
47   Handle(Interface_Check)& theCheck,
48   const Handle(StepVisual_ComplexTriangulatedSurfaceSet)& theEnt) const
49 {
50   // Check number of parameters
51   if (!theData->CheckNbParams(theNum, 7, theCheck, "complex_triangulated_surface_set"))
52   {
53     return;
54   }
55
56   // Inherited fields of RepresentationItem
57
58   Handle(TCollection_HAsciiString) aRepresentationItem_Name;
59   theData->ReadString(theNum, 1, "representation_item.name", theCheck, aRepresentationItem_Name);
60
61   // Inherited fields of TessellatedSurfaceSet
62
63   Handle(StepVisual_CoordinatesList) aTessellatedSurfaceSet_Coordinates;
64   theData->ReadEntity(theNum, 2, "tessellated_surface_set.coordinates", theCheck,
65     STANDARD_TYPE(StepVisual_CoordinatesList), aTessellatedSurfaceSet_Coordinates);
66
67   Standard_Integer aTessellatedSurfaceSet_Pnmax;
68   theData->ReadInteger(theNum, 3, "tessellated_surface_set.pnmax", theCheck, aTessellatedSurfaceSet_Pnmax);
69
70   Handle(TColStd_HArray2OfReal) aTessellatedSurfaceSet_Normals;
71   Standard_Integer sub4 = 0;
72   if (theData->ReadSubList(theNum, 4, "tessellated_surface_set.normals", theCheck, sub4))
73   {
74     Standard_Integer nb0 = theData->NbParams(sub4);
75     Standard_Integer nbj0 = theData->NbParams(theData->ParamNumber(sub4,1));
76     aTessellatedSurfaceSet_Normals = new TColStd_HArray2OfReal(1, nb0, 1, nbj0);
77     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
78     {
79       Standard_Integer subj4 = 0;
80       if ( theData->ReadSubList (sub4, i0, "sub-part(tessellated_surface_set.normals)", theCheck, subj4) ) {
81         Standard_Integer num4 = subj4;
82         for (Standard_Integer j0 = 1; j0 <= nbj0; j0++)
83         {
84           Standard_Real anIt0;
85           theData->ReadReal(num4, j0, "real", theCheck, anIt0);
86           aTessellatedSurfaceSet_Normals->SetValue(i0,j0, anIt0);
87         }
88       }
89     }
90   }
91
92   // Own fields of ComplexTriangulatedSurfaceSet
93
94   Handle(TColStd_HArray1OfInteger) aPnindex;
95   Standard_Integer sub5 = 0;
96   if (theData->ReadSubList(theNum, 5, "pnindex", theCheck, sub5))
97   {
98     Standard_Integer nb0 = theData->NbParams(sub5);
99     aPnindex = new TColStd_HArray1OfInteger(1, nb0);
100     Standard_Integer num2 = sub5;
101     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
102     {
103       Standard_Integer anIt0;
104       theData->ReadInteger(num2, i0, "integer", theCheck, anIt0);
105       aPnindex->SetValue(i0, anIt0);
106     }
107   }
108
109   Handle(TColStd_HArray2OfInteger) aTriangleStrips;
110   Standard_Integer sub6 = 0;
111   if (theData->ReadSubList(theNum, 6, "triangle_strips", theCheck, sub6))
112   {
113     Standard_Integer nb0 = theData->NbParams(sub6);
114     Standard_Integer nbj0 = theData->NbParams(theData->ParamNumber(sub6,1));
115     aTriangleStrips = new TColStd_HArray2OfInteger(1, nb0, 1, nbj0);
116     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
117     {
118       Standard_Integer subj6 = 0;
119       if ( theData->ReadSubList (sub6, i0, "sub-part(triangle_strips)", theCheck, subj6) ) {
120         Standard_Integer num4 = subj6;
121         for (Standard_Integer j0 = 1; j0 <= nbj0; j0++)
122         {
123           Standard_Integer anIt0;
124           theData->ReadInteger(num4, j0, "integer", theCheck, anIt0);
125           aTriangleStrips->SetValue(i0,j0, anIt0);
126         }
127       }
128     }
129   }
130
131   Handle(TColStd_HArray2OfInteger) aTriangleFans;
132   Standard_Integer sub7 = 0;
133   if (theData->ReadSubList(theNum, 7, "triangle_fans", theCheck, sub7))
134   {
135     Standard_Integer nb0 = theData->NbParams(sub7);
136     Standard_Integer nbj0 = theData->NbParams(theData->ParamNumber(sub7,1));
137     aTriangleFans = new TColStd_HArray2OfInteger(1, nb0, 1, nbj0);
138     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
139     {
140       Standard_Integer subj7 = 0;
141       if ( theData->ReadSubList (sub7, i0, "sub-part(triangle_fans)", theCheck, subj7) ) {
142         Standard_Integer num4 = subj7;
143         for (Standard_Integer j0 = 1; j0 <= nbj0; j0++)
144         {
145           Standard_Integer anIt0;
146           theData->ReadInteger(num4, j0, "integer", theCheck, anIt0);
147           aTriangleFans->SetValue(i0,j0, anIt0);
148         }
149       }
150     }
151   }
152
153   // Initialize entity
154   theEnt->Init(aRepresentationItem_Name, aTessellatedSurfaceSet_Coordinates, aTessellatedSurfaceSet_Pnmax, aTessellatedSurfaceSet_Normals, aPnindex, aTriangleStrips, aTriangleFans);
155 }
156
157 //=======================================================================
158 //function : WriteStep
159 //purpose  : 
160 //=======================================================================
161
162 void RWStepVisual_RWComplexTriangulatedSurfaceSet::WriteStep(
163   StepData_StepWriter& theSW,
164   const Handle(StepVisual_ComplexTriangulatedSurfaceSet)& theEnt) const
165 {
166
167   // Own fields of RepresentationItem
168
169   theSW.Send(theEnt->Name());
170
171   // Own fields of TessellatedSurfaceSet
172
173   theSW.Send(theEnt->Coordinates());
174
175   theSW.Send(theEnt->Pnmax());
176
177   theSW.OpenSub();
178   for (Standard_Integer i3 = 1; i3 <= theEnt->Normals()->RowLength(); i3++)
179   {
180     theSW.NewLine(Standard_False);
181     theSW.OpenSub();
182     for (Standard_Integer j3 = 1; j3 <= theEnt->Normals()->ColLength(); j3++)
183     {
184       Standard_Real Var0 = theEnt->Normals()->Value(i3,j3);
185       theSW.Send(Var0);
186     }
187     theSW.CloseSub();
188   }
189   theSW.CloseSub();
190
191   // Own fields of ComplexTriangulatedSurfaceSet
192
193   theSW.OpenSub();
194   for (Standard_Integer i4 = 1; i4 <= theEnt->Pnindex()->Length(); i4++)
195   {
196     Standard_Integer Var0 = theEnt->Pnindex()->Value(i4);
197     theSW.Send(Var0);
198   }
199   theSW.CloseSub();
200
201   theSW.OpenSub();
202   for (Standard_Integer i5 = 1; i5 <= theEnt->TriangleStrips()->RowLength(); i5++)
203   {
204     theSW.NewLine(Standard_False);
205     theSW.OpenSub();
206     for (Standard_Integer j5 = 1; j5 <= theEnt->TriangleStrips()->ColLength(); j5++)
207     {
208       Standard_Integer Var0 = theEnt->TriangleStrips()->Value(i5,j5);
209       theSW.Send(Var0);
210     }
211     theSW.CloseSub();
212   }
213   theSW.CloseSub();
214
215   theSW.OpenSub();
216   for (Standard_Integer i6 = 1; i6 <= theEnt->TriangleFans()->RowLength(); i6++)
217   {
218     theSW.NewLine(Standard_False);
219     theSW.OpenSub();
220     for (Standard_Integer j6 = 1; j6 <= theEnt->TriangleFans()->ColLength(); j6++)
221     {
222       Standard_Integer Var0 = theEnt->TriangleFans()->Value(i6,j6);
223       theSW.Send(Var0);
224     }
225     theSW.CloseSub();
226   }
227   theSW.CloseSub();
228 }
229
230 //=======================================================================
231 //function : Share
232 //purpose  : 
233 //=======================================================================
234
235 void RWStepVisual_RWComplexTriangulatedSurfaceSet::Share(
236   const Handle(StepVisual_ComplexTriangulatedSurfaceSet)&theEnt,
237 Interface_EntityIterator& theIter) const
238 {
239
240   // Inherited fields of RepresentationItem
241
242   // Inherited fields of TessellatedSurfaceSet
243
244   theIter.AddItem(theEnt->StepVisual_TessellatedSurfaceSet::Coordinates());
245
246   // Own fields of ComplexTriangulatedSurfaceSet
247 }