1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
28 // --- Enum : TrimmingPreference ---
29 static TCollection_AsciiString tpParameter(".PARAMETER.");
30 static TCollection_AsciiString tpUnspecified(".UNSPECIFIED.");
31 static TCollection_AsciiString tpCartesian(".CARTESIAN.");
33 RWStepGeom_RWTrimmedCurve::RWStepGeom_RWTrimmedCurve () {}
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
43 // --- Number of Parameter Control ---
45 if (!data->CheckNbParams(num,6,ach,"trimmed_curve")) return;
47 // --- inherited field : name ---
49 Handle(TCollection_HAsciiString) aName;
50 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
51 data->ReadString (num,1,"name",ach,aName);
53 // --- own field : basisCurve ---
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);
59 // --- own field : trim1 ---
61 Handle(StepGeom_CartesianPoint) aCartesianPoint;
62 //Standard_Real aParameterValue; //szv#4:S4163:12Mar99 unused
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);
77 // --- own field : trim2 ---
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 ++) {
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);
93 // --- own field : senseAgreement ---
95 Standard_Boolean aSenseAgreement;
96 //szv#4:S4163:12Mar99 `Standard_Boolean stat5 =` not needed
97 data->ReadBoolean (num,5,"sense_agreement",ach,aSenseAgreement);
99 // --- own field : masterRepresentation ---
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");
109 else ach->AddFail("Parameter #6 (master_representation) is not an enumeration");
111 //--- Initialisation of the read entity ---
114 ent->Init(aName, aBasisCurve, aTrim1, aTrim2, aSenseAgreement, aMasterRepresentation);
118 void RWStepGeom_RWTrimmedCurve::WriteStep
119 (StepData_StepWriter& SW,
120 const Handle(StepGeom_TrimmedCurve)& ent) const
123 // --- inherited field name ---
125 SW.Send(ent->Name());
127 // --- own field : basisCurve ---
129 SW.Send(ent->BasisCurve());
131 // --- own field : trim1 ---
134 for (Standard_Integer i2 = 1; i2 <= ent->NbTrim1(); i2 ++) {
135 SW.Send(ent->Trim1Value(i2).Value());
139 // --- own field : trim2 ---
142 for (Standard_Integer i3 = 1; i3 <= ent->NbTrim2(); i3 ++) {
143 SW.Send(ent->Trim2Value(i3).Value());
147 // --- own field : senseAgreement ---
149 SW.SendBoolean(ent->SenseAgreement());
151 // --- own field : masterRepresentation ---
153 switch(ent->MasterRepresentation()) {
154 case StepGeom_tpParameter :
155 SW.SendEnum (tpParameter);
157 case StepGeom_tpUnspecified :
158 SW.SendEnum (tpUnspecified);
160 case StepGeom_tpCartesian :
161 SW.SendEnum (tpCartesian);
167 void RWStepGeom_RWTrimmedCurve::Share(const Handle(StepGeom_TrimmedCurve)& ent, Interface_EntityIterator& iter) const
170 iter.GetOneItem(ent->BasisCurve());
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());
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());