b311480e |
1 | // Created on: 1992-06-24 |
2 | // Created by: Gilles DEBARBOUILLE |
3 | // Copyright (c) 1992-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 | |
42cf5bc1 |
17 | |
18 | #include <Standard_Type.hxx> |
7fd59977 |
19 | #include <Units.hxx> |
42cf5bc1 |
20 | #include <Units_Dimensions.hxx> |
7fd59977 |
21 | #include <Units_Operators.hxx> |
42cf5bc1 |
22 | #include <Units_UnitsDictionary.hxx> |
7fd59977 |
23 | |
25e59720 |
24 | IMPLEMENT_STANDARD_RTTIEXT(Units_Dimensions,Standard_Transient) |
92efcf78 |
25 | |
7fd59977 |
26 | //======================================================================= |
27 | //function : Units_Dimensions |
28 | //purpose : |
29 | //======================================================================= |
7fd59977 |
30 | Units_Dimensions::Units_Dimensions(const Standard_Real amass , |
31 | const Standard_Real alength , |
32 | const Standard_Real atime , |
33 | const Standard_Real anelectriccurrent , |
34 | const Standard_Real athermodynamictemperature , |
35 | const Standard_Real anamountofsubstance , |
36 | const Standard_Real aluminousintensity , |
37 | const Standard_Real aplaneangle , |
38 | const Standard_Real asolidangle ) |
39 | { |
40 | themass = amass ; |
41 | thelength = alength ; |
42 | thetime = atime ; |
43 | theelectriccurrent = anelectriccurrent ; |
44 | thethermodynamictemperature = athermodynamictemperature ; |
45 | theamountofsubstance = anamountofsubstance ; |
46 | theluminousintensity = aluminousintensity ; |
47 | theplaneangle = aplaneangle ; |
48 | thesolidangle = asolidangle ; |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Quantity |
53 | |
54 | //purpose : gets the string quantity from dimension parameter |
55 | //Warning : Bo Bo Tetete,take an aspirine !! |
56 | // If you found a more simple way ,phone to GG,thanks ... |
57 | //======================================================================= |
58 | |
59 | static Handle(Units_QuantitiesSequence) quantitySequence; |
60 | static TCollection_AsciiString quantityName; |
61 | Standard_CString Units_Dimensions::Quantity() const |
62 | { |
63 | if( quantitySequence.IsNull() ) { |
64 | quantitySequence = Units::DictionaryOfUnits(Standard_False)->Sequence(); |
65 | } |
66 | Handle(Units_Dimensions) dim; |
67 | for (Standard_Integer i=1; i <= quantitySequence->Length(); i++) { |
68 | dim = quantitySequence->Value(i)->Dimensions(); |
69 | if( themass == dim->Mass() && |
70 | thelength == dim->Length() && |
71 | thetime == dim->Time() && |
72 | theelectriccurrent == dim->ElectricCurrent() && |
73 | thethermodynamictemperature == dim->ThermodynamicTemperature() && |
74 | theamountofsubstance == dim->AmountOfSubstance() && |
75 | theluminousintensity == dim->LuminousIntensity() && |
76 | theplaneangle == dim->PlaneAngle() && |
77 | thesolidangle == dim->SolidAngle() ) { |
78 | quantityName = quantitySequence->Value(i)->Name(); |
79 | return quantityName.ToCString(); |
80 | } |
81 | } |
82 | return NULL; |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : Multiply |
87 | |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | Handle(Units_Dimensions) Units_Dimensions::Multiply |
92 | (const Handle(Units_Dimensions)& adimensions) const |
93 | { |
94 | return new Units_Dimensions |
95 | (themass + adimensions->Mass(), |
96 | thelength + adimensions->Length(), |
97 | thetime + adimensions->Time(), |
98 | theelectriccurrent + adimensions->ElectricCurrent(), |
99 | thethermodynamictemperature + adimensions->ThermodynamicTemperature(), |
100 | theamountofsubstance + adimensions->AmountOfSubstance(), |
101 | theluminousintensity + adimensions->LuminousIntensity(), |
102 | theplaneangle + adimensions->PlaneAngle(), |
103 | thesolidangle + adimensions->SolidAngle()); |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : Divide |
108 | |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | Handle(Units_Dimensions) Units_Dimensions::Divide |
113 | (const Handle(Units_Dimensions)& adimensions) const |
114 | { |
115 | return new Units_Dimensions |
116 | (themass - adimensions->Mass() , |
117 | thelength - adimensions->Length() , |
118 | thetime - adimensions->Time() , |
119 | theelectriccurrent - adimensions->ElectricCurrent() , |
120 | thethermodynamictemperature - adimensions->ThermodynamicTemperature() , |
121 | theamountofsubstance - adimensions->AmountOfSubstance() , |
122 | theluminousintensity - adimensions->LuminousIntensity() , |
123 | theplaneangle - adimensions->PlaneAngle() , |
124 | thesolidangle - adimensions->SolidAngle() ); |
125 | } |
126 | |
127 | //======================================================================= |
128 | //function : Power |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | Handle(Units_Dimensions) Units_Dimensions::Power(const Standard_Real anexponent) const |
133 | { |
134 | return new Units_Dimensions(themass * anexponent, |
135 | thelength * anexponent, |
136 | thetime * anexponent, |
137 | theelectriccurrent * anexponent, |
138 | thethermodynamictemperature * anexponent, |
139 | theamountofsubstance * anexponent, |
140 | theluminousintensity * anexponent, |
141 | theplaneangle * anexponent, |
142 | thesolidangle * anexponent); |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : IsEqual |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | Standard_Boolean Units_Dimensions::IsEqual (const Handle(Units_Dimensions)& adimensions) |
151 | const |
152 | { |
153 | return (themass == adimensions->Mass() && |
154 | thelength == adimensions->Length() && |
155 | thetime == adimensions->Time() && |
156 | theelectriccurrent == adimensions->ElectricCurrent() && |
157 | thethermodynamictemperature == adimensions->ThermodynamicTemperature() && |
158 | theamountofsubstance == adimensions->AmountOfSubstance() && |
159 | theluminousintensity == adimensions->LuminousIntensity() && |
160 | theplaneangle == adimensions->PlaneAngle() && |
161 | thesolidangle == adimensions->SolidAngle() |
162 | ? Standard_True : Standard_False); |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : IsNotEqual |
167 | |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | Standard_Boolean Units_Dimensions::IsNotEqual |
172 | (const Handle(Units_Dimensions)& adimensions) const |
173 | { |
174 | return !(IsEqual(adimensions)) ? Standard_True : Standard_False; |
175 | } |
176 | |
177 | //======================================================================= |
178 | //function : Dump |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | void Units_Dimensions::Dump(const Standard_Integer ashift) const |
183 | { |
184 | int i; |
04232180 |
185 | for(i=0; i<ashift; i++)std::cout<<" "; |
186 | std::cout<<" with the physical dimensions : "<<std::endl; |
187 | for(i=0; i<ashift; i++)std::cout<<" "; |
188 | std::cout<<" mass : "<<themass<<std::endl; |
189 | for(i=0; i<ashift; i++)std::cout<<" "; |
190 | std::cout<<" length : "<<thelength<<std::endl; |
191 | for(i=0; i<ashift; i++)std::cout<<" "; |
192 | std::cout<<" time : "<<thetime<<std::endl; |
193 | for(i=0; i<ashift; i++)std::cout<<" "; |
194 | std::cout<<" electric current : "<<theelectriccurrent<<std::endl; |
195 | for(i=0; i<ashift; i++)std::cout<<" "; |
196 | std::cout<<" thermodynamic temperature : "<<thethermodynamictemperature<<std::endl; |
197 | for(i=0; i<ashift; i++)std::cout<<" "; |
198 | std::cout<<" amount of substance : "<<theamountofsubstance<<std::endl; |
199 | for(i=0; i<ashift; i++)std::cout<<" "; |
200 | std::cout<<" luminous intensity : "<<theluminousintensity<<std::endl; |
201 | for(i=0; i<ashift; i++)std::cout<<" "; |
202 | std::cout<<" plane angle : "<<theplaneangle<<std::endl; |
203 | for(i=0; i<ashift; i++)std::cout<<" "; |
204 | std::cout<<" solid angle : "<<thesolidangle<<std::endl; |
7fd59977 |
205 | } |
206 | |
207 | //======================================================================= |
208 | //function : operator * |
209 | //purpose : |
210 | //======================================================================= |
211 | |
212 | Handle(Units_Dimensions) operator *(const Handle(Units_Dimensions)& adimension1, |
213 | const Handle(Units_Dimensions)& adimension2) |
214 | { |
215 | return adimension1->Multiply(adimension2); |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : operator / |
220 | //purpose : |
221 | //======================================================================= |
222 | |
223 | Handle(Units_Dimensions) operator /(const Handle(Units_Dimensions)& adimension1, |
224 | const Handle(Units_Dimensions)& adimension2) |
225 | { |
226 | return adimension1->Divide(adimension2); |
227 | } |
228 | |
229 | //======================================================================= |
230 | //function : pow |
231 | //purpose : |
232 | //======================================================================= |
233 | |
234 | Handle(Units_Dimensions) pow(const Handle(Units_Dimensions)&adimension, |
235 | const Standard_Real areal) |
236 | { |
237 | return adimension->Power(areal); |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : operator == |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | //Standard_Boolean operator ==(const Handle(Units_Dimensions)& adimension1, |
246 | // const Handle(Units_Dimensions)& adimension2) |
247 | //{ |
248 | // return adimension1->IsEqual(adimension2); |
249 | //} |
250 | |
251 | //======================================================================= |
252 | //function : operator != |
253 | //purpose : |
254 | //======================================================================= |
255 | |
256 | //Standard_Boolean operator !=(const Handle(Units_Dimensions)& adimension1, |
257 | // const Handle(Units_Dimensions)& adimension2) |
258 | //{ |
259 | // return adimension1->IsNotEqual(adimension2); |
260 | //} |
261 | |
262 | Handle(Units_Dimensions) Units_Dimensions::ALess() { |
263 | static Handle(Units_Dimensions) aDim; |
264 | if (aDim.IsNull()) |
265 | aDim = new Units_Dimensions(0.,0.,0.,0.,0.,0.,0.,0.,0.); |
266 | return aDim; |
267 | } |
268 | Handle(Units_Dimensions) Units_Dimensions::AMass() { |
269 | static Handle(Units_Dimensions) aDim; |
270 | if (aDim.IsNull()) |
271 | aDim = new Units_Dimensions(1.,0.,0.,0.,0.,0.,0.,0.,0.); |
272 | return aDim; |
273 | } |
274 | Handle(Units_Dimensions) Units_Dimensions::ALength() { |
275 | static Handle(Units_Dimensions) aDim; |
276 | if (aDim.IsNull()) |
277 | aDim = new Units_Dimensions(0.,1.,0.,0.,0.,0.,0.,0.,0.); |
278 | return aDim; |
279 | } |
280 | Handle(Units_Dimensions) Units_Dimensions::ATime() { |
281 | static Handle(Units_Dimensions) aDim; |
282 | if (aDim.IsNull()) |
283 | aDim = new Units_Dimensions(0.,0.,1.,0.,0.,0.,0.,0.,0.); |
284 | return aDim; |
285 | } |
286 | Handle(Units_Dimensions) Units_Dimensions::AElectricCurrent() { |
287 | static Handle(Units_Dimensions) aDim; |
288 | if (aDim.IsNull()) |
289 | aDim = new Units_Dimensions(0.,0.,0.,1.,0.,0.,0.,0.,0.); |
290 | return aDim; |
291 | } |
292 | Handle(Units_Dimensions) Units_Dimensions::AThermodynamicTemperature() { |
293 | static Handle(Units_Dimensions) aDim; |
294 | if (aDim.IsNull()) |
295 | aDim = new Units_Dimensions(0.,0.,0.,0.,1.,0.,0.,0.,0.); |
296 | return aDim; |
297 | } |
298 | Handle(Units_Dimensions) Units_Dimensions::AAmountOfSubstance() { |
299 | static Handle(Units_Dimensions) aDim; |
300 | if (aDim.IsNull()) |
301 | aDim = new Units_Dimensions(0.,0.,0.,0.,0.,1.,0.,0.,0.); |
302 | return aDim; |
303 | } |
304 | Handle(Units_Dimensions) Units_Dimensions::ALuminousIntensity() { |
305 | static Handle(Units_Dimensions) aDim; |
306 | if (aDim.IsNull()) |
307 | aDim = new Units_Dimensions(0.,0.,0.,0.,0.,0.,1.,0.,0.); |
308 | return aDim; |
309 | } |
310 | Handle(Units_Dimensions) Units_Dimensions::APlaneAngle() { |
311 | static Handle(Units_Dimensions) aDim; |
312 | if (aDim.IsNull()) |
313 | aDim = new Units_Dimensions(0.,0.,0.,0.,0.,0.,0.,1.,0.); |
314 | return aDim; |
315 | } |
316 | Handle(Units_Dimensions) Units_Dimensions::ASolidAngle() { |
317 | static Handle(Units_Dimensions) aDim; |
318 | if (aDim.IsNull()) |
319 | aDim = new Units_Dimensions(0.,0.,0.,0.,0.,0.,0.,0.,1.); |
320 | return aDim; |
321 | } |