0026715: Problems in reading STEP short names in complex entities
[occt.git] / src / RWStepBasic / RWStepBasic_RWSiUnitAndVolumeUnit.cxx
CommitLineData
b311480e 1// Created on: 1999-10-12
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_RWSiUnitAndVolumeUnit.hxx>
ec357c5c 21#include <StepBasic_DimensionalExponents.hxx>
42cf5bc1 22#include <StepBasic_SiUnit.hxx>
23#include <StepBasic_SiUnitAndVolumeUnit.hxx>
24#include <StepData_StepReaderData.hxx>
25#include <StepData_StepWriter.hxx>
7fd59977 26
27RWStepBasic_RWSiUnitAndVolumeUnit::RWStepBasic_RWSiUnitAndVolumeUnit()
28{
29}
30
31void RWStepBasic_RWSiUnitAndVolumeUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
32 const Standard_Integer num0,
33 Handle(Interface_Check)& ach,
34 const Handle(StepBasic_SiUnitAndVolumeUnit)& ent) const
35{
36 Standard_Integer num = 0;
a7197ef3 37 data->NamedForComplex("NAMED_UNIT", "NMDUNT",num0,num,ach);
7fd59977 38 if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
39 Handle(StepBasic_DimensionalExponents) aDimensions;
40 data->ReadEntity(num, 1,"dimensions", ach, STANDARD_TYPE(StepBasic_DimensionalExponents), aDimensions);
41
a7197ef3 42 data->NamedForComplex("SI_UNIT", "SUNT",num0,num,ach);
7fd59977 43 if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
44
45 RWStepBasic_RWSiUnit reader;
1d47d8d0 46 StepBasic_SiPrefix aPrefix = StepBasic_spExa;
7fd59977 47 Standard_Boolean hasAprefix = Standard_False;
48 if (data->IsParamDefined(num,1)) {
49 if (data->ParamType(num,1) == Interface_ParamEnum) {
50 Standard_CString text = data->ParamCValue(num,1);
51 hasAprefix = reader.DecodePrefix(aPrefix,text);
4e76d93b 52 if(!hasAprefix){
53 ach->AddFail("Enumeration si_prefix has not an allowed value");
54 return;
55 }
56 }
57 else{
58 ach->AddFail("Parameter #2 (prefix) is not an enumeration");
59 return;
7fd59977 60 }
7fd59977 61 }
62
63 StepBasic_SiUnitName aName;
64 if (data->ParamType(num,2) == Interface_ParamEnum) {
65 Standard_CString text = data->ParamCValue(num,2);
4e76d93b 66 if(!reader.DecodeName(aName,text)){
7fd59977 67 ach->AddFail("Enumeration si_unit_name has not an allowed value");
4e76d93b 68 return;
69 }
70 }
71 else{
72 ach->AddFail("Parameter #3 (name) is not an enumeration");
73 return;
7fd59977 74 }
7fd59977 75
a7197ef3 76 data->NamedForComplex("VOLUME_UNIT","VLMUNT",num0,num,ach);
7fd59977 77 if (!data->CheckNbParams(num,0,ach,"volume_unit")) return;
78
79 ent->Init(hasAprefix,aPrefix,aName);
80 ent->SetDimensions(aDimensions);
81}
82
83void RWStepBasic_RWSiUnitAndVolumeUnit::WriteStep(StepData_StepWriter& SW,
84 const Handle(StepBasic_SiUnitAndVolumeUnit)& ent) const
85{
86 SW.StartEntity("NAMED_UNIT");
87 SW.Send(ent->Dimensions());
88 SW.StartEntity("SI_UNIT");
89
90 RWStepBasic_RWSiUnit writer;
91 Standard_Boolean hasAprefix = ent->HasPrefix();
92 if (hasAprefix)
93 SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
94 else
95 SW.SendUndef();
96
97 SW.SendEnum(writer.EncodeName(ent->Name()));
98 SW.StartEntity("VOLUME_UNIT");
99}
100
101