0026715: Problems in reading STEP short names in complex entities
[occt.git] / src / RWStepBasic / RWStepBasic_RWSiUnitAndAreaUnit.cxx
CommitLineData
b311480e 1// Created on: 1999-10-11
2// Created by: data exchange team
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Interface_Check.hxx>
7fd59977 19#include <RWStepBasic_RWSiUnit.hxx>
42cf5bc1 20#include <RWStepBasic_RWSiUnitAndAreaUnit.hxx>
7fd59977 21#include <StepBasic_DimensionalExponents.hxx>
42cf5bc1 22#include <StepBasic_SiUnit.hxx>
23#include <StepBasic_SiUnitAndAreaUnit.hxx>
24#include <StepData_StepReaderData.hxx>
25#include <StepData_StepWriter.hxx>
7fd59977 26
27RWStepBasic_RWSiUnitAndAreaUnit::RWStepBasic_RWSiUnitAndAreaUnit ()
28{
29}
30
31void RWStepBasic_RWSiUnitAndAreaUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
32 const Standard_Integer num0,
33 Handle(Interface_Check)& ach,
34 const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
35{
36 Standard_Integer num = 0;
a7197ef3 37 data->NamedForComplex("AREA_UNIT","ARUNT",num0,num,ach);
7fd59977 38 if (!data->CheckNbParams(num,0,ach,"area_unit")) return;
39
a7197ef3 40 data->NamedForComplex("NAMED_UNIT", "NMDUNT",num0,num,ach);
7fd59977 41 if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
42 Handle(StepBasic_DimensionalExponents) aDimensions;
43 data->ReadEntity(num, 1,"dimensions", ach, STANDARD_TYPE(StepBasic_DimensionalExponents), aDimensions);
44
a7197ef3 45 data->NamedForComplex("SI_UNIT", "SUNT",num0,num,ach);
7fd59977 46 if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
47
48 RWStepBasic_RWSiUnit reader;
1d47d8d0 49 StepBasic_SiPrefix aPrefix = StepBasic_spExa;
7fd59977 50 Standard_Boolean hasAprefix = Standard_False;
51 if (data->IsParamDefined(num,1)) {
52 if (data->ParamType(num,1) == Interface_ParamEnum) {
53 Standard_CString text = data->ParamCValue(num,1);
54 hasAprefix = reader.DecodePrefix(aPrefix,text);
4e76d93b 55 if(!hasAprefix){
56 ach->AddFail("Enumeration si_prefix has not an allowed value");
57 return;
58 }
59 }
60 else{
61 ach->AddFail("Parameter #2 (prefix) is not an enumeration");
62 return;
7fd59977 63 }
7fd59977 64 }
65
66 StepBasic_SiUnitName aName;
67 if (data->ParamType(num,2) == Interface_ParamEnum) {
68 Standard_CString text = data->ParamCValue(num,2);
4e76d93b 69 if(!reader.DecodeName(aName,text)){
7fd59977 70 ach->AddFail("Enumeration si_unit_name has not an allowed value");
4e76d93b 71 return;
72 }
73 }
74 else{
75 ach->AddFail("Parameter #3 (name) is not an enumeration");
76 return;
7fd59977 77 }
7fd59977 78
79 ent->Init(hasAprefix,aPrefix,aName);
80 ent->SetDimensions(aDimensions);
81}
82
83void RWStepBasic_RWSiUnitAndAreaUnit::WriteStep(StepData_StepWriter& SW,
84 const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
85{
86 SW.StartEntity("AREA_UNIT");
87 SW.StartEntity("NAMED_UNIT");
88 SW.Send(ent->Dimensions());
89 SW.StartEntity("SI_UNIT");
90
91 RWStepBasic_RWSiUnit writer;
92 Standard_Boolean hasAprefix = ent->HasPrefix();
93 if (hasAprefix)
94 SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
95 else
96 SW.SendUndef();
97
98 SW.SendEnum(writer.EncodeName(ent->Name()));
99}
100