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