]> OCCT Git - occt.git/blob
e86c0766a8ec7026631a0f03151076876d286b62
[occt.git] /
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 #include <Interface_Check.hxx>
15 #include <Interface_EntityIterator.hxx>
16 #include "RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.pxx"
17 #include <StepBasic_MeasureWithUnit.hxx>
18 #include <StepData_StepReaderData.hxx>
19 #include <StepData_StepWriter.hxx>
20 #include <StepDimTol_GeometricToleranceWithDatumReference.hxx>
21 #include <StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol.hxx>
22 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
23 #include <StepDimTol_ModifiedGeometricTolerance.hxx>
24
25 //=================================================================================================
26
27 RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol::
28   RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol()
29 {
30 }
31
32 //=================================================================================================
33
34 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol::ReadStep(
35   const Handle(StepData_StepReaderData)&                                  data,
36   const Standard_Integer                                                  num0,
37   Handle(Interface_Check)&                                                ach,
38   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)& ent) const
39 {
40   Standard_Integer num = 0; // num0;
41   data->NamedForComplex("GEOMETRIC_TOLERANCE", "GMTTLR", num0, num, ach);
42   if (!data->CheckNbParams(num, 4, ach, "geometric_tolerance"))
43     return;
44   // Own fields of GeometricTolerance
45   Handle(TCollection_HAsciiString) aName;
46   data->ReadString(num, 1, "name", ach, aName);
47   Handle(TCollection_HAsciiString) aDescription;
48   data->ReadString(num, 2, "description", ach, aDescription);
49   Handle(StepBasic_MeasureWithUnit) aMagnitude;
50   data->ReadEntity(num, 3, "magnitude", ach, STANDARD_TYPE(StepBasic_MeasureWithUnit), aMagnitude);
51   StepDimTol_GeometricToleranceTarget aTolerancedShapeAspect;
52   data->ReadEntity(num, 4, "toleranced_shape_aspect", ach, aTolerancedShapeAspect);
53
54   data->NamedForComplex("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE", "GTWDR", num0, num, ach);
55   // Own fields of GeometricToleranceWithDatumReference
56   Handle(StepDimTol_HArray1OfDatumSystemOrReference) aDatumSystem;
57   Standard_Integer                                   sub5 = 0;
58   if (data->ReadSubList(num, 1, "datum_system", ach, sub5))
59   {
60     Standard_Integer nb0  = data->NbParams(sub5);
61     aDatumSystem          = new StepDimTol_HArray1OfDatumSystemOrReference(1, nb0);
62     Standard_Integer num2 = sub5;
63     for (Standard_Integer i0 = 1; i0 <= nb0; i0++)
64     {
65       StepDimTol_DatumSystemOrReference anIt0;
66       data->ReadEntity(num2, i0, "datum_system_or_reference", ach, anIt0);
67       aDatumSystem->SetValue(i0, anIt0);
68     }
69   }
70   // Initialize entity
71   Handle(StepDimTol_GeometricToleranceWithDatumReference) GTWDR =
72     new StepDimTol_GeometricToleranceWithDatumReference;
73   GTWDR->SetDatumSystem(aDatumSystem);
74
75   data->NamedForComplex("MODIFIED_GEOMETRIC_TOLERANCE", "MDGMTL", num0, num, ach);
76   // Own fields of ModifiedGeometricTolerance
77   StepDimTol_LimitCondition aModifier = StepDimTol_MaximumMaterialCondition;
78   if (data->ParamType(num, 1) == Interface_ParamEnum)
79   {
80     Standard_CString text = data->ParamCValue(num, 1);
81     if (strcmp(text, ".MAXIMUM_MATERIAL_CONDITION.") == 0)
82       aModifier = StepDimTol_MaximumMaterialCondition;
83     else if (strcmp(text, ".LEAST_MATERIAL_CONDITION.") == 0)
84       aModifier = StepDimTol_LeastMaterialCondition;
85     else if (strcmp(text, ".REGARDLESS_OF_FEATURE_SIZE.") == 0)
86       aModifier = StepDimTol_RegardlessOfFeatureSize;
87     else
88       ach->AddFail("Parameter in MODIFIED_GEOMETRIC_TOLERANCE has not allowed value");
89   }
90   else
91     ach->AddFail("Parameter in MODIFIED_GEOMETRIC_TOLERANCE is not enumeration");
92   Handle(StepDimTol_ModifiedGeometricTolerance) MGT = new StepDimTol_ModifiedGeometricTolerance;
93   MGT->SetModifier(aModifier);
94
95   // Initialize entity
96   ent->Init(aName, aDescription, aMagnitude, aTolerancedShapeAspect, GTWDR, MGT);
97 }
98
99 //=================================================================================================
100
101 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol::WriteStep(
102   StepData_StepWriter&                                                    SW,
103   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)& ent) const
104 {
105   SW.StartEntity("GEOMETRIC_TOLERANCE");
106   SW.Send(ent->Name());
107   SW.Send(ent->Description());
108   SW.Send(ent->Magnitude());
109   SW.Send(ent->TolerancedShapeAspect().Value());
110   SW.StartEntity("GEOMETRIC_TOLERANCE_WITH_DATUM_REFERENCE");
111   SW.OpenSub();
112   for (Standard_Integer i4 = 1;
113        i4 <= ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length();
114        i4++)
115   {
116     StepDimTol_DatumSystemOrReference Var0 =
117       ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i4);
118     SW.Send(Var0.Value());
119   }
120   SW.CloseSub();
121   SW.StartEntity("MODIFIED_GEOMETRIC_TOLERANCE");
122   switch (ent->GetModifiedGeometricTolerance()->Modifier())
123   {
124     case StepDimTol_MaximumMaterialCondition:
125       SW.SendEnum(".MAXIMUM_MATERIAL_CONDITION.");
126       break;
127     case StepDimTol_LeastMaterialCondition:
128       SW.SendEnum(".LEAST_MATERIAL_CONDITION.");
129       break;
130     case StepDimTol_RegardlessOfFeatureSize:
131       SW.SendEnum(".REGARDLESS_OF_FEATURE_SIZE.");
132       break;
133   }
134   SW.StartEntity("POSITION_TOLERANCE");
135 }
136
137 //=================================================================================================
138
139 void RWStepDimTol_RWGeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol::Share(
140   const Handle(StepDimTol_GeoTolAndGeoTolWthDatRefAndModGeoTolAndPosTol)& ent,
141   Interface_EntityIterator&                                               iter) const
142 {
143   // Own fields of GeometricTolerance
144   iter.AddItem(ent->Magnitude());
145   iter.AddItem(ent->TolerancedShapeAspect().Value());
146   // Own fields of GeometricToleranceWithDatumReference
147   for (Standard_Integer i3 = 1;
148        i3 <= ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Length();
149        i3++)
150   {
151     StepDimTol_DatumSystemOrReference Var0 =
152       ent->GetGeometricToleranceWithDatumReference()->DatumSystemAP242()->Value(i3);
153     iter.AddItem(Var0.Value());
154   }
155 }