0026715: Problems in reading STEP short names in complex entities
[occt.git] / src / RWStepBasic / RWStepBasic_RWSiUnitAndMassUnit.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <Interface_Check.hxx>
16#include <RWStepBasic_RWSiUnit.hxx>
17#include <RWStepBasic_RWSiUnitAndMassUnit.hxx>
7fd59977 18#include <StepBasic_DimensionalExponents.hxx>
42cf5bc1 19#include <StepBasic_MassUnit.hxx>
7fd59977 20#include <StepBasic_SiPrefix.hxx>
42cf5bc1 21#include <StepBasic_SiUnit.hxx>
22#include <StepBasic_SiUnitAndMassUnit.hxx>
7fd59977 23#include <StepBasic_SiUnitName.hxx>
42cf5bc1 24#include <StepData_StepReaderData.hxx>
25#include <StepData_StepWriter.hxx>
7fd59977 26
27//=======================================================================
28//function : RWStepBasic_RWSiUnitAndLengthUnit
29//purpose :
30//=======================================================================
7fd59977 31RWStepBasic_RWSiUnitAndMassUnit::RWStepBasic_RWSiUnitAndMassUnit ()
32{
33}
34
35
36//=======================================================================
37//function : ReadStep
38//purpose :
39//=======================================================================
40
41void RWStepBasic_RWSiUnitAndMassUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
42 const Standard_Integer num0,
43 Handle(Interface_Check)& ach,
44 const Handle(StepBasic_SiUnitAndMassUnit)& ent) const
45{
46 Standard_Integer num = 0; // num0;
a7197ef3 47 Standard_Boolean sorted = data->NamedForComplex("MASS_UNIT","MSSUNT",num0,num,ach);
7fd59977 48
49 // --- Instance of plex componant LengthUnit ---
50 if (!data->CheckNbParams(num,0,ach,"mass_unit")) return;
51
52 if (!sorted) num = 0; //pdn unsorted case
a7197ef3 53 sorted &=data->NamedForComplex("NAMED_UNIT", "NMDUNT",num0,num,ach);
7fd59977 54
55 // --- Instance of common supertype NamedUnit ---
56 if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
57
58 // --- field : dimensions ---
59 // --- this field is redefined ---
60 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
61 data->CheckDerived(num,1,"dimensions",ach,Standard_False);
62
63 if (!sorted) num = 0; //pdn unsorted case
a7197ef3 64 data->NamedForComplex("SI_UNIT", "SUNT",num0,num,ach);
7fd59977 65
66 // --- Instance of plex componant SiUnit ---
67 if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
68
69 // --- field : prefix ---
70 RWStepBasic_RWSiUnit reader;
a8195d65 71 StepBasic_SiPrefix aPrefix = StepBasic_spExa;
7fd59977 72 Standard_Boolean hasAprefix = Standard_False;
73 if (data->IsParamDefined(num,1)) {
74 if (data->ParamType(num,1) == Interface_ParamEnum) {
75 Standard_CString text = data->ParamCValue(num,1);
76 hasAprefix = reader.DecodePrefix(aPrefix,text);
4e76d93b 77 if(!hasAprefix){
78 ach->AddFail("Enumeration si_prefix has not an allowed value");
79 return;
80 }
81 }
82 else{
83 ach->AddFail("Parameter #2 (prefix) is not an enumeration");
84 return;
7fd59977 85 }
7fd59977 86 }
87
88 // --- field : name ---
89 StepBasic_SiUnitName aName;
90 if (data->ParamType(num,2) == Interface_ParamEnum) {
91 Standard_CString text = data->ParamCValue(num,2);
4e76d93b 92 if(!reader.DecodeName(aName,text)){
7fd59977 93 ach->AddFail("Enumeration si_unit_name has not an allowed value");
4e76d93b 94 return;
95 }
96 }
97 else{
98 ach->AddFail("Parameter #2 (name) is not an enumeration");
99 return;
7fd59977 100 }
7fd59977 101
102 //--- Initialisation of the red entity ---
103 ent->Init(hasAprefix,aPrefix,aName);
104}
105
106
107void RWStepBasic_RWSiUnitAndMassUnit::WriteStep(StepData_StepWriter& SW,
108 const Handle(StepBasic_SiUnitAndMassUnit)& ent) const
109{
110
111 // --- Instance of plex componant LengthUnit ---
112 SW.StartEntity("MASS_UNIT");
113
114 // --- Instance of common supertype NamedUnit ---
115 SW.StartEntity("NAMED_UNIT");
116
117 // --- field : dimensions ---
118 // --- redefined field ---
119 SW.SendDerived();
120
121 // --- Instance of plex componant SiUnit ---
122 SW.StartEntity("SI_UNIT");
123
124 // --- field : prefix ---
125 RWStepBasic_RWSiUnit writer;
126 Standard_Boolean hasAprefix = ent->HasPrefix();
127 if (hasAprefix)
128 SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
129 else
130 SW.SendUndef();
131
132 // --- field : name ---
133 SW.SendEnum(writer.EncodeName(ent->Name()));
134}