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