28a73c1f |
1 | // Created on: 2015-07-16 |
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 <RWStepDimTol_RWGeneralDatumReference.hxx> |
17 | |
18 | #include <Interface_EntityIterator.hxx> |
19 | #include <StepData_StepReaderData.hxx> |
20 | #include <StepData_StepWriter.hxx> |
21 | #include <StepDimTol_Datum.hxx> |
22 | #include <StepDimTol_DatumReferenceModifier.hxx> |
23 | #include <StepDimTol_GeneralDatumReference.hxx> |
24 | #include <StepDimTol_HArray1OfDatumReferenceElement.hxx> |
25 | #include <StepRepr_ProductDefinitionShape.hxx> |
26 | |
27 | //======================================================================= |
28 | //function : RWStepDimTol_RWGeneralDatumReference |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | RWStepDimTol_RWGeneralDatumReference::RWStepDimTol_RWGeneralDatumReference () |
33 | { |
34 | } |
35 | |
36 | //======================================================================= |
37 | //function : ReadStep |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | void RWStepDimTol_RWGeneralDatumReference::ReadStep (const Handle(StepData_StepReaderData)& data, |
42 | const Standard_Integer num, |
43 | Handle(Interface_Check)& ach, |
44 | const Handle(StepDimTol_GeneralDatumReference) &ent) const |
45 | { |
46 | // Check number of parameters |
47 | if ( ! data->CheckNbParams(num,6,ach,"general_datum_reference") ) return; |
48 | |
49 | // Inherited fields of ShapeAspect |
50 | |
51 | Handle(TCollection_HAsciiString) aShapeAspect_Name; |
52 | data->ReadString (num, 1, "shape_aspect.name", ach, aShapeAspect_Name); |
53 | |
54 | Handle(TCollection_HAsciiString) aShapeAspect_Description; |
55 | if ( data->IsParamDefined (num,2) ) { |
56 | data->ReadString (num, 2, "shape_aspect.description", ach, aShapeAspect_Description); |
57 | } |
58 | |
59 | Handle(StepRepr_ProductDefinitionShape) aShapeAspect_OfShape; |
60 | data->ReadEntity (num, 3, "shape_aspect.of_shape", ach, STANDARD_TYPE(StepRepr_ProductDefinitionShape), aShapeAspect_OfShape); |
61 | |
62 | StepData_Logical aShapeAspect_ProductDefinitional; |
63 | data->ReadLogical (num, 4, "shape_aspect.product_definitional", ach, aShapeAspect_ProductDefinitional); |
64 | |
65 | // Own fields of GeneralDatumReference |
66 | |
67 | StepDimTol_DatumOrCommonDatum aBase; |
68 | Handle(StepDimTol_Datum) aDatum; |
69 | Interface_ParamType aType = data->ParamType(num, 5); |
70 | if (aType == Interface_ParamIdent) { |
71 | data->ReadEntity(num, 5, "general_datum_reference.base", ach, STANDARD_TYPE(StepDimTol_Datum), aDatum); |
72 | aBase.SetValue(aDatum); |
73 | } |
74 | else { |
75 | Handle(StepDimTol_HArray1OfDatumReferenceElement) anItems; |
76 | Handle(StepDimTol_DatumReferenceElement) anEnt; |
77 | Standard_Integer nbSub; |
78 | if (data->ReadSubList (num,5,"general_datum_reference.base",ach,nbSub)) { |
79 | aType = data->ParamType(nbSub, 1); |
80 | if (aType == Interface_ParamSub) { |
81 | Standard_Integer aNewNbSub; |
82 | if (data->ReadSubList (nbSub,1,"general_datum_reference.base",ach,aNewNbSub)) { |
83 | nbSub = aNewNbSub; |
84 | } |
85 | } |
86 | Standard_Integer nbElements = data->NbParams(nbSub); |
87 | anItems = new StepDimTol_HArray1OfDatumReferenceElement (1, nbElements); |
88 | for (Standard_Integer i = 1; i <= nbElements; i++) { |
89 | if (data->ReadEntity(nbSub, i,"datum_reference_element", ach, STANDARD_TYPE(StepDimTol_DatumReferenceElement), anEnt)) |
90 | anItems->SetValue(i, anEnt); |
91 | } |
92 | } |
93 | aBase.SetValue(anItems); |
94 | } |
95 | |
96 | Standard_Integer nbSub; |
97 | Standard_Boolean hasModifiers = data->ReadSubList(num, 6, "general_datum_reference.modifiers", ach, nbSub, Standard_True); |
98 | Handle(StepDimTol_HArray1OfDatumReferenceModifier) aModifiers; |
99 | if (hasModifiers) { |
100 | StepDimTol_DatumReferenceModifier anEnt; |
101 | Standard_Integer nbElements = data->NbParams(nbSub); |
102 | aModifiers = new StepDimTol_HArray1OfDatumReferenceModifier (1, nbElements); |
103 | for (Standard_Integer i = 1; i <= nbElements; i++) { |
2f220b97 |
104 | aType = data->ParamType (nbSub, i); |
28a73c1f |
105 | if (aType == Interface_ParamIdent) { |
106 | Handle(StepDimTol_DatumReferenceModifierWithValue) aDRMWV; |
107 | data->ReadEntity(nbSub, i,"datum_reference_modifier_with_value", ach, STANDARD_TYPE(StepDimTol_DatumReferenceModifierWithValue), aDRMWV); |
108 | anEnt.SetValue(aDRMWV); |
109 | } |
110 | else { |
111 | Handle(StepData_SelectMember) aMember; |
112 | data->ReadMember(nbSub, i, "simple_datum_reference_modifier", ach, aMember); |
113 | Standard_CString anEnumText = aMember->EnumText(); |
114 | Handle(StepDimTol_SimpleDatumReferenceModifierMember) aSDRM = new StepDimTol_SimpleDatumReferenceModifierMember(); |
115 | aSDRM->SetEnumText(0, anEnumText); |
116 | anEnt.SetValue(aSDRM); |
117 | } |
118 | aModifiers->SetValue(i, anEnt); |
119 | } |
120 | } |
121 | |
122 | // Initialize entity |
123 | ent->Init(aShapeAspect_Name, |
124 | aShapeAspect_Description, |
125 | aShapeAspect_OfShape, |
126 | aShapeAspect_ProductDefinitional, |
127 | aBase, |
128 | hasModifiers, |
129 | aModifiers); |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : WriteStep |
134 | //purpose : |
135 | //======================================================================= |
136 | |
137 | void RWStepDimTol_RWGeneralDatumReference::WriteStep (StepData_StepWriter& SW, |
138 | const Handle(StepDimTol_GeneralDatumReference) &ent) const |
139 | { |
140 | |
141 | // Inherited fields of ShapeAspect |
142 | |
143 | SW.Send (ent->Name()); |
144 | |
145 | SW.Send (ent->Description()); |
146 | |
147 | SW.Send (ent->OfShape()); |
148 | |
149 | SW.SendLogical (ent->ProductDefinitional()); |
150 | |
151 | // Own fields of GeneralDatumReference |
152 | Standard_Integer aBaseType = ent->Base().CaseNum(ent->Base().Value()); |
153 | if (aBaseType == 1) { |
154 | SW.Send(ent->Base().Datum()); |
155 | } |
156 | else if (aBaseType == 2) { |
157 | Handle(StepDimTol_HArray1OfDatumReferenceElement) anArray = ent->Base().CommonDatumList(); |
158 | Standard_Integer i, nb = (anArray.IsNull() ? 0 : anArray->Length()); |
159 | SW.OpenSub(); |
160 | for (i = 1; i <= nb; i++) |
161 | SW.Send (anArray->Value(i)); |
162 | SW.CloseSub(); |
163 | } |
164 | |
165 | if (ent->HasModifiers()) { |
166 | Standard_Integer i, nb = ent->NbModifiers(); |
167 | SW.OpenSub(); |
168 | for (i = 1; i <= nb; i++) { |
169 | StepDimTol_DatumReferenceModifier aModifier = ent->ModifiersValue(i); |
170 | Standard_Integer aType = aModifier.CaseNum(aModifier.Value()); |
171 | switch (aType) { |
172 | case 1: SW.Send(aModifier.DatumReferenceModifierWithValue()); break; |
173 | case 2: SW.SendEnum(aModifier.SimpleDatumReferenceModifierMember()->EnumText());break; |
174 | } |
175 | } |
176 | SW.CloseSub(); |
177 | } |
178 | |
179 | } |
180 | |
181 | //======================================================================= |
182 | //function : Share |
183 | //purpose : |
184 | //======================================================================= |
185 | |
186 | void RWStepDimTol_RWGeneralDatumReference::Share (const Handle(StepDimTol_GeneralDatumReference) &ent, |
187 | Interface_EntityIterator& iter) const |
188 | { |
189 | |
190 | // Inherited fields of ShapeAspect |
191 | |
192 | iter.AddItem (ent->OfShape()); |
193 | |
194 | // Own fields of GeneralDatumReference |
195 | Standard_Integer aBaseType = ent->Base().CaseNum(ent->Base().Value()); |
196 | if (aBaseType == 1) { |
197 | iter.AddItem(ent->Base().Datum()); |
198 | } |
199 | else if (aBaseType == 2) { |
200 | Handle(StepDimTol_HArray1OfDatumReferenceElement) anArray = ent->Base().CommonDatumList(); |
201 | Standard_Integer i, nb = (anArray.IsNull() ? 0 : anArray->Length()); |
202 | for (i = 1; i <= nb; i++) |
203 | iter.AddItem (anArray->Value(i)); |
204 | } |
205 | } |