b311480e |
1 | // Created on: 1997-12-10 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Standard_DomainError.hxx> |
19 | #include <Standard_GUID.hxx> |
20 | #include <Standard_Type.hxx> |
21 | #include <TCollection_AsciiString.hxx> |
22 | #include <TCollection_ExtendedString.hxx> |
23 | #include <TDataStd_Expression.hxx> |
24 | #include <TDataStd_Name.hxx> |
25 | #include <TDataStd_Real.hxx> |
26 | #include <TDataStd_Variable.hxx> |
27 | #include <TDF_Attribute.hxx> |
28 | #include <TDF_DataSet.hxx> |
29 | #include <TDF_Label.hxx> |
30 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
31 | |
92efcf78 |
32 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Variable,TDF_Attribute) |
33 | |
7fd59977 |
34 | //======================================================================= |
35 | //function : GetID |
36 | //purpose : |
37 | //======================================================================= |
7fd59977 |
38 | const Standard_GUID& TDataStd_Variable::GetID() |
39 | { |
40 | static Standard_GUID TDataStd_VariableID("ce241469-8e57-11d1-8953-080009dc4425"); |
41 | return TDataStd_VariableID; |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Set |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | Handle(TDataStd_Variable) TDataStd_Variable::Set(const TDF_Label& L) |
50 | { |
51 | Handle(TDataStd_Variable) A; |
52 | if (!L.FindAttribute (TDataStd_Variable::GetID(), A)) { |
53 | A = new TDataStd_Variable (); |
54 | L.AddAttribute(A); |
55 | } |
56 | return A; |
57 | } |
58 | |
59 | //======================================================================= |
60 | //function : TDataStd_Variable |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | TDataStd_Variable::TDataStd_Variable() |
65 | :isConstant(Standard_False), |
66 | myUnit("SCALAR") |
67 | { |
68 | } |
69 | |
70 | //======================================================================= |
71 | //function : Name |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | void TDataStd_Variable::Name (const TCollection_ExtendedString& string) |
76 | { |
77 | TDataStd_Name::Set(Label(),string); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Name |
82 | //purpose : |
83 | //======================================================================= |
84 | const TCollection_ExtendedString& TDataStd_Variable::Name () const |
85 | { |
86 | Handle(TDataStd_Name) N; |
87 | if (!Label().FindAttribute(TDataStd_Name::GetID(),N)) { |
9775fa61 |
88 | throw Standard_DomainError("TDataStd_Variable::Name : invalid model"); |
7fd59977 |
89 | } |
90 | return N->Get(); |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : IsValued |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | Standard_Boolean TDataStd_Variable::IsValued () const |
99 | { |
100 | return (Label().IsAttribute (TDataStd_Real::GetID())); |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : Real |
105 | //purpose : |
106 | //======================================================================= |
107 | |
108 | Handle(TDataStd_Real) TDataStd_Variable::Real() const |
109 | { |
110 | Handle(TDataStd_Real) R; |
111 | if (!Label().FindAttribute(TDataStd_Real::GetID(),R)) { |
9775fa61 |
112 | throw Standard_DomainError("TDataStd_Variable::Real : invalid model"); |
7fd59977 |
113 | } |
114 | return R; |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : Set |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void TDataStd_Variable::Set (const Standard_Real value, const TDataStd_RealEnum dimension) const |
123 | { |
124 | if (!IsValued()) { |
125 | Handle(TDataStd_Real) R = TDataStd_Real::Set(Label(),value); |
126 | R->SetDimension (dimension); |
127 | } |
128 | else { |
129 | Handle(TDataStd_Real) R = TDataStd_Real::Set(Label(),value); |
130 | } |
131 | } |
132 | |
133 | |
134 | //======================================================================= |
135 | //function : Get |
136 | //purpose : |
137 | //======================================================================= |
138 | |
139 | Standard_Real TDataStd_Variable::Get () const |
140 | { |
141 | Handle(TDataStd_Real) R; |
142 | if (!Label().FindAttribute(TDataStd_Real::GetID(),R)) { |
9775fa61 |
143 | throw Standard_DomainError("TDataStd_Variable::Get : invalid model"); |
7fd59977 |
144 | } |
145 | return R->Get(); |
146 | } |
147 | |
148 | |
149 | |
150 | //======================================================================= |
151 | //function : IsAssigned |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | Standard_Boolean TDataStd_Variable::IsAssigned () const |
156 | { |
157 | return (Label().IsAttribute(TDataStd_Expression::GetID())); |
158 | } |
159 | |
160 | //======================================================================= |
161 | //function : Assign |
162 | //purpose : |
163 | //======================================================================= |
164 | |
165 | Handle(TDataStd_Expression) TDataStd_Variable::Assign () const |
166 | { |
167 | Handle(TDataStd_Expression) E = TDataStd_Expression::Set(Label()); |
168 | return E; |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : Desassign |
173 | //purpose : |
174 | //======================================================================= |
175 | |
176 | void TDataStd_Variable::Desassign () const |
177 | { |
178 | Handle(TDataStd_Expression) E; |
179 | if (!Label().FindAttribute(TDataStd_Expression::GetID(),E)) { |
9775fa61 |
180 | throw Standard_DomainError("TDataStd_Variable::Deassign"); |
7fd59977 |
181 | } |
182 | Label().ForgetAttribute(E); |
183 | } |
184 | |
185 | //======================================================================= |
186 | //function : Expression |
187 | //purpose : |
188 | //======================================================================= |
189 | |
190 | Handle(TDataStd_Expression) TDataStd_Variable::Expression () const |
191 | { |
192 | Handle(TDataStd_Expression) E; |
193 | if (!Label().FindAttribute(TDataStd_Expression::GetID(),E)) { |
9775fa61 |
194 | throw Standard_DomainError("TDataStd_Variable::GetExpression"); |
7fd59977 |
195 | } |
196 | return E; |
197 | } |
198 | |
199 | //======================================================================= |
200 | //function : IsCaptured |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | Standard_Boolean TDataStd_Variable::IsCaptured() const |
205 | { |
206 | return Real()->IsCaptured(); |
207 | } |
208 | |
209 | //======================================================================= |
210 | //function : IsConstant |
211 | //purpose : |
212 | //======================================================================= |
213 | |
214 | Standard_Boolean TDataStd_Variable::IsConstant () const |
215 | { |
216 | return isConstant; |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : Constant |
221 | //purpose : |
222 | //======================================================================= |
223 | |
224 | void TDataStd_Variable::Constant (const Standard_Boolean status) |
225 | { |
226 | // OCC2932 correction |
227 | if(isConstant == status) return; |
228 | |
229 | Backup(); |
230 | isConstant = status; |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : Unit |
235 | //purpose : |
236 | //======================================================================= |
237 | void TDataStd_Variable::Unit(const TCollection_AsciiString& unit) |
238 | { |
239 | // OCC2932 correction |
240 | if(myUnit == unit) |
241 | return; |
242 | |
243 | Backup(); |
244 | myUnit = unit; |
245 | } |
246 | //======================================================================= |
247 | //function : Unit |
248 | //purpose : |
249 | //======================================================================= |
250 | const TCollection_AsciiString& TDataStd_Variable::Unit() const |
251 | { |
252 | return myUnit; |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : ID |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | const Standard_GUID& TDataStd_Variable::ID() const |
261 | { |
262 | return GetID(); |
263 | } |
264 | |
265 | //======================================================================= |
266 | //function : Restore |
267 | //purpose : |
268 | //======================================================================= |
269 | |
270 | void TDataStd_Variable::Restore (const Handle(TDF_Attribute)& With) |
271 | { |
272 | Handle(TDataStd_Variable) V = Handle(TDataStd_Variable)::DownCast (With); |
273 | isConstant = V->IsConstant(); |
274 | myUnit = V->Unit(); |
275 | } |
276 | |
277 | //======================================================================= |
278 | //function : NewEmpty |
279 | //purpose : |
280 | //======================================================================= |
281 | |
282 | Handle(TDF_Attribute) TDataStd_Variable::NewEmpty() const |
283 | { |
284 | return new TDataStd_Variable(); |
285 | } |
286 | |
287 | //======================================================================= |
288 | //function : Paste |
289 | //purpose : |
290 | //======================================================================= |
291 | |
292 | void TDataStd_Variable::Paste (const Handle(TDF_Attribute)& Into, |
293 | const Handle(TDF_RelocationTable)& /*RT*/) const |
294 | { |
295 | Handle(TDataStd_Variable) V = Handle(TDataStd_Variable)::DownCast (Into); |
296 | V->Constant(isConstant); |
297 | V->Unit(myUnit); |
298 | } |
299 | |
300 | |
301 | //======================================================================= |
302 | //function : References |
303 | //purpose : |
304 | //======================================================================= |
305 | |
306 | void TDataStd_Variable::References(const Handle(TDF_DataSet)& DS) const |
307 | { |
308 | Handle(TDataStd_Name) N; |
309 | if (Label().FindAttribute(TDataStd_Name::GetID(),N)) { |
310 | DS->AddAttribute(N); |
311 | } |
312 | } |
313 | |
314 | //======================================================================= |
315 | //function : Dump |
316 | //purpose : |
317 | //======================================================================= |
318 | |
319 | Standard_OStream& TDataStd_Variable::Dump(Standard_OStream& anOS) const |
320 | { |
321 | anOS << "Variable"; |
322 | return anOS; |
323 | } |
324 | |