0023132: Suspicious code snippets
[occt.git] / src / RWStepBasic / RWStepBasic_RWSiUnitAndAreaUnit.cxx
1 // Created on: 1999-10-11
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <RWStepBasic_RWSiUnitAndAreaUnit.ixx>
24 #include <StepBasic_SiUnit.hxx>
25 #include <RWStepBasic_RWSiUnit.hxx>
26 #include <StepBasic_DimensionalExponents.hxx>
27
28
29 RWStepBasic_RWSiUnitAndAreaUnit::RWStepBasic_RWSiUnitAndAreaUnit ()
30 {
31 }
32
33 void RWStepBasic_RWSiUnitAndAreaUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
34                                                const Standard_Integer num0,
35                                                Handle(Interface_Check)& ach,
36                                                const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
37 {
38   Standard_Integer num = 0;
39   data->NamedForComplex("AREA_UNIT",num0,num,ach);
40   if (!data->CheckNbParams(num,0,ach,"area_unit")) return;
41
42   data->NamedForComplex("NAMED_UNIT NMDUNT",num0,num,ach);
43   if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
44   Handle(StepBasic_DimensionalExponents) aDimensions;
45   data->ReadEntity(num, 1,"dimensions", ach, STANDARD_TYPE(StepBasic_DimensionalExponents), aDimensions);
46   
47   data->NamedForComplex("SI_UNIT SUNT",num0,num,ach);
48   if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
49   
50   RWStepBasic_RWSiUnit reader;
51   StepBasic_SiPrefix aPrefix;
52   Standard_Boolean hasAprefix = Standard_False;
53   if (data->IsParamDefined(num,1)) {
54     if (data->ParamType(num,1) == Interface_ParamEnum) {
55       Standard_CString text = data->ParamCValue(num,1);
56       hasAprefix = reader.DecodePrefix(aPrefix,text);
57       if(!hasAprefix){
58               ach->AddFail("Enumeration si_prefix has not an allowed value");
59         return;
60       }
61     }
62     else{
63       ach->AddFail("Parameter #2 (prefix) is not an enumeration");
64       return;
65     }
66   }
67      
68   StepBasic_SiUnitName aName;
69   if (data->ParamType(num,2) == Interface_ParamEnum) {
70     Standard_CString text = data->ParamCValue(num,2);
71     if(!reader.DecodeName(aName,text)){
72       ach->AddFail("Enumeration si_unit_name has not an allowed value");
73       return;
74     }
75   }
76   else{
77     ach->AddFail("Parameter #3 (name) is not an enumeration");
78     return;
79   }
80   
81   ent->Init(hasAprefix,aPrefix,aName);
82   ent->SetDimensions(aDimensions);
83 }
84
85 void RWStepBasic_RWSiUnitAndAreaUnit::WriteStep(StepData_StepWriter& SW,
86                                                 const Handle(StepBasic_SiUnitAndAreaUnit)& ent) const
87 {
88   SW.StartEntity("AREA_UNIT");
89   SW.StartEntity("NAMED_UNIT");
90   SW.Send(ent->Dimensions());
91   SW.StartEntity("SI_UNIT");
92   
93   RWStepBasic_RWSiUnit writer;
94   Standard_Boolean hasAprefix = ent->HasPrefix();
95   if (hasAprefix) 
96     SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
97   else
98     SW.SendUndef();
99   
100   SW.SendEnum(writer.EncodeName(ent->Name()));   
101 }
102