0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / RWStepGeom / RWStepGeom_RWQuasiUniformSurface.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <RWStepGeom_RWQuasiUniformSurface.hxx>
18 #include <StepData_Logical.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <StepGeom_BSplineSurfaceForm.hxx>
22 #include <StepGeom_CartesianPoint.hxx>
23 #include <StepGeom_HArray2OfCartesianPoint.hxx>
24 #include <StepGeom_QuasiUniformSurface.hxx>
25
26 // --- Enum : BSplineSurfaceForm ---
27 static TCollection_AsciiString bssfSurfOfLinearExtrusion(".SURF_OF_LINEAR_EXTRUSION.");
28 static TCollection_AsciiString bssfPlaneSurf(".PLANE_SURF.");
29 static TCollection_AsciiString bssfGeneralisedCone(".GENERALISED_CONE.");
30 static TCollection_AsciiString bssfToroidalSurf(".TOROIDAL_SURF.");
31 static TCollection_AsciiString bssfConicalSurf(".CONICAL_SURF.");
32 static TCollection_AsciiString bssfSphericalSurf(".SPHERICAL_SURF.");
33 static TCollection_AsciiString bssfUnspecified(".UNSPECIFIED.");
34 static TCollection_AsciiString bssfRuledSurf(".RULED_SURF.");
35 static TCollection_AsciiString bssfSurfOfRevolution(".SURF_OF_REVOLUTION.");
36 static TCollection_AsciiString bssfCylindricalSurf(".CYLINDRICAL_SURF.");
37 static TCollection_AsciiString bssfQuadricSurf(".QUADRIC_SURF.");
38
39 RWStepGeom_RWQuasiUniformSurface::RWStepGeom_RWQuasiUniformSurface () {}
40
41 void RWStepGeom_RWQuasiUniformSurface::ReadStep
42         (const Handle(StepData_StepReaderData)& data,
43          const Standard_Integer num,
44          Handle(Interface_Check)& ach,
45          const Handle(StepGeom_QuasiUniformSurface)& ent) const
46 {
47
48
49         // --- Number of Parameter Control ---
50
51         if (!data->CheckNbParams(num,8,ach,"quasi_uniform_surface")) return;
52
53         // --- inherited field : name ---
54
55         Handle(TCollection_HAsciiString) aName;
56         //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
57         data->ReadString (num,1,"name",ach,aName);
58
59         // --- inherited field : uDegree ---
60
61         Standard_Integer aUDegree;
62         //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
63         data->ReadInteger (num,2,"u_degree",ach,aUDegree);
64
65         // --- inherited field : vDegree ---
66
67         Standard_Integer aVDegree;
68         //szv#4:S4163:12Mar99 `Standard_Boolean stat3 =` not needed
69         data->ReadInteger (num,3,"v_degree",ach,aVDegree);
70
71         // --- inherited field : controlPointsList ---
72
73         Handle(StepGeom_HArray2OfCartesianPoint) aControlPointsList;
74         Handle(StepGeom_CartesianPoint) anent4;
75         Standard_Integer nsub4;
76         if (data->ReadSubList (num,4,"control_points_list",ach,nsub4)) {
77           Standard_Integer nbi4 = data->NbParams(nsub4);
78           Standard_Integer nbj4 = data->NbParams(data->ParamNumber(nsub4,1));
79           aControlPointsList = new StepGeom_HArray2OfCartesianPoint (1, nbi4, 1, nbj4);
80           for (Standard_Integer i4 = 1; i4 <= nbi4; i4 ++) {
81             Standard_Integer nsi4;
82             if (data->ReadSubList (nsub4,i4,"sub-part(control_points_list)",ach,nsi4)) {
83               for (Standard_Integer j4 =1; j4 <= nbj4; j4 ++) {
84                 //szv#4:S4163:12Mar99 `Standard_Boolean stat4 =` not needed
85                 if (data->ReadEntity (nsi4, j4,"cartesian_point", ach,
86                                       STANDARD_TYPE(StepGeom_CartesianPoint), anent4))
87                   aControlPointsList->SetValue(i4, j4, anent4);
88               }
89             }
90           }
91         }
92
93         // --- inherited field : surfaceForm ---
94
95         StepGeom_BSplineSurfaceForm aSurfaceForm = StepGeom_bssfPlaneSurf;
96         if (data->ParamType(num,5) == Interface_ParamEnum) {
97           Standard_CString text = data->ParamCValue(num,5);
98           if      (bssfSurfOfLinearExtrusion.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfLinearExtrusion;
99           else if (bssfPlaneSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfPlaneSurf;
100           else if (bssfGeneralisedCone.IsEqual(text)) aSurfaceForm = StepGeom_bssfGeneralisedCone;
101           else if (bssfToroidalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfToroidalSurf;
102           else if (bssfConicalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfConicalSurf;
103           else if (bssfSphericalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfSphericalSurf;
104           else if (bssfUnspecified.IsEqual(text)) aSurfaceForm = StepGeom_bssfUnspecified;
105           else if (bssfRuledSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfRuledSurf;
106           else if (bssfSurfOfRevolution.IsEqual(text)) aSurfaceForm = StepGeom_bssfSurfOfRevolution;
107           else if (bssfCylindricalSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfCylindricalSurf;
108           else if (bssfQuadricSurf.IsEqual(text)) aSurfaceForm = StepGeom_bssfQuadricSurf;
109           else ach->AddFail("Enumeration b_spline_surface_form has not an allowed value");
110         }
111         else ach->AddFail("Parameter #5 (surface_form) is not an enumeration");
112
113         // --- inherited field : uClosed ---
114
115         StepData_Logical aUClosed;
116         //szv#4:S4163:12Mar99 `Standard_Boolean stat6 =` not needed
117         data->ReadLogical (num,6,"u_closed",ach,aUClosed);
118
119         // --- inherited field : vClosed ---
120
121         StepData_Logical aVClosed;
122         //szv#4:S4163:12Mar99 `Standard_Boolean stat7 =` not needed
123         data->ReadLogical (num,7,"v_closed",ach,aVClosed);
124
125         // --- inherited field : selfIntersect ---
126
127         StepData_Logical aSelfIntersect;
128         //szv#4:S4163:12Mar99 `Standard_Boolean stat8 =` not needed
129         data->ReadLogical (num,8,"self_intersect",ach,aSelfIntersect);
130
131         //--- Initialisation of the read entity ---
132
133
134         ent->Init(aName, aUDegree, aVDegree, aControlPointsList, aSurfaceForm, aUClosed, aVClosed, aSelfIntersect);
135 }
136
137
138 void RWStepGeom_RWQuasiUniformSurface::WriteStep
139         (StepData_StepWriter& SW,
140          const Handle(StepGeom_QuasiUniformSurface)& ent) const
141 {
142
143         // --- inherited field name ---
144
145         SW.Send(ent->Name());
146
147         // --- inherited field uDegree ---
148
149         SW.Send(ent->UDegree());
150
151         // --- inherited field vDegree ---
152
153         SW.Send(ent->VDegree());
154
155         // --- inherited field controlPointsList ---
156
157         SW.OpenSub();
158         for (Standard_Integer i4 = 1;  i4 <= ent->NbControlPointsListI(); i4 ++) {
159           SW.NewLine(Standard_False);
160           SW.OpenSub();
161           for (Standard_Integer j4 = 1;  j4 <= ent->NbControlPointsListJ(); j4 ++) {
162             SW.Send(ent->ControlPointsListValue(i4,j4));
163             SW.JoinLast(Standard_False);
164           }
165           SW.CloseSub();
166         }
167         SW.CloseSub();
168
169         // --- inherited field surfaceForm ---
170
171         switch(ent->SurfaceForm()) {
172           case StepGeom_bssfSurfOfLinearExtrusion : SW.SendEnum (bssfSurfOfLinearExtrusion); break;
173           case StepGeom_bssfPlaneSurf : SW.SendEnum (bssfPlaneSurf); break;
174           case StepGeom_bssfGeneralisedCone : SW.SendEnum (bssfGeneralisedCone); break;
175           case StepGeom_bssfToroidalSurf : SW.SendEnum (bssfToroidalSurf); break;
176           case StepGeom_bssfConicalSurf : SW.SendEnum (bssfConicalSurf); break;
177           case StepGeom_bssfSphericalSurf : SW.SendEnum (bssfSphericalSurf); break;
178           case StepGeom_bssfUnspecified : SW.SendEnum (bssfUnspecified); break;
179           case StepGeom_bssfRuledSurf : SW.SendEnum (bssfRuledSurf); break;
180           case StepGeom_bssfSurfOfRevolution : SW.SendEnum (bssfSurfOfRevolution); break;
181           case StepGeom_bssfCylindricalSurf : SW.SendEnum (bssfCylindricalSurf); break;
182           case StepGeom_bssfQuadricSurf : SW.SendEnum (bssfQuadricSurf); break;
183         }
184
185         // --- inherited field uClosed ---
186
187         SW.SendLogical(ent->UClosed());
188
189         // --- inherited field vClosed ---
190
191         SW.SendLogical(ent->VClosed());
192
193         // --- inherited field selfIntersect ---
194
195         SW.SendLogical(ent->SelfIntersect());
196 }
197
198
199 void RWStepGeom_RWQuasiUniformSurface::Share(const Handle(StepGeom_QuasiUniformSurface)& ent, Interface_EntityIterator& iter) const
200 {
201
202         Standard_Integer nbiElem1 = ent->NbControlPointsListI();
203         Standard_Integer nbjElem1 = ent->NbControlPointsListJ();
204         for (Standard_Integer is1=1; is1<=nbiElem1; is1 ++) {
205           for (Standard_Integer js1=1; js1<=nbjElem1; js1 ++) {
206             iter.GetOneItem(ent->ControlPointsListValue(is1,js1));
207           }
208         }
209
210 }
211