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