b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <RWStepBasic_RWSiUnitAndMassUnit.ixx> |
19 | #include <StepBasic_SiUnit.hxx> |
20 | #include <StepBasic_MassUnit.hxx> |
21 | #include <StepBasic_DimensionalExponents.hxx> |
22 | #include <StepBasic_SiPrefix.hxx> |
23 | #include <StepBasic_SiUnitName.hxx> |
24 | #include <RWStepBasic_RWSiUnit.hxx> |
25 | |
26 | |
27 | //======================================================================= |
28 | //function : RWStepBasic_RWSiUnitAndLengthUnit |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | RWStepBasic_RWSiUnitAndMassUnit::RWStepBasic_RWSiUnitAndMassUnit () |
33 | { |
34 | } |
35 | |
36 | |
37 | //======================================================================= |
38 | //function : ReadStep |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | void RWStepBasic_RWSiUnitAndMassUnit::ReadStep(const Handle(StepData_StepReaderData)& data, |
43 | const Standard_Integer num0, |
44 | Handle(Interface_Check)& ach, |
45 | const Handle(StepBasic_SiUnitAndMassUnit)& ent) const |
46 | { |
47 | Standard_Integer num = 0; // num0; |
48 | Standard_Boolean sorted = data->NamedForComplex("MASS_UNIT",num0,num,ach); |
49 | |
50 | // --- Instance of plex componant LengthUnit --- |
51 | if (!data->CheckNbParams(num,0,ach,"mass_unit")) return; |
52 | |
53 | if (!sorted) num = 0; //pdn unsorted case |
54 | sorted &=data->NamedForComplex("NAMED_UNIT NMDUNT",num0,num,ach); |
55 | |
56 | // --- Instance of common supertype NamedUnit --- |
57 | if (!data->CheckNbParams(num,1,ach,"named_unit")) return; |
58 | |
59 | // --- field : dimensions --- |
60 | // --- this field is redefined --- |
61 | //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed |
62 | data->CheckDerived(num,1,"dimensions",ach,Standard_False); |
63 | |
64 | if (!sorted) num = 0; //pdn unsorted case |
65 | data->NamedForComplex("SI_UNIT SUNT",num0,num,ach); |
66 | |
67 | // --- Instance of plex componant SiUnit --- |
68 | if (!data->CheckNbParams(num,2,ach,"si_unit")) return; |
69 | |
70 | // --- field : prefix --- |
71 | RWStepBasic_RWSiUnit reader; |
72 | StepBasic_SiPrefix aPrefix; |
73 | Standard_Boolean hasAprefix = Standard_False; |
74 | if (data->IsParamDefined(num,1)) { |
75 | if (data->ParamType(num,1) == Interface_ParamEnum) { |
76 | Standard_CString text = data->ParamCValue(num,1); |
77 | hasAprefix = reader.DecodePrefix(aPrefix,text); |
78 | if(!hasAprefix) |
79 | ach->AddFail("Enumeration si_prefix has not an allowed value"); |
80 | } |
81 | else ach->AddFail("Parameter #2 (prefix) is not an enumeration"); |
82 | } |
83 | |
84 | // --- field : name --- |
85 | StepBasic_SiUnitName aName; |
86 | if (data->ParamType(num,2) == Interface_ParamEnum) { |
87 | Standard_CString text = data->ParamCValue(num,2); |
88 | if(!reader.DecodeName(aName,text)) |
89 | ach->AddFail("Enumeration si_unit_name has not an allowed value"); |
90 | } |
91 | else ach->AddFail("Parameter #2 (name) is not an enumeration"); |
92 | |
93 | //--- Initialisation of the red entity --- |
94 | ent->Init(hasAprefix,aPrefix,aName); |
95 | } |
96 | |
97 | |
98 | void RWStepBasic_RWSiUnitAndMassUnit::WriteStep(StepData_StepWriter& SW, |
99 | const Handle(StepBasic_SiUnitAndMassUnit)& ent) const |
100 | { |
101 | |
102 | // --- Instance of plex componant LengthUnit --- |
103 | SW.StartEntity("MASS_UNIT"); |
104 | |
105 | // --- Instance of common supertype NamedUnit --- |
106 | SW.StartEntity("NAMED_UNIT"); |
107 | |
108 | // --- field : dimensions --- |
109 | // --- redefined field --- |
110 | SW.SendDerived(); |
111 | |
112 | // --- Instance of plex componant SiUnit --- |
113 | SW.StartEntity("SI_UNIT"); |
114 | |
115 | // --- field : prefix --- |
116 | RWStepBasic_RWSiUnit writer; |
117 | Standard_Boolean hasAprefix = ent->HasPrefix(); |
118 | if (hasAprefix) |
119 | SW.SendEnum(writer.EncodePrefix(ent->Prefix())); |
120 | else |
121 | SW.SendUndef(); |
122 | |
123 | // --- field : name --- |
124 | SW.SendEnum(writer.EncodeName(ent->Name())); |
125 | } |