0026715: Problems in reading STEP short names in complex entities
[occt.git] / src / RWStepShape / RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem.cxx
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
15 #include <Interface_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem.hxx>
18 #include <StepBasic_MeasureValueMember.hxx>
19 #include <StepBasic_MeasureWithUnit.hxx>
20 #include <StepBasic_Unit.hxx>
21 #include <StepData_StepReaderData.hxx>
22 #include <StepData_StepWriter.hxx>
23 #include <StepShape_HArray1OfValueQualifier.hxx>
24 #include <StepShape_MeasureRepresentationItemAndQualifiedRepresentationItem.hxx>
25 #include <StepShape_ValueQualifier.hxx>
26
27 RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem::RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem () {}
28
29 void RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem::ReadStep
30         (const Handle(StepData_StepReaderData)& data,
31          const Standard_Integer num0,
32          Handle(Interface_Check)& ach,
33          const Handle(StepShape_MeasureRepresentationItemAndQualifiedRepresentationItem)& ent) const
34 {
35
36 //  Complex Entity : MeasureReprItem + QualifiedreprItem : so, add ReprItem
37
38   //  --- Instance of plex componant : MeasureReprItem
39
40   Standard_Integer num = 0;
41   data->NamedForComplex("MEASURE_REPRESENTATION_ITEM","MSRPIT",num0,num,ach);
42
43   // --- Number of Parameter Control ---
44
45   if (!data->CheckNbParams(num,2,ach,"measure_representation_item")) return;
46
47   // --- inherited from measure_with_unit : value_component ---
48   Handle(StepBasic_MeasureValueMember) mvc = new StepBasic_MeasureValueMember;
49   data->ReadMember (num, 1, "value_component", ach, mvc);
50
51   // --- inherited from measure_with_unit : unit_component ---
52   StepBasic_Unit aUnitComponent;
53   data->ReadEntity (num, 2, "unit_component", ach, aUnitComponent);
54
55
56   //  --- Instance of plex componant : QualifiedReprItem
57
58   data->NamedForComplex("QUALIFIED_REPRESENTATION_ITEM","QLRPIT",num0,num,ach);
59
60   // --- Number of Parameter Control ---
61
62   if (!data->CheckNbParams(num,1,ach,"qualified_representation_item")) return;
63
64   // --- own field : qualifiers ---
65
66   Handle(StepShape_HArray1OfValueQualifier) quals;
67   Standard_Integer nsub1;
68   if (data->ReadSubList (num,1,"qualifiers",ach,nsub1)) {
69     Standard_Integer nb1 = data->NbParams(nsub1);
70     quals = new StepShape_HArray1OfValueQualifier (1,nb1);
71     for (Standard_Integer i1 = 1; i1 <= nb1; i1 ++) {
72       StepShape_ValueQualifier VQ;
73       if (data->ReadEntity (nsub1,i1,"qualifier",ach,VQ))
74         quals->SetValue (i1,VQ);
75     }
76   }
77
78
79   //  --- Instance of plex componant : RepresentationItem
80
81   data->NamedForComplex("REPRESENTATION_ITEM","RPRITM",num0,num,ach);
82
83   if (!data->CheckNbParams(num,1,ach,"representation_item")) return;
84
85   // --- inherited field from this component : name ---
86
87   Handle(TCollection_HAsciiString) aName;
88   data->ReadString (num,1,"name",ach,aName);
89
90   //--- Initialisation of the read entity ---
91
92   ent->Init(aName, mvc,aUnitComponent,quals);
93 }
94
95
96 void RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem::WriteStep
97         (StepData_StepWriter& SW,
98          const Handle(StepShape_MeasureRepresentationItemAndQualifiedRepresentationItem)& ent) const
99 {
100 //  Complex Entity : MeasureReprItem + QualifiedreprItem : so, add ReprItem
101
102   //  --- Instance of plex componant : MeasureReprItem
103
104   SW.StartEntity ("MEASURE_REPRESENTATION_ITEM");
105
106   // --- inherited from measure_with_unit : value_component ---
107   SW.Send(ent->Measure()->ValueComponentMember());
108   
109   // --- inherited from measure_with_unit : unit_component ---
110   SW.Send(ent->Measure()->UnitComponent().Value());
111
112   //  --- Instance of plex componant : QualifiedReprItem
113
114   SW.StartEntity ("QUALIFIED_REPRESENTATION_ITEM");
115
116   // --- own field : qualifiers ---
117   Standard_Integer i, nbq = ent->NbQualifiers();
118   SW.OpenSub();
119   for (i = 1; i <= nbq; i ++) SW.Send (ent->QualifiersValue(i).Value());
120   SW.CloseSub();
121
122   //  --- Instance of plex componant : ReprsentationItem
123
124   SW.StartEntity ("REPRESENTATION_ITEM");
125
126   // --- inherited field name ---
127
128   SW.Send(ent->Name());
129 }
130
131
132 void RWStepShape_RWMeasureRepresentationItemAndQualifiedRepresentationItem::Share(const Handle(StepShape_MeasureRepresentationItemAndQualifiedRepresentationItem)& ent, Interface_EntityIterator& iter) const
133 {
134   iter.AddItem(ent->Measure()->UnitComponent().Value());
135
136   Standard_Integer i, nbq = ent->NbQualifiers();
137   for (i = 1; i <= nbq; i ++) iter.AddItem (ent->QualifiersValue(i).Value());
138 }
139