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