0024023: Revamp the OCCT Handle -- ambiguity
[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
17#include <RWStepBasic_RWSiUnitAndAreaUnit.ixx>
18#include <StepBasic_SiUnit.hxx>
19#include <RWStepBasic_RWSiUnit.hxx>
20#include <StepBasic_DimensionalExponents.hxx>
21
22
23RWStepBasic_RWSiUnitAndAreaUnit::RWStepBasic_RWSiUnitAndAreaUnit ()
24{
25}
26
27void RWStepBasic_RWSiUnitAndAreaUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
28 const Standard_Integer num0,
29 Handle(Interface_Check)& ach,
30 const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
31{
32 Standard_Integer num = 0;
33 data->NamedForComplex("AREA_UNIT",num0,num,ach);
34 if (!data->CheckNbParams(num,0,ach,"area_unit")) return;
35
36 data->NamedForComplex("NAMED_UNIT NMDUNT",num0,num,ach);
37 if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
38 Handle(StepBasic_DimensionalExponents) aDimensions;
39 data->ReadEntity(num, 1,"dimensions", ach, STANDARD_TYPE(StepBasic_DimensionalExponents), aDimensions);
40
41 data->NamedForComplex("SI_UNIT SUNT",num0,num,ach);
42 if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
43
44 RWStepBasic_RWSiUnit reader;
1d47d8d0 45 StepBasic_SiPrefix aPrefix = StepBasic_spExa;
7fd59977 46 Standard_Boolean hasAprefix = Standard_False;
47 if (data->IsParamDefined(num,1)) {
48 if (data->ParamType(num,1) == Interface_ParamEnum) {
49 Standard_CString text = data->ParamCValue(num,1);
50 hasAprefix = reader.DecodePrefix(aPrefix,text);
4e76d93b 51 if(!hasAprefix){
52 ach->AddFail("Enumeration si_prefix has not an allowed value");
53 return;
54 }
55 }
56 else{
57 ach->AddFail("Parameter #2 (prefix) is not an enumeration");
58 return;
7fd59977 59 }
7fd59977 60 }
61
62 StepBasic_SiUnitName aName;
63 if (data->ParamType(num,2) == Interface_ParamEnum) {
64 Standard_CString text = data->ParamCValue(num,2);
4e76d93b 65 if(!reader.DecodeName(aName,text)){
7fd59977 66 ach->AddFail("Enumeration si_unit_name has not an allowed value");
4e76d93b 67 return;
68 }
69 }
70 else{
71 ach->AddFail("Parameter #3 (name) is not an enumeration");
72 return;
7fd59977 73 }
7fd59977 74
75 ent->Init(hasAprefix,aPrefix,aName);
76 ent->SetDimensions(aDimensions);
77}
78
79void RWStepBasic_RWSiUnitAndAreaUnit::WriteStep(StepData_StepWriter& SW,
80 const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
81{
82 SW.StartEntity("AREA_UNIT");
83 SW.StartEntity("NAMED_UNIT");
84 SW.Send(ent->Dimensions());
85 SW.StartEntity("SI_UNIT");
86
87 RWStepBasic_RWSiUnit writer;
88 Standard_Boolean hasAprefix = ent->HasPrefix();
89 if (hasAprefix)
90 SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
91 else
92 SW.SendUndef();
93
94 SW.SendEnum(writer.EncodeName(ent->Name()));
95}
96