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 | |
bc73b006 |
17 | #include <TDataStd_Variable.hxx> |
7fd59977 |
18 | |
42cf5bc1 |
19 | #include <Standard_DomainError.hxx> |
bc73b006 |
20 | #include <Standard_Dump.hxx> |
42cf5bc1 |
21 | #include <Standard_GUID.hxx> |
22 | #include <Standard_Type.hxx> |
23 | #include <TCollection_AsciiString.hxx> |
24 | #include <TCollection_ExtendedString.hxx> |
25 | #include <TDataStd_Expression.hxx> |
26 | #include <TDataStd_Name.hxx> |
27 | #include <TDataStd_Real.hxx> |
42cf5bc1 |
28 | #include <TDF_Attribute.hxx> |
29 | #include <TDF_DataSet.hxx> |
30 | #include <TDF_Label.hxx> |
31 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
32 | |
92efcf78 |
33 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Variable,TDF_Attribute) |
34 | |
7fd59977 |
35 | //======================================================================= |
36 | //function : GetID |
37 | //purpose : |
38 | //======================================================================= |
7fd59977 |
39 | const Standard_GUID& TDataStd_Variable::GetID() |
40 | { |
41 | static Standard_GUID TDataStd_VariableID("ce241469-8e57-11d1-8953-080009dc4425"); |
42 | return TDataStd_VariableID; |
43 | } |
44 | |
45 | //======================================================================= |
46 | //function : Set |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | Handle(TDataStd_Variable) TDataStd_Variable::Set(const TDF_Label& L) |
51 | { |
52 | Handle(TDataStd_Variable) A; |
53 | if (!L.FindAttribute (TDataStd_Variable::GetID(), A)) { |
54 | A = new TDataStd_Variable (); |
55 | L.AddAttribute(A); |
56 | } |
57 | return A; |
58 | } |
59 | |
60 | //======================================================================= |
61 | //function : TDataStd_Variable |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | TDataStd_Variable::TDataStd_Variable() |
66 | :isConstant(Standard_False), |
67 | myUnit("SCALAR") |
68 | { |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : Name |
73 | //purpose : |
74 | //======================================================================= |
75 | |
76 | void TDataStd_Variable::Name (const TCollection_ExtendedString& string) |
77 | { |
78 | TDataStd_Name::Set(Label(),string); |
79 | } |
80 | |
81 | //======================================================================= |
82 | //function : Name |
83 | //purpose : |
84 | //======================================================================= |
85 | const TCollection_ExtendedString& TDataStd_Variable::Name () const |
86 | { |
87 | Handle(TDataStd_Name) N; |
88 | if (!Label().FindAttribute(TDataStd_Name::GetID(),N)) { |
9775fa61 |
89 | throw Standard_DomainError("TDataStd_Variable::Name : invalid model"); |
7fd59977 |
90 | } |
91 | return N->Get(); |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : IsValued |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | Standard_Boolean TDataStd_Variable::IsValued () const |
100 | { |
101 | return (Label().IsAttribute (TDataStd_Real::GetID())); |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : Real |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | Handle(TDataStd_Real) TDataStd_Variable::Real() const |
110 | { |
111 | Handle(TDataStd_Real) R; |
112 | if (!Label().FindAttribute(TDataStd_Real::GetID(),R)) { |
9775fa61 |
113 | throw Standard_DomainError("TDataStd_Variable::Real : invalid model"); |
7fd59977 |
114 | } |
115 | return R; |
116 | } |
117 | |
58e5d30e |
118 | |
119 | //======================================================================= |
120 | //function : Set |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | void TDataStd_Variable::Set (const Standard_Real value) const |
125 | { |
126 | Handle(TDataStd_Real) R = TDataStd_Real::Set(Label(), value); |
127 | } |
128 | |
129 | |
7fd59977 |
130 | //======================================================================= |
131 | //function : Set |
132 | //purpose : |
133 | //======================================================================= |
134 | |
135 | void TDataStd_Variable::Set (const Standard_Real value, const TDataStd_RealEnum dimension) const |
136 | { |
137 | if (!IsValued()) { |
138 | Handle(TDataStd_Real) R = TDataStd_Real::Set(Label(),value); |
58e5d30e |
139 | Standard_DISABLE_DEPRECATION_WARNINGS |
7fd59977 |
140 | R->SetDimension (dimension); |
58e5d30e |
141 | Standard_ENABLE_DEPRECATION_WARNINGS |
7fd59977 |
142 | } |
143 | else { |
144 | Handle(TDataStd_Real) R = TDataStd_Real::Set(Label(),value); |
145 | } |
146 | } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : Get |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | Standard_Real TDataStd_Variable::Get () const |
155 | { |
156 | Handle(TDataStd_Real) R; |
157 | if (!Label().FindAttribute(TDataStd_Real::GetID(),R)) { |
9775fa61 |
158 | throw Standard_DomainError("TDataStd_Variable::Get : invalid model"); |
7fd59977 |
159 | } |
160 | return R->Get(); |
161 | } |
162 | |
163 | |
164 | |
165 | //======================================================================= |
166 | //function : IsAssigned |
167 | //purpose : |
168 | //======================================================================= |
169 | |
170 | Standard_Boolean TDataStd_Variable::IsAssigned () const |
171 | { |
172 | return (Label().IsAttribute(TDataStd_Expression::GetID())); |
173 | } |
174 | |
175 | //======================================================================= |
176 | //function : Assign |
177 | //purpose : |
178 | //======================================================================= |
179 | |
180 | Handle(TDataStd_Expression) TDataStd_Variable::Assign () const |
181 | { |
182 | Handle(TDataStd_Expression) E = TDataStd_Expression::Set(Label()); |
183 | return E; |
184 | } |
185 | |
186 | //======================================================================= |
187 | //function : Desassign |
188 | //purpose : |
189 | //======================================================================= |
190 | |
191 | void TDataStd_Variable::Desassign () const |
192 | { |
193 | Handle(TDataStd_Expression) E; |
194 | if (!Label().FindAttribute(TDataStd_Expression::GetID(),E)) { |
9775fa61 |
195 | throw Standard_DomainError("TDataStd_Variable::Deassign"); |
7fd59977 |
196 | } |
197 | Label().ForgetAttribute(E); |
198 | } |
199 | |
200 | //======================================================================= |
201 | //function : Expression |
202 | //purpose : |
203 | //======================================================================= |
204 | |
205 | Handle(TDataStd_Expression) TDataStd_Variable::Expression () const |
206 | { |
207 | Handle(TDataStd_Expression) E; |
208 | if (!Label().FindAttribute(TDataStd_Expression::GetID(),E)) { |
9775fa61 |
209 | throw Standard_DomainError("TDataStd_Variable::GetExpression"); |
7fd59977 |
210 | } |
211 | return E; |
212 | } |
213 | |
214 | //======================================================================= |
215 | //function : IsCaptured |
216 | //purpose : |
217 | //======================================================================= |
218 | |
219 | Standard_Boolean TDataStd_Variable::IsCaptured() const |
220 | { |
221 | return Real()->IsCaptured(); |
222 | } |
223 | |
224 | //======================================================================= |
225 | //function : IsConstant |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | Standard_Boolean TDataStd_Variable::IsConstant () const |
230 | { |
231 | return isConstant; |
232 | } |
233 | |
234 | //======================================================================= |
235 | //function : Constant |
236 | //purpose : |
237 | //======================================================================= |
238 | |
239 | void TDataStd_Variable::Constant (const Standard_Boolean status) |
240 | { |
241 | // OCC2932 correction |
242 | if(isConstant == status) return; |
243 | |
244 | Backup(); |
245 | isConstant = status; |
246 | } |
247 | |
248 | //======================================================================= |
249 | //function : Unit |
250 | //purpose : |
251 | //======================================================================= |
252 | void TDataStd_Variable::Unit(const TCollection_AsciiString& unit) |
253 | { |
254 | // OCC2932 correction |
255 | if(myUnit == unit) |
256 | return; |
257 | |
258 | Backup(); |
259 | myUnit = unit; |
260 | } |
261 | //======================================================================= |
262 | //function : Unit |
263 | //purpose : |
264 | //======================================================================= |
265 | const TCollection_AsciiString& TDataStd_Variable::Unit() const |
266 | { |
267 | return myUnit; |
268 | } |
269 | |
270 | //======================================================================= |
271 | //function : ID |
272 | //purpose : |
273 | //======================================================================= |
274 | |
275 | const Standard_GUID& TDataStd_Variable::ID() const |
276 | { |
277 | return GetID(); |
278 | } |
279 | |
280 | //======================================================================= |
281 | //function : Restore |
282 | //purpose : |
283 | //======================================================================= |
284 | |
285 | void TDataStd_Variable::Restore (const Handle(TDF_Attribute)& With) |
286 | { |
287 | Handle(TDataStd_Variable) V = Handle(TDataStd_Variable)::DownCast (With); |
288 | isConstant = V->IsConstant(); |
289 | myUnit = V->Unit(); |
290 | } |
291 | |
292 | //======================================================================= |
293 | //function : NewEmpty |
294 | //purpose : |
295 | //======================================================================= |
296 | |
297 | Handle(TDF_Attribute) TDataStd_Variable::NewEmpty() const |
298 | { |
299 | return new TDataStd_Variable(); |
300 | } |
301 | |
302 | //======================================================================= |
303 | //function : Paste |
304 | //purpose : |
305 | //======================================================================= |
306 | |
307 | void TDataStd_Variable::Paste (const Handle(TDF_Attribute)& Into, |
308 | const Handle(TDF_RelocationTable)& /*RT*/) const |
309 | { |
310 | Handle(TDataStd_Variable) V = Handle(TDataStd_Variable)::DownCast (Into); |
311 | V->Constant(isConstant); |
312 | V->Unit(myUnit); |
313 | } |
314 | |
315 | |
316 | //======================================================================= |
317 | //function : References |
318 | //purpose : |
319 | //======================================================================= |
320 | |
321 | void TDataStd_Variable::References(const Handle(TDF_DataSet)& DS) const |
322 | { |
323 | Handle(TDataStd_Name) N; |
324 | if (Label().FindAttribute(TDataStd_Name::GetID(),N)) { |
325 | DS->AddAttribute(N); |
326 | } |
327 | } |
328 | |
329 | //======================================================================= |
330 | //function : Dump |
331 | //purpose : |
332 | //======================================================================= |
333 | |
334 | Standard_OStream& TDataStd_Variable::Dump(Standard_OStream& anOS) const |
335 | { |
336 | anOS << "Variable"; |
337 | return anOS; |
338 | } |
339 | |
bc73b006 |
340 | //======================================================================= |
341 | //function : DumpJson |
342 | //purpose : |
343 | //======================================================================= |
344 | void TDataStd_Variable::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
345 | { |
346 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
347 | |
348 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
349 | |
350 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, isConstant) |
351 | OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myUnit) |
352 | } |