1 // Created on: 2015-10-29
2 // Created by: Irina KRYLOVA
3 // Copyright (c) 2015 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <Interface_Check.hxx>
18 #include <Interface_EntityIterator.hxx>
19 #include <RWStepVisual_RWCoordinatesList.hxx>
20 #include <StepData_StepReaderData.hxx>
21 #include <StepData_StepWriter.hxx>
22 #include <StepRepr_RepresentationItem.hxx>
23 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
24 #include <StepVisual_PresentationStyleAssignment.hxx>
25 #include <StepVisual_CoordinatesList.hxx>
26 #include <TColgp_HArray1OfXYZ.hxx>
27 #include <gp_XYZ.hxx>
28
29 //=======================================================================
30 //function : RWStepVisual_RWCoordinatesList
31 //purpose :
32 //=======================================================================
RWStepVisual_RWCoordinatesList()33 RWStepVisual_RWCoordinatesList::RWStepVisual_RWCoordinatesList () {}
34
35 //=======================================================================
36 //function : ReadStep
37 //purpose :
38 //=======================================================================
ReadStep(const Handle (StepData_StepReaderData)& data,const Standard_Integer num,Handle (Interface_Check)& ach,const Handle (StepVisual_CoordinatesList)& ent) const39 void RWStepVisual_RWCoordinatesList::ReadStep
40 (const Handle(StepData_StepReaderData)& data,
41 const Standard_Integer num,
42 Handle(Interface_Check)& ach,
43 const Handle(StepVisual_CoordinatesList)& ent) const
44 {
45 // Number of Parameter Control
46 if (!data->CheckNbParams(num, 3, ach, "coordinate list")) return;
47
48 // Inherited field : name
49 Handle(TCollection_HAsciiString) aName;
50 data->ReadString (num, 1, "name", ach, aName);
51 Standard_Integer nbP =0;
52 data->ReadInteger(num, 2, "number_points", ach,nbP);
53
54 Handle(TColgp_HArray1OfXYZ) aPoints;// = new TColgp_HArray1OfXYZ(1, nbP);
55 Standard_Integer nsub2;
56 if (data->ReadSubList (num,3,"items",ach,nsub2))
57 {
58 Standard_Integer nb2 = data->NbParams(nsub2);
59 if( !nb2)
60 return;
61 aPoints = new TColgp_HArray1OfXYZ(1, nb2);
62 for (Standard_Integer i = 1; i <= nb2; i++)
63 {
64 gp_XYZ aXYZ(0.,0.,0.);
65 Standard_Integer nsub3;
66 if (data->ReadSubList (nsub2,i,"coordinates",ach,nsub3)) {
67 Standard_Integer nb3 = data->NbParams(nsub3);
68 if(nb3 > 3) {
69 ach->AddWarning("More than 3 coordinates, ignored");
70 }
71 Standard_Integer nbcoord = Min (nb3, 3);
72 for (Standard_Integer j = 1; j <= nbcoord; j++) {
73 Standard_Real aVal =0.;
74 if (data->ReadReal (nsub3,j,"coordinates",ach,aVal)) {
75 aXYZ.SetCoord(j, aVal);
76 }
77 }
78
79 }
80 aPoints->SetValue(i, aXYZ);
81 }
82 }
83
84
85 //--- Initialisation of the read entity ---
86
87
88 ent->Init(aName, aPoints);
89 }
90
91 //=======================================================================
92 //function : WriteStep
93 //purpose :
94 //=======================================================================
WriteStep(StepData_StepWriter & SW,const Handle (StepVisual_CoordinatesList)& ent) const95 void RWStepVisual_RWCoordinatesList::WriteStep
96 (StepData_StepWriter& SW, const Handle(StepVisual_CoordinatesList)& ent) const
97 {
98 // Inherited field : name
99 SW.Send(ent->Name());
100
101 // Own field : npoints
102 SW.Send(ent->Points()->Length());
103
104 // Own field : position_coords
105 SW.OpenSub();
106 for (Standard_Integer i = 1; i <= ent->Points()->Length(); i++) {
107 SW.OpenSub();
108 gp_XYZ aPoint = ent->Points()->Value(i);
109 SW.Send(aPoint.X());
110 SW.Send(aPoint.Y());
111 SW.Send(aPoint.Z());
112 SW.CloseSub();
113 }
114 SW.CloseSub();
115 }
116