]> OCCT Git - occt.git/blob
ed81cb20473be0a37ad475b67d08e53aebc73f0b
[occt.git] /
1 // Created on: 2015-11-13
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 #include <Interface_Check.hxx>
17 #include <Interface_EntityIterator.hxx>
18 #include "RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.pxx"
19 #include <StepBasic_LengthMeasureWithUnit.hxx>
20 #include <StepBasic_MeasureWithUnit.hxx>
21 #include <StepData_StepReaderData.hxx>
22 #include <StepData_StepWriter.hxx>
23 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
24 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx>
25 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
26 #include <StepDimTol_GeometricToleranceWithModifiers.hxx>
27
28 //=================================================================================================
29
30 RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol::
31   RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol()
32 {
33 }
34
35 //=================================================================================================
36
37 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol::ReadStep(
38   const Handle(StepData_StepReaderData)&                               data,
39   const Standard_Integer                                               num0,
40   Handle(Interface_Check)&                                             ach,
41   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)& ent) const
42 {
43   Standard_Integer num = 0; // num0;
44   data->NamedForComplex("GEOMETRIC_TOLERANCE", "GMTTLR", num0, num, ach);
45   if (!data->CheckNbParams(num, 4, ach, "geometric_tolerance"))
46     return;
47   // Own fields of GeometricTolerance
48   Handle(TCollection_HAsciiString) aName;
49   data->ReadString(num, 1, "name", ach, aName);
50   Handle(TCollection_HAsciiString) aDescription;
51   data->ReadString(num, 2, "description", ach, aDescription);
52   Handle(StepBasic_MeasureWithUnit) aMagnitude;
53   data->ReadEntity(num, 3, "magnitude", ach, STANDARD_TYPE(StepBasic_MeasureWithUnit), aMagnitude);
54   StepDimTol_GeometricToleranceTarget aTolerancedShapeAspect;
55   data->ReadEntity(num, 4, "toleranced_shape_aspect", ach, aTolerancedShapeAspect);
56
57   data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE", "GTWDR", num0, num, ach);
58   // Own fields of GeometricToleranceWithDatumReference
59   Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
60   Standard_Integer                                   sub5 = 0;
61   if (data->ReadSubList(num, 1, "datum_system", ach, sub5))
62   {
63     Standard_Integer nb0  = data->NbParams(sub5);
64     aDatumSystem          = new StepDimTol_HArray1OfDatumSystemOrReference(1, nb0);
65     Standard_Integer num2 = sub5;
66     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
67     {
68       StepDimTol_DatumSystemOrReference anIt0;
69       data->ReadEntity(num2, i0, "datum_system_or_reference", ach, anIt0);
70       aDatumSystem->SetValue(i0, anIt0);
71     }
72   }
73   // Initialize entity
74   Handle(StepDimTol_GeometricToleranceWithDatumReference) aGTWDR =
75     new StepDimTol_GeometricToleranceWithDatumReference;
76   aGTWDR->SetDatumSystem(aDatumSystem);
77
78   data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_MAXIMUM_TOLERANCE", num0, num, ach);
79   Handle(StepBasic_LengthMeasureWithUnit) aMaxTol;
80   data->ReadEntity(num,
81                    1,
82                    "maximum_upper_tolerance",
83                    ach,
84                    STANDARD_TYPE(StepBasic_LengthMeasureWithUnit),
85                    aMaxTol);
86
87   data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_MODIFIERS", num0, num, ach);
88   // Own fields of ModifiedGeometricTolerance
89   Handle(StepDimTol_HArray1OfGeometricToleranceModifier) aModifiers;
90   Standard_Integer                                       sub = 0;
91   if (data->ReadSubList(num, 1, "modifiers", ach, sub))
92   {
93     Standard_Integer nb0  = data->NbParams(sub);
94     aModifiers            = new StepDimTol_HArray1OfGeometricToleranceModifier(1, nb0);
95     Standard_Integer num2 = sub;
96     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
97     {
98       StepDimTol_GeometricToleranceModifier anIt0 = StepDimTol_GTMMaximumMaterialRequirement;
99       if (data->ParamType(num2, i0) == Interface_ParamEnum)
100       {
101         Standard_CString text = data->ParamCValue(num2, i0);
102         if (strcmp(text, ".ANY_CROSS_SECTION.") == 0)
103           anIt0 = StepDimTol_GTMAnyCrossSection;
104         else if (strcmp(text, ".COMMON_ZONE.") == 0)
105           anIt0 = StepDimTol_GTMCommonZone;
106         else if (strcmp(text, ".EACH_RADIAL_ELEMENT.") == 0)
107           anIt0 = StepDimTol_GTMEachRadialElement;
108         else if (strcmp(text, ".FREE_STATE.") == 0)
109           anIt0 = StepDimTol_GTMFreeState;
110         else if (strcmp(text, ".LEAST_MATERIAL_REQUIREMENT.") == 0)
111           anIt0 = StepDimTol_GTMLeastMaterialRequirement;
112         else if (strcmp(text, ".LINE_ELEMENT.") == 0)
113           anIt0 = StepDimTol_GTMLineElement;
114         else if (strcmp(text, ".MAJOR_DIAMETER.") == 0)
115           anIt0 = StepDimTol_GTMMajorDiameter;
116         else if (strcmp(text, ".MAXIMUM_MATERIAL_REQUIREMENT.") == 0)
117           anIt0 = StepDimTol_GTMMaximumMaterialRequirement;
118         else if (strcmp(text, ".MINOR_DIAMETER.") == 0)
119           anIt0 = StepDimTol_GTMMinorDiameter;
120         else if (strcmp(text, ".NOT_CONVEX.") == 0)
121           anIt0 = StepDimTol_GTMNotConvex;
122         else if (strcmp(text, ".PITCH_DIAMETER.") == 0)
123           anIt0 = StepDimTol_GTMPitchDiameter;
124         else if (strcmp(text, ".RECIPROCITY_REQUIREMENT.") == 0)
125           anIt0 = StepDimTol_GTMReciprocityRequirement;
126         else if (strcmp(text, ".SEPARATE_REQUIREMENT.") == 0)
127           anIt0 = StepDimTol_GTMSeparateRequirement;
128         else if (strcmp(text, ".STATISTICAL_TOLERANCE.") == 0)
129           anIt0 = StepDimTol_GTMStatisticalTolerance;
130         else if (strcmp(text, ".TANGENT_PLANE.") == 0)
131           anIt0 = StepDimTol_GTMTangentPlane;
132         else
133           ach->AddFail("Parameter #5 (modifiers) has not allowed value");
134       }
135       else
136         ach->AddFail("Parameter #5 (modifier) is not set of enumerations");
137       aModifiers->SetValue(i0, anIt0);
138     }
139   }
140   Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
141     new StepDimTol_GeometricToleranceWithModifiers;
142   aGTWM->SetModifiers(aModifiers);
143
144   // Choose type of geometric tolerance
145   TColStd_SequenceOfAsciiString aTypes;
146   data->ComplexType(num0, aTypes);
147   Standard_CString                  aFirst = aTypes.First().ToCString();
148   Standard_CString                  aLast  = aTypes.Last().ToCString();
149   StepDimTol_GeometricToleranceType aType  = StepDimTol_GTTPositionTolerance;
150   if (strcmp(aFirst, "ANGULARITY_TOLERANCE") == 0)
151     aType = StepDimTol_GTTAngularityTolerance;
152   else if (strcmp(aFirst, "CIRCULAR_RUNOUT_TOLERANCE") == 0)
153     aType = StepDimTol_GTTCircularRunoutTolerance;
154   else if (strcmp(aFirst, "COAXIALITY_TOLERANCE") == 0)
155     aType = StepDimTol_GTTCoaxialityTolerance;
156   else if (strcmp(aFirst, "CONCENTRICITY_TOLERANCE") == 0)
157     aType = StepDimTol_GTTConcentricityTolerance;
158   else if (strcmp(aFirst, "CYLINDRICITY_TOLERANCE") == 0)
159     aType = StepDimTol_GTTCylindricityTolerance;
160   else if (strcmp(aFirst, "FLATNESS_TOLERANCE") == 0)
161     aType = StepDimTol_GTTFlatnessTolerance;
162   else if (strcmp(aLast, "LINE_PROFILE_TOLERANCE") == 0)
163     aType = StepDimTol_GTTLineProfileTolerance;
164   else if (strcmp(aLast, "PARALLELISM_TOLERANCE") == 0)
165     aType = StepDimTol_GTTParallelismTolerance;
166   else if (strcmp(aLast, "PERPENDICULARITY_TOLERANCE") == 0)
167     aType = StepDimTol_GTTPerpendicularityTolerance;
168   else if (strcmp(aLast, "POSITION_TOLERANCE") == 0)
169     aType = StepDimTol_GTTPositionTolerance;
170   else if (strcmp(aLast, "ROUNDNESS_TOLERANCE") == 0)
171     aType = StepDimTol_GTTRoundnessTolerance;
172   else if (strcmp(aLast, "STRAIGHTNESS_TOLERANCE") == 0)
173     aType = StepDimTol_GTTStraightnessTolerance;
174   else if (strcmp(aLast, "SURFACE_PROFILE_TOLERANCE") == 0)
175     aType = StepDimTol_GTTSurfaceProfileTolerance;
176   else if (strcmp(aLast, "SYMMETRY_TOLERANCE") == 0)
177     aType = StepDimTol_GTTSymmetryTolerance;
178   else if (strcmp(aLast, "TOTAL_RUNOUT_TOLERANCE") == 0)
179     aType = StepDimTol_GTTTotalRunoutTolerance;
180   else
181     ach->AddFail("The type of geometric tolerance is not supported");
182
183   // Initialize entity
184   ent->Init(aName, aDescription, aMagnitude, aTolerancedShapeAspect, aGTWDR, aGTWM, aMaxTol, aType);
185 }
186
187 //=================================================================================================
188
189 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol::WriteStep(
190   StepData_StepWriter&                                                 SW,
191   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)& ent) const
192 {
193   StepDimTol_GeometricToleranceType aType = ent->GetToleranceType();
194   if (aType == StepDimTol_GTTAngularityTolerance)
195     SW.StartEntity("ANGULARITY_TOLERANCE");
196   else if (aType == StepDimTol_GTTCircularRunoutTolerance)
197     SW.StartEntity("CIRCULAR_RUNOUT_TOLERANCE");
198   else if (aType == StepDimTol_GTTCoaxialityTolerance)
199     SW.StartEntity("COAXIALITY_TOLERANCE");
200   else if (aType == StepDimTol_GTTConcentricityTolerance)
201     SW.StartEntity("CONCENTRICITY_TOLERANCE");
202   else if (aType == StepDimTol_GTTCylindricityTolerance)
203     SW.StartEntity("CYLINDRICITY_TOLERANCE");
204   else if (aType == StepDimTol_GTTFlatnessTolerance)
205     SW.StartEntity("FLATNESS_TOLERANCE");
206
207   SW.StartEntity("GEOMETRIC_TOLERANCE");
208   SW.Send(ent->Name());
209   SW.Send(ent->Description());
210   SW.Send(ent->Magnitude());
211   SW.Send(ent->TolerancedShapeAspect().Value());
212   SW.StartEntity("GEOMETRIC_TOLERANCE_WITH_MAXIMUM_TOLERANCE");
213   SW.Send(ent->GetMaxTolerance());
214   SW.StartEntity("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE");
215   SW.OpenSub();
216   for (Standard_Integer i4 = 1;
217        i4 <= ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length();
218        i4++)
219   {
220     StepDimTol_DatumSystemOrReference Var0 =
221       ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i4);
222     SW.Send(Var0.Value());
223   }
224   SW.CloseSub();
225
226   SW.StartEntity("GEOMETRIC_TOLERANCE_WITH_MODIFIERS");
227   SW.OpenSub();
228   Handle(StepDimTol_GeometricToleranceWithModifiers) aGTWM =
229     ent->GetGeometricToleranceWithModifiers();
230   for (Standard_Integer i = 1; i <= aGTWM->NbModifiers(); i++)
231   {
232     switch (aGTWM->ModifierValue(i))
233     {
234       case StepDimTol_GTMAnyCrossSection:
235         SW.SendEnum(".ANY_CROSS_SECTION.");
236         break;
237       case StepDimTol_GTMCommonZone:
238         SW.SendEnum(".COMMON_ZONE.");
239         break;
240       case StepDimTol_GTMEachRadialElement:
241         SW.SendEnum(".EACH_RADIAL_ELEMENT.");
242         break;
243       case StepDimTol_GTMFreeState:
244         SW.SendEnum(".FREE_STATE.");
245         break;
246       case StepDimTol_GTMLeastMaterialRequirement:
247         SW.SendEnum(".LEAST_MATERIAL_REQUIREMENT.");
248         break;
249       case StepDimTol_GTMLineElement:
250         SW.SendEnum(".LINE_ELEMENT.");
251         break;
252       case StepDimTol_GTMMajorDiameter:
253         SW.SendEnum(".MAJOR_DIAMETER.");
254         break;
255       case StepDimTol_GTMMaximumMaterialRequirement:
256         SW.SendEnum(".MAXIMUM_MATERIAL_REQUIREMENT.");
257         break;
258       case StepDimTol_GTMMinorDiameter:
259         SW.SendEnum(".MINOR_DIAMETER.");
260         break;
261       case StepDimTol_GTMNotConvex:
262         SW.SendEnum(".NOT_CONVEX.");
263         break;
264       case StepDimTol_GTMPitchDiameter:
265         SW.SendEnum(".PITCH_DIAMETER.");
266         break;
267       case StepDimTol_GTMReciprocityRequirement:
268         SW.SendEnum(".RECIPROCITY_REQUIREMENT.");
269         break;
270       case StepDimTol_GTMSeparateRequirement:
271         SW.SendEnum(".SEPARATE_REQUIREMENT.");
272         break;
273       case StepDimTol_GTMStatisticalTolerance:
274         SW.SendEnum(".STATISTICAL_TOLERANCE.");
275         break;
276       case StepDimTol_GTMTangentPlane:
277         SW.SendEnum(".TANGENT_PLANE.");
278         break;
279     }
280   }
281   SW.CloseSub();
282
283   if (aType == StepDimTol_GTTLineProfileTolerance)
284     SW.StartEntity("LINE_PROFILE_TOLERANCE");
285   else if (aType == StepDimTol_GTTParallelismTolerance)
286     SW.StartEntity("PARALLELISM_TOLERANCE");
287   else if (aType == StepDimTol_GTTPerpendicularityTolerance)
288     SW.StartEntity("PERPENDICULARITY_TOLERANCE");
289   else if (aType == StepDimTol_GTTPositionTolerance)
290     SW.StartEntity("POSITION_TOLERANCE");
291   else if (aType == StepDimTol_GTTRoundnessTolerance)
292     SW.StartEntity("ROUNDNESS_TOLERANCE");
293   else if (aType == StepDimTol_GTTStraightnessTolerance)
294     SW.StartEntity("STRAIGHTNESS_TOLERANCE");
295   else if (aType == StepDimTol_GTTSurfaceProfileTolerance)
296     SW.StartEntity("SURFACE_PROFILE_TOLERANCE");
297   else if (aType == StepDimTol_GTTSymmetryTolerance)
298     SW.StartEntity("SYMMETRY_TOLERANCE");
299   else if (aType == StepDimTol_GTTTotalRunoutTolerance)
300     SW.StartEntity("TOTAL_RUNOUT_TOLERANCE");
301 }
302
303 //=================================================================================================
304
305 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol::Share(
306   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol)& ent,
307   Interface_EntityIterator&                                            iter) const
308 {
309   // Own fields of GeometricTolerance
310   iter.AddItem(ent->Magnitude());
311   iter.AddItem(ent->TolerancedShapeAspect().Value());
312   // Own fields of GeometricToleranceWithDatumReference
313   for (Standard_Integer i3 = 1;
314        i3 <= ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length();
315        i3++)
316   {
317     StepDimTol_DatumSystemOrReference Var0 =
318       ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i3);
319     iter.AddItem(Var0.Value());
320   }
321 }