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 <Interface_Macros.hxx>
16 #include <Standard_Transient.hxx>
17 #include <Standard_TypeMismatch.hxx>
18 #include <StepData_PDescr.hxx>
19 #include <StepData_SelectInt.hxx>
20 #include <StepData_SelectMember.hxx>
21 #include <StepData_SelectNamed.hxx>
22 #include <StepData_SelectReal.hxx>
23 #include <StepData_SelectType.hxx>
24 #include <StepData_UndefinedEntity.hxx>
25
26
Matches(const Handle (Standard_Transient)& ent) const27 Standard_Boolean StepData_SelectType::Matches
28 (const Handle(Standard_Transient)& ent) const
29 {
30 if (CaseNum(ent) > 0) return Standard_True;
31 DeclareAndCast(StepData_SelectMember,sm,ent);
32 if (sm.IsNull()) return Standard_False;
33 if (CaseMem(sm) > 0) return Standard_True;
34 return Standard_False;
35 }
36
SetValue(const Handle (Standard_Transient)& ent)37 void StepData_SelectType::SetValue (const Handle(Standard_Transient)& ent)
38 {
39 if (ent.IsNull()) thevalue.Nullify();
40 else if (ent->IsKind(STANDARD_TYPE(StepData_UndefinedEntity)))
41 thevalue = ent;
42 else if (!Matches(ent))
43 throw Standard_TypeMismatch("StepData : SelectType, SetValue");
44 else thevalue = ent;
45 }
46
Nullify()47 void StepData_SelectType::Nullify ()
48 { thevalue.Nullify(); }
49
Handle(Standard_Transient)50 const Handle(Standard_Transient)& StepData_SelectType::Value () const
51 { return thevalue; }
52
IsNull() const53 Standard_Boolean StepData_SelectType::IsNull () const
54 { return thevalue.IsNull(); }
55
Handle(Standard_Type)56 Handle(Standard_Type) StepData_SelectType::Type () const
57 {
58 if (thevalue.IsNull()) return STANDARD_TYPE(Standard_Transient);
59 return thevalue->DynamicType();
60 }
61
CaseNumber() const62 Standard_Integer StepData_SelectType::CaseNumber () const
63 { if (thevalue.IsNull()) return 0; return CaseNum(thevalue); }
64
65
66 // ********** Types Immediats ***********
67
Handle(StepData_PDescr)68 Handle(StepData_PDescr) StepData_SelectType::Description () const
69 { Handle(StepData_PDescr) nuldescr; return nuldescr; }
70
Handle(StepData_SelectMember)71 Handle(StepData_SelectMember) StepData_SelectType::NewMember () const
72 { Handle(StepData_SelectMember) nulmem; return nulmem; }
73
CaseMem(const Handle (StepData_SelectMember)&) const74 Standard_Integer StepData_SelectType::CaseMem (const Handle(StepData_SelectMember)& /*ent*/) const
75 { return 0; }
76
CaseMember() const77 Standard_Integer StepData_SelectType::CaseMember () const
78 {
79 DeclareAndCast(StepData_SelectMember,sm,thevalue);
80 if (sm.IsNull()) return 0;
81 return CaseMem (sm);
82 }
83
Handle(StepData_SelectMember)84 Handle(StepData_SelectMember) StepData_SelectType::Member () const
85 { return GetCasted(StepData_SelectMember,thevalue); }
86
SelectName() const87 Standard_CString StepData_SelectType::SelectName () const
88 {
89 DeclareAndCast(StepData_SelectMember,sm,thevalue);
90 if (sm.IsNull()) return "";
91 return sm->Name();
92 }
93
Int() const94 Standard_Integer StepData_SelectType::Int () const
95 {
96 DeclareAndCast(StepData_SelectMember,sm,thevalue);
97 if (sm.IsNull()) return 0;
98 return sm->Int();
99 }
100
SetInt(const Standard_Integer val)101 void StepData_SelectType::SetInt (const Standard_Integer val)
102 {
103 DeclareAndCast(StepData_SelectMember,sm,thevalue);
104 if (sm.IsNull()) throw Standard_TypeMismatch("StepData : SelectType, SetInt");
105 sm->SetInt (val);
106 }
107
108 // ********** Types Immediats : Differents Cas ***********
109
SelectVal(const Handle (Standard_Transient)& thevalue,const Standard_CString name,const int mode)110 static Handle(StepData_SelectMember) SelectVal
111 (const Handle(Standard_Transient)& thevalue, const Standard_CString name,
112 const int mode)
113 {
114 DeclareAndCast(StepData_SelectMember,sm,thevalue);
115 if (!sm.IsNull()) {
116 if (name && name[0] != '\0')
117 if (!sm->SetName(name)) throw Standard_TypeMismatch("StepData : SelectType, SetInteger");
118 }
119 else if (name && name[0] != '\0') {
120 Handle(StepData_SelectNamed) sn = new StepData_SelectNamed;
121 sn->SetName (name);
122 sm = sn;
123 } else {
124 if (mode == 0) sm = new StepData_SelectInt;
125 if (mode == 1) sm = new StepData_SelectReal;
126 }
127 return sm;
128 }
129
130
Integer() const131 Standard_Integer StepData_SelectType::Integer () const
132 {
133 DeclareAndCast(StepData_SelectMember,sm,thevalue);
134 if (sm.IsNull()) return 0;
135 return sm->Integer();
136 }
137
SetInteger(const Standard_Integer val,const Standard_CString name)138 void StepData_SelectType::SetInteger
139 (const Standard_Integer val, const Standard_CString name)
140 {
141 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
142 sm->SetInteger (val);
143 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetInteger");
144 thevalue = sm;
145 }
146
Boolean() const147 Standard_Boolean StepData_SelectType::Boolean () const
148 {
149 DeclareAndCast(StepData_SelectMember,sm,thevalue);
150 if (sm.IsNull()) return Standard_False;
151 return sm->Boolean();
152 }
153
SetBoolean(const Standard_Boolean val,const Standard_CString name)154 void StepData_SelectType::SetBoolean
155 (const Standard_Boolean val, const Standard_CString name)
156 {
157 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
158 sm->SetBoolean (val);
159 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetBoolean");
160 thevalue = sm;
161 }
162
Logical() const163 StepData_Logical StepData_SelectType::Logical () const
164 {
165 DeclareAndCast(StepData_SelectMember,sm,thevalue);
166 if (sm.IsNull()) return StepData_LUnknown;
167 return sm->Logical();
168 }
169
SetLogical(const StepData_Logical val,const Standard_CString name)170 void StepData_SelectType::SetLogical
171 (const StepData_Logical val, const Standard_CString name)
172 {
173 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,0);
174 sm->SetLogical (val);
175 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetLogical");
176 thevalue = sm;
177 }
178
Real() const179 Standard_Real StepData_SelectType::Real () const
180 {
181 DeclareAndCast(StepData_SelectMember,sm,thevalue);
182 if (sm.IsNull()) return 0.0;
183 return sm->Real();
184 }
185
SetReal(const Standard_Real val,const Standard_CString name)186 void StepData_SelectType::SetReal
187 (const Standard_Real val, const Standard_CString name)
188 {
189 Handle(StepData_SelectMember) sm = SelectVal (thevalue,name,1);
190 sm->SetReal (val);
191 if (CaseMem (sm) == 0) throw Standard_TypeMismatch("StepData : SelectType, SetReal");
192 thevalue = sm;
193 }
194
~StepData_SelectType()195 StepData_SelectType::~StepData_SelectType()
196 {}
197