0033018: Coding - get rid of unused headers [Plugin to ShapeAnalysis]
[occt.git] / src / RWStepBasic / RWStepBasic_RWSiUnitAndRatioUnit.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <RWStepBasic_RWSiUnit.hxx>
16 #include <RWStepBasic_RWSiUnitAndRatioUnit.hxx>
17 #include <StepBasic_DimensionalExponents.hxx>
18 #include <StepBasic_SiPrefix.hxx>
19 #include <StepBasic_SiUnitAndRatioUnit.hxx>
20 #include <StepBasic_SiUnitName.hxx>
21 #include <StepData_StepReaderData.hxx>
22 #include <StepData_StepWriter.hxx>
23
24 RWStepBasic_RWSiUnitAndRatioUnit::RWStepBasic_RWSiUnitAndRatioUnit () {}
25
26 void RWStepBasic_RWSiUnitAndRatioUnit::ReadStep (const Handle(StepData_StepReaderData)& data,
27                                                  const Standard_Integer num0,
28                                                  Handle(Interface_Check)& ach,
29                                                  const Handle(StepBasic_SiUnitAndRatioUnit)& ent) const
30 {
31   
32   Standard_Integer num = num0;
33
34   // --- Instance of common supertype NamedUnit ---
35   if (!data->CheckNbParams(num,1,ach,"named_unit")) return;
36
37   // --- field : dimensions ---
38   // --- this field is redefined ---
39   //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
40   data->CheckDerived(num,1,"dimensions",ach,Standard_False);
41
42   // --- Instance of plex component RatioUnit ---
43   num = data->NextForComplex(num);
44   if (!data->CheckNbParams(num,0,ach,"ratio_unit")) return;
45
46   // --- Instance of plex component SiUnit ---
47   num = data->NextForComplex(num);
48   if (!data->CheckNbParams(num,2,ach,"si_unit")) return;
49
50   // --- field : prefix ---
51   RWStepBasic_RWSiUnit reader;
52   StepBasic_SiPrefix aPrefix = StepBasic_spExa;
53   Standard_Boolean hasAprefix = Standard_False;
54   if (data->IsParamDefined(num,1)) {
55     if (data->ParamType(num,1) == Interface_ParamEnum) {
56       Standard_CString text = data->ParamCValue(num,1);
57       hasAprefix = reader.DecodePrefix(aPrefix,text);
58       if(!hasAprefix){
59               ach->AddFail("Enumeration si_prefix has not an allowed value");
60         return;
61       }
62     }
63     else{
64       ach->AddFail("Parameter #1 (prefix) is not an enumeration");
65       return;
66     }
67   }
68
69   // --- field : name ---
70   StepBasic_SiUnitName aName;
71   if (data->ParamType(num,2) == Interface_ParamEnum) {
72     Standard_CString text = data->ParamCValue(num,2);
73     if(!reader.DecodeName(aName,text)){
74       ach->AddFail("Enumeration si_unit_name has not an allowed value");
75       return;
76     }
77   }
78   else{
79     ach->AddFail("Parameter #2 (name) is not an enumeration");
80     return;
81   }
82   
83   //--- Initialisation of the red entity ---
84   ent->Init(hasAprefix,aPrefix,aName);
85 }
86
87
88 void RWStepBasic_RWSiUnitAndRatioUnit::WriteStep(StepData_StepWriter& SW,
89                                                  const Handle(StepBasic_SiUnitAndRatioUnit)& ent) const
90 {
91   
92   // --- Instance of plex component RatioUnit ---
93   SW.StartEntity("RATIO_UNIT");
94
95   // --- Instance of common supertype NamedUnit ---
96   SW.StartEntity("NAMED_UNIT");
97   // --- field : dimensions ---
98   // --- redefined field ---
99   SW.SendDerived();
100
101   // --- Instance of plex component SiUnit ---
102   SW.StartEntity("SI_UNIT");
103   
104   // --- field : prefix ---
105   RWStepBasic_RWSiUnit writer;
106   Standard_Boolean hasAprefix = ent->HasPrefix();
107   if (hasAprefix) 
108     SW.SendEnum(writer.EncodePrefix(ent->Prefix()));
109   else
110     SW.SendUndef();
111
112   // --- field : name ---
113   SW.SendEnum(writer.EncodeName(ent->Name()));
114 }