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