0026715: Problems in reading STEP short names in complex entities
[occt.git] / src / RWStepDimTol / RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod.cxx
CommitLineData
28a73c1f 1// Created on: 2015-08-10
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 <RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
20#include <StepBasic_MeasureWithUnit.hxx>
21#include <StepData_StepReaderData.hxx>
22#include <StepData_StepWriter.hxx>
23#include <StepDimTol_DatumReference.hxx>
24#include <StepDimTol_GeometricToleranceTarget.hxx>
25#include <StepDimTol_GeometricToleranceType.hxx>
26#include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
27#include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod.hxx>
28#include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
29#include <StepDimTol_GeometricToleranceWithModifiers.hxx>
30
31//=======================================================================
32//function : RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod
33//purpose :
34//=======================================================================
35RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod::RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod()
36{
37}
38
39
40//=======================================================================
41//function : ReadStep
42//purpose :
43//=======================================================================
44
45void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod::ReadStep
46 (const Handle(StepData_StepReaderData)& data,
47 const Standard_Integer num0, Handle(Interface_Check)& ach,
48 const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)& ent) const
49{
50 Standard_Integer num = 0;//num0;
a7197ef3 51 data->NamedForComplex("GEOMETRIC_TOLERANCE","GMTTLR",num0,num,ach);
28a73c1f 52 if (!data->CheckNbParams(num,4,ach,"geometric_tolerance")) return;
53 // Own fields of GeometricTolerance
54 Handle(TCollection_HAsciiString) aName;
55 data->ReadString (num, 1, "name", ach, aName);
56 Handle(TCollection_HAsciiString) aDescription;
57 data->ReadString (num, 2, "description", ach, aDescription);
58 Handle(StepBasic_MeasureWithUnit) aMagnitude;
59 data->ReadEntity (num, 3, "magnitude", ach, STANDARD_TYPE(StepBasic_MeasureWithUnit), aMagnitude);
60 StepDimTol_GeometricToleranceTarget aTolerancedShapeAspect;
61 data->ReadEntity (num, 4, "toleranced_shape_aspect", ach, aTolerancedShapeAspect);
62
a7197ef3 63 data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE","GTWDR",num0,num,ach);
28a73c1f 64 // Own fields of GeometricToleranceWithDatumReference
65 Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
66 Standard_Integer sub5 = 0;
67 if ( data->ReadSubList (num, 1, "datum_system", ach, sub5) ) {
68 Standard_Integer nb0 = data->NbParams(sub5);
69 aDatumSystem = new StepDimTol_HArray1OfDatumSystemOrReference (1, nb0);
70 Standard_Integer num2 = sub5;
71 for ( Standard_Integer i0=1; i0 <= nb0; i0++ ) {
72 StepDimTol_DatumSystemOrReference anIt0;
73 data->ReadEntity (num2, i0, "datum_system_or_reference", ach, anIt0);
74 aDatumSystem->SetValue(i0, anIt0);
75 }
76 }
77 // Initialize entity
78 Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
79 new StepDimTol_GeometricToleranceWithDatumReference;
80 aGTWDR->SetDatumSystem(aDatumSystem);
81
82 data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_MODIFIERS",num0,num,ach);
83 // Own fields of ModifiedGeometricTolerance
84 Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
85 Standard_Integer sub = 0;
86 if ( data->ReadSubList (num, 1, "modifiers", ach, sub) ) {
87 Standard_Integer nb0 = data->NbParams(sub5);
88 aModifiers = new StepDimTol_HArray1OfGeometricToleranceModifier (1, nb0);
89 Standard_Integer num2 = sub;
90 for ( Standard_Integer i0=1; i0 <= nb0; i0++ ) {
91 StepDimTol_GeometricToleranceModifier anIt0 = StepDimTol_GTMMaximumMaterialRequirement;
92 if (data->ParamType (num2, i0) == Interface_ParamEnum) {
93 Standard_CString text = data->ParamCValue(num2, i0);
94 if (strcmp(text, ".ANY_CROSS_SECTION.")==0) anIt0 = StepDimTol_GTMAnyCrossSection;
95 else if (strcmp(text, ".COMMON_ZONE.")==0) anIt0 = StepDimTol_GTMCommonZone;
96 else if (strcmp(text, ".EACH_RADIAL_ELEMENT.")==0) anIt0 = StepDimTol_GTMEachRadialElement;
97 else if (strcmp(text, ".FREE_STATE.")==0) anIt0 = StepDimTol_GTMFreeState;
98 else if (strcmp(text, ".LEAST_MATERIAL_REQUIREMENT.")==0) anIt0 = StepDimTol_GTMLeastMaterialRequirement;
99 else if (strcmp(text, ".LINE_ELEMENT.")==0) anIt0 = StepDimTol_GTMLineElement;
100 else if (strcmp(text, ".MAJOR_DIAMETER.")==0) anIt0 = StepDimTol_GTMMajorDiameter;
101 else if (strcmp(text, ".MAXIMUM_MATERIAL_REQUIREMENT.")==0) anIt0 = StepDimTol_GTMMaximumMaterialRequirement;
102 else if (strcmp(text, ".MINOR_DIAMETER.")==0) anIt0 = StepDimTol_GTMMinorDiameter;
103 else if (strcmp(text, ".NOT_CONVEX.")==0) anIt0 = StepDimTol_GTMNotConvex;
104 else if (strcmp(text, ".PITCH_DIAMETER.")==0) anIt0 = StepDimTol_GTMPitchDiameter;
105 else if (strcmp(text, ".RECIPROCITY_REQUIREMENT.")==0) anIt0 = StepDimTol_GTMReciprocityRequirement;
106 else if (strcmp(text, ".SEPARATE_REQUIREMENT.")==0) anIt0 = StepDimTol_GTMSeparateRequirement;
107 else if (strcmp(text, ".STATISTICAL_TOLERANCE.")==0) anIt0 = StepDimTol_GTMStatisticalTolerance;
108 else if (strcmp(text, ".TANGENT_PLANE.")==0) anIt0 = StepDimTol_GTMTangentPlane;
109 else ach->AddFail("Parameter #5 (modifiers) has not allowed value");
110 }
111 else ach->AddFail("Parameter #5 (modifier) is not set of enumerations");
112 aModifiers->SetValue(i0, anIt0);
113 }
114 }
115 Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM = new StepDimTol_GeometricToleranceWithModifiers;
116 aGTWM->SetModifiers(aModifiers);
117
118 //Choose type of geometric tolerance
119 TColStd_SequenceOfAsciiString aTypes;
120 data->ComplexType(num0, aTypes);
121 Standard_CString aFirst = aTypes.First().ToCString();
122 Standard_CString aLast = aTypes.Last().ToCString();
123 StepDimTol_GeometricToleranceType aType = StepDimTol_GTTPositionTolerance;
124 if (strcmp(aFirst, "ANGULARITY_TOLERANCE") == 0) aType = StepDimTol_GTTAngularityTolerance;
125 else if (strcmp(aFirst, "CIRCULAR_RUNOUT_TOLERANCE") == 0) aType = StepDimTol_GTTCircularRunoutTolerance;
126 else if (strcmp(aFirst, "COAXIALITY_TOLERANCE") == 0) aType = StepDimTol_GTTCoaxialityTolerance;
127 else if (strcmp(aFirst, "CONCENTRICITY_TOLERANCE") == 0) aType = StepDimTol_GTTConcentricityTolerance;
128 else if (strcmp(aFirst, "CYLINDRICITY_TOLERANCE") == 0) aType = StepDimTol_GTTCylindricityTolerance;
129 else if (strcmp(aFirst, "FLATNESS_TOLERANCE") == 0) aType = StepDimTol_GTTFlatnessTolerance;
130 else if (strcmp(aLast, "LINE_PROFILE_TOLERANCE") == 0) aType = StepDimTol_GTTLineProfileTolerance;
131 else if (strcmp(aLast, "PARALLELISM_TOLERANCE") == 0) aType = StepDimTol_GTTParallelismTolerance;
132 else if (strcmp(aLast, "PERPENDICULARITY_TOLERANCE") == 0) aType = StepDimTol_GTTPerpendicularityTolerance;
133 else if (strcmp(aLast, "POSITION_TOLERANCE") == 0) aType = StepDimTol_GTTPositionTolerance;
134 else if (strcmp(aLast, "ROUNDNESS_TOLERANCE") == 0) aType = StepDimTol_GTTRoundnessTolerance;
135 else if (strcmp(aLast, "STRAIGHTNESS_TOLERANCE") == 0) aType = StepDimTol_GTTStraightnessTolerance;
136 else if (strcmp(aLast, "SURFACE_PROFILE_TOLERANCE") == 0) aType = StepDimTol_GTTSurfaceProfileTolerance;
137 else if (strcmp(aLast, "SYMMETRY_TOLERANCE") == 0) aType = StepDimTol_GTTSymmetryTolerance;
138 else if (strcmp(aLast, "TOTAL_RUNOUT_TOLERANCE") == 0) aType = StepDimTol_GTTTotalRunoutTolerance;
139 else ach->AddFail("The type of geometric tolerance is not supported");
140
141 // Initialize entity
142 ent->Init(aName, aDescription, aMagnitude, aTolerancedShapeAspect, aGTWDR, aGTWM, aType);
143
144}
145
146
147//=======================================================================
148//function : WriteStep
149//purpose :
150//=======================================================================
151
152void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod::WriteStep
153 (StepData_StepWriter& SW,
154 const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)& ent) const
155{
156 StepDimTol_GeometricToleranceType aType = ent->GetToleranceType();
157 if (aType == StepDimTol_GTTAngularityTolerance)
158 SW.StartEntity("ANGULARITY_TOLERANCE");
159 else if (aType == StepDimTol_GTTCircularRunoutTolerance)
160 SW.StartEntity("CIRCULAR_RUNOUT_TOLERANCE");
161 else if (aType == StepDimTol_GTTCoaxialityTolerance)
162 SW.StartEntity("COAXIALITY_TOLERANCE");
163 else if (aType == StepDimTol_GTTConcentricityTolerance)
164 SW.StartEntity("CONCENTRICITY_TOLERANCE");
165 else if (aType == StepDimTol_GTTCylindricityTolerance)
166 SW.StartEntity("CYLINDRICITY_TOLERANCE");
167 else if (aType == StepDimTol_GTTFlatnessTolerance)
168 SW.StartEntity("FLATNESS_TOLERANCE");
169
170 SW.StartEntity("GEOMETRIC_TOLERANCE");
171 SW.Send(ent->Name());
172 SW.Send(ent->Description());
173 SW.Send(ent->Magnitude());
174 SW.Send(ent->TolerancedShapeAspect().Value());
175 SW.StartEntity("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE");
176 SW.OpenSub();
177 for(Standard_Integer i4=1; i4<=ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length(); i4++) {
178 StepDimTol_DatumSystemOrReference Var0 =
179 ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i4);
180 SW.Send(Var0.Value());
181 }
182 SW.CloseSub();
183
184 if (aType == StepDimTol_GTTLineProfileTolerance)
185 SW.StartEntity("LINE_PROFILE_TOLERANCE");
186 else if (aType == StepDimTol_GTTParallelismTolerance)
187 SW.StartEntity("PARALLELISM_TOLERANCE");
188 else if (aType == StepDimTol_GTTPerpendicularityTolerance)
189 SW.StartEntity("PERPENDICULARITY_TOLERANCE");
190 else if (aType == StepDimTol_GTTPositionTolerance)
191 SW.StartEntity("POSITION_TOLERANCE");
192 else if (aType == StepDimTol_GTTRoundnessTolerance)
193 SW.StartEntity("ROUNDNESS_TOLERANCE");
194 else if (aType == StepDimTol_GTTStraightnessTolerance)
195 SW.StartEntity("STRAIGHTNESS_TOLERANCE");
196 else if (aType == StepDimTol_GTTSurfaceProfileTolerance)
197 SW.StartEntity("SURFACE_PROFILE_TOLERANCE");
198 else if (aType == StepDimTol_GTTSymmetryTolerance)
199 SW.StartEntity("SYMMETRY_TOLERANCE");
200 else if (aType == StepDimTol_GTTTotalRunoutTolerance)
201 SW.StartEntity("TOTAL_RUNOUT_TOLERANCE");
202}
203
204
205//=======================================================================
206//function : Share
207//purpose :
208//=======================================================================
209
210void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMod::Share
211 (const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod)& ent,
212 Interface_EntityIterator& iter) const
213{
214 // Own fields of GeometricTolerance
215 iter.AddItem (ent->Magnitude());
216 iter.AddItem (ent->TolerancedShapeAspect().Value());
217 // Own fields of GeometricToleranceWithDatumReference
218 for (Standard_Integer i3=1; i3<=ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length(); i3++ ) {
219 StepDimTol_DatumSystemOrReference Var0 = ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i3);
220 iter.AddItem (Var0.Value());
221 }
222}