0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / RWStepGeom / RWStepGeom_RWTrimmedCurve.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_RWTrimmedCurve.hxx>
18 #include <StepData_StepReaderData.hxx>
19 #include <StepData_StepWriter.hxx>
20 #include <StepGeom_CartesianPoint.hxx>
21 #include <StepGeom_Curve.hxx>
22 #include <StepGeom_HArray1OfTrimmingSelect.hxx>
23 #include <StepGeom_TrimmedCurve.hxx>
24 #include <StepGeom_TrimmingPreference.hxx>
25 #include <StepGeom_TrimmingSelect.hxx>
26 #include <TCollection_AsciiString.hxx>
27
28 // --- Enum : TrimmingPreference ---
29 static TCollection_AsciiString tpParameter(".PARAMETER.");
30 static TCollection_AsciiString tpUnspecified(".UNSPECIFIED.");
31 static TCollection_AsciiString tpCartesian(".CARTESIAN.");
32
33 RWStepGeom_RWTrimmedCurve::RWStepGeom_RWTrimmedCurve () {}
34
35 void RWStepGeom_RWTrimmedCurve::ReadStep
36 (const Handle(StepData_StepReaderData)& data,
37  const Standard_Integer num,
38  Handle(Interface_Check)& ach,
39  const Handle(StepGeom_TrimmedCurve)& ent) const
40 {
41   
42   
43   // --- Number of Parameter Control ---
44   
45   if (!data->CheckNbParams(num,6,ach,"trimmed_curve")) return;
46   
47   // --- inherited field : name ---
48   
49   Handle(TCollection_HAsciiString) aName;
50   //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
51   data->ReadString (num,1,"name",ach,aName);
52   
53   // --- own field : basisCurve ---
54   
55   Handle(StepGeom_Curve) aBasisCurve;
56   //szv#4:S4163:12Mar99 `Standard_Boolean stat2 =` not needed
57   data->ReadEntity(num, 2,"basis_curve", ach, STANDARD_TYPE(StepGeom_Curve), aBasisCurve);
58   
59   // --- own field : trim1 ---
60   
61   Handle(StepGeom_CartesianPoint) aCartesianPoint;
62   //Standard_Real aParameterValue; //szv#4:S4163:12Mar99 unused
63   
64   Handle(StepGeom_HArray1OfTrimmingSelect) aTrim1;
65   Standard_Integer nsub3;
66   if (data->ReadSubList (num,3,"trim_1",ach,nsub3)) {
67     Standard_Integer nb3 = data->NbParams(nsub3);
68     aTrim1 = new StepGeom_HArray1OfTrimmingSelect (1, nb3);
69     for (Standard_Integer i3 = 1; i3 <= nb3; i3 ++) {
70       StepGeom_TrimmingSelect aTrim1Item;
71       //szv#4:S4163:12Mar99 `Standard_Boolean stat3a =` not needed
72       if (data->ReadEntity (nsub3,i3,"trim_1",ach,aTrim1Item))
73         aTrim1->SetValue(i3,aTrim1Item);
74     }
75   }
76   
77   // --- own field : trim2 ---
78   
79   Handle(StepGeom_HArray1OfTrimmingSelect) aTrim2;
80   Standard_Integer nsub4;
81   if (data->ReadSubList (num,4,"trim_2",ach,nsub4)) {
82     Standard_Integer nb4 = data->NbParams(nsub4);
83     aTrim2 = new StepGeom_HArray1OfTrimmingSelect (1, nb4);
84     for (Standard_Integer i4 = 1; i4 <= nb4; i4 ++) {
85       
86       StepGeom_TrimmingSelect aTrim2Item;
87       //szv#4:S4163:12Mar99 `Standard_Boolean stat4a =` not needed
88       if (data->ReadEntity (nsub4,i4,"trim_2",ach,aTrim2Item))
89         aTrim2->SetValue(i4,aTrim2Item);
90     }
91   }
92   
93   // --- own field : senseAgreement ---
94   
95   Standard_Boolean aSenseAgreement;
96   //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
97   data->ReadBoolean (num,5,"sense_agreement",ach,aSenseAgreement);
98   
99   // --- own field : masterRepresentation ---
100   
101   StepGeom_TrimmingPreference aMasterRepresentation = StepGeom_tpCartesian;
102   if (data->ParamType(num,6) == Interface_ParamEnum) {
103     Standard_CString text = data->ParamCValue(num,6);
104     if      (tpParameter.IsEqual(text)) aMasterRepresentation = StepGeom_tpParameter;
105     else if (tpUnspecified.IsEqual(text)) aMasterRepresentation = StepGeom_tpUnspecified;
106     else if (tpCartesian.IsEqual(text)) aMasterRepresentation = StepGeom_tpCartesian;
107     else ach->AddFail("Enumeration trimming_preference has not an allowed value");
108   }
109   else ach->AddFail("Parameter #6 (master_representation) is not an enumeration");
110   
111   //--- Initialisation of the read entity ---
112   
113   
114   ent->Init(aName, aBasisCurve, aTrim1, aTrim2, aSenseAgreement, aMasterRepresentation);
115 }
116
117
118 void RWStepGeom_RWTrimmedCurve::WriteStep
119 (StepData_StepWriter& SW,
120  const Handle(StepGeom_TrimmedCurve)& ent) const
121 {
122   
123   // --- inherited field name ---
124   
125   SW.Send(ent->Name());
126   
127   // --- own field : basisCurve ---
128   
129   SW.Send(ent->BasisCurve());
130   
131   // --- own field : trim1 ---
132   
133   SW.OpenSub();
134   for (Standard_Integer i2 = 1;  i2 <= ent->NbTrim1();  i2 ++) {
135     SW.Send(ent->Trim1Value(i2).Value());
136   }
137   SW.CloseSub();
138   
139   // --- own field : trim2 ---
140   
141   SW.OpenSub();
142   for (Standard_Integer i3 = 1;  i3 <= ent->NbTrim2();  i3 ++) {
143     SW.Send(ent->Trim2Value(i3).Value());
144   }
145   SW.CloseSub();
146   
147   // --- own field : senseAgreement ---
148   
149   SW.SendBoolean(ent->SenseAgreement());
150   
151   // --- own field : masterRepresentation ---
152   
153   switch(ent->MasterRepresentation()) {
154   case StepGeom_tpParameter : 
155     SW.SendEnum (tpParameter); 
156     break;
157   case StepGeom_tpUnspecified : 
158     SW.SendEnum (tpUnspecified); 
159     break;
160   case StepGeom_tpCartesian : 
161     SW.SendEnum (tpCartesian); 
162     break;
163   }
164 }
165
166
167 void RWStepGeom_RWTrimmedCurve::Share(const Handle(StepGeom_TrimmedCurve)& ent, Interface_EntityIterator& iter) const
168 {
169
170   iter.GetOneItem(ent->BasisCurve());
171   
172   Standard_Integer nbElem2 = ent->NbTrim1();
173   for (Standard_Integer is2=1; is2<=nbElem2; is2 ++) {
174     if (ent->Trim1Value(is2).CaseNumber() > 0) {
175       iter.GetOneItem(ent->Trim1Value(is2).Value());
176     }
177   }
178   
179   Standard_Integer nbElem3 = ent->NbTrim2();
180   for (Standard_Integer is3=1; is3<=nbElem3; is3 ++) {
181     if (ent->Trim2Value(is3).CaseNumber() > 0) {
182       iter.GetOneItem(ent->Trim2Value(is3).Value());
183     }
184   }
185 }
186