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