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