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