00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef UnitSystemsManagerH
00033 #define UnitSystemsManagerH
00034
00035 #include <zeusmath/Config/PlatformDefines.hpp>
00036 #include <zeusmath/System/Interfaces/IUnitSystemsManager.hpp>
00037 #include <zeusbase/System/ZObject.h>
00038
00039
00040 #define UnitSystemsManager NAMESPACE_Zeus::TUnitSystemsManager::getInstance()
00041
00044 enum EUnit
00045 {
00046 etNoUnit = 0,
00047 etDistance_mm = 1,
00048 etSpeed_m_per_s = 2,
00049 etSpeed_mm_per_min = 3,
00050 etRevolutions_per_min = 4,
00051 etTime_s = 5,
00052 etTime_min = 6,
00053 etDegrees360 = 7,
00054 etDegrees360_per_min = 8,
00055 etVolumePerLength_mm3_per_mm = 9,
00056 etVolume_mm3 = 10,
00057 etVolumePerTime_mm3_per_s = 11,
00058 etForce_Newton = 12,
00059 etTime_h = 13,
00060 etSpeed_mm_per_revolutions = 14,
00061 etVolumePerTime_mm3_per_h = 15,
00062 etNumberOfUnits
00063 };
00064
00065
00066
00067 BEGIN_NAMESPACE_Zeus
00068
00069
00073
00074 zeusmath_class TUnitSystemsManager : public TZObject, public IUnitSystemsManager
00075 {
00076 public:
00078 static inline TUnitSystemsManager& getInstance() { return m_Instance; }
00079 void setDelegationInterface(IUnitSystemsManager& rManager);
00080 void releaseDelegationInterface();
00081
00082
00085
00086 inline EUnitSystem MQUALIFIER getUnitSystem() const
00087 {
00088 EUnitSystem eRetval = m_eUnitSystem;
00089 if (m_ptrDelegation != NULL)
00090 {
00091 eRetval = m_ptrDelegation->getUnitSystem();
00092 }
00093 return m_eUnitSystem;
00094 }
00095
00096
00099
00100 inline void MQUALIFIER setUnitSystem(EUnitSystem eUnitSystem)
00101 {
00102 m_eUnitSystem = eUnitSystem;
00103 if (m_ptrDelegation != NULL)
00104 {
00105 m_ptrDelegation->setUnitSystem(eUnitSystem);
00106 }
00107 }
00108
00109
00110 MEMORY_MANAGER_DECL
00111
00113 TString getUnitText(EUnit eUnit) const;
00114
00116 static TString getUnitTextMetric(EUnit eUnit);
00117
00119 static TString getUnitTextInch(EUnit eUnit);
00120
00123 Float getConversionFactorToMetric(EUnit eUnit) const;
00124
00127 Float getConversionFactorFromMetric(EUnit eUnit) const;
00128
00131 void convertToMetric(Float& fValue, EUnit eUnit,
00132 bool bRound, bool bExcludeZero = false) const;
00133
00136 void convertFromMetric(Float& fValue, EUnit eUnit,
00137 bool bRound, bool bExcludeZero = false) const;
00138
00141 Float getConversionToMetric(const Float& fValue, EUnit eUnit,
00142 bool bRound, bool bExcludeZero = false) const;
00143
00146 Float getConversionFromMetric(const Float& fValue, EUnit eUnit,
00147 bool bRound, bool bExcludeZero = false) const;
00148
00150 static void round(Float& fValue, const Float& fRoundingStep, bool bExcludeZero);
00151
00153 void round(Float& rfValue, bool bExcludeZero = false);
00154
00156 static Int getStandardRoundingDigits(EUnitSystem eUnitSystem);
00157
00159 inline Int getStandardRoundingDigits() const { return getStandardRoundingDigits(getUnitSystem()); }
00160
00162 static Float getStandardRoundingStep(EUnitSystem eUnitSystem);
00163
00165 inline Float getStandardRoundingStep() const { return getStandardRoundingStep(getUnitSystem()); }
00166
00168 static TString getStandardRoundingFormat(EUnitSystem eUnitSystem);
00169
00171 inline TString getStandardRoundingFormat() const { return getStandardRoundingFormat(getUnitSystem()); }
00172
00176 #define INVERSE(Method) Float(1) / Method()
00177
00178
00179 static inline Float mm_per_m() { return 1000; }
00180 static inline Float m_per_mm() { return INVERSE(mm_per_m); }
00181 static inline Float um_per_mm() { return 1000; }
00182 static inline Float mm_per_um() { return INVERSE(um_per_mm); }
00183 static inline Float mm_per_inch() { return 25.4; }
00184 static inline Float inch_per_mm() { return INVERSE(mm_per_inch); }
00185 static inline Float inch_per_foot() { return 12; }
00186 static inline Float foot_per_inch() { return INVERSE(inch_per_foot); }
00187 static inline Float mm_per_foot() { return mm_per_inch() * inch_per_foot(); }
00188 static inline Float foot_per_mm() { return INVERSE(mm_per_foot); }
00189 static inline Float m_per_foot() { return m_per_mm() * mm_per_foot(); }
00190 static inline Float foot_per_m() { return INVERSE(m_per_foot); }
00191
00192 static inline Float mm2_per_inch2() { return TMath::pow(mm_per_inch(), 2); }
00193 static inline Float inch2_per_mm2() { return INVERSE(mm2_per_inch2); }
00194
00195 static inline Float mm3_per_inch3() { return TMath::pow(mm_per_inch(), 3); }
00196 static inline Float inch3_per_mm3() { return INVERSE(mm3_per_inch3); }
00197
00198 static inline Float s_per_min() { return 60; }
00199 static inline Float min_per_s() { return INVERSE(s_per_min); }
00200
00201 static inline Float gram_per_kilo() { return 1000; }
00202 static inline Float kilo_per_gram() { return INVERSE(gram_per_kilo); }
00203 static inline Float gram_per_ounce() { return 28.349523125; }
00204 static inline Float ounce_per_gram() { return INVERSE(gram_per_ounce); }
00205 static inline Float ounce_per_pound() { return 16; }
00206 static inline Float pound_per_ounce() { return INVERSE(ounce_per_pound); }
00207 static inline Float gram_per_pound() { return gram_per_ounce() * ounce_per_pound(); }
00208 static inline Float pound_per_gram() { return INVERSE(gram_per_pound); }
00209 static inline Float kilo_per_pound() { return kilo_per_gram() * gram_per_pound(); }
00210 static inline Float pound_per_kilo() { return INVERSE(kilo_per_pound); }
00211
00212 static inline Float earthGravity_ms2() { return 9.81; }
00213 static inline Float newton_per_kilo() { return earthGravity_ms2(); }
00214 static inline Float kilo_per_newton() { return INVERSE(newton_per_kilo); }
00215 static inline Float newton_per_pound() { return newton_per_kilo() * kilo_per_pound(); }
00216 static inline Float pound_per_newton() { return INVERSE(newton_per_pound); }
00217
00218 private:
00220 TUnitSystemsManager();
00221
00222 private:
00224 static TUnitSystemsManager m_Instance;
00226 TAutoPtr<IUnitSystemsManager> m_ptrDelegation;
00227
00229 EUnitSystem m_eUnitSystem;
00230 };
00231
00232
00233
00234
00237
00238 inline TUnitSystemsManager::TUnitSystemsManager()
00239 {
00240 m_eUnitSystem = etUndefinedUnitSystem;
00241 }
00242
00243
00246
00247 inline void TUnitSystemsManager::releaseDelegationInterface()
00248 {
00249 m_ptrDelegation.release();
00250 }
00251
00252
00260
00261 inline Float TUnitSystemsManager::getConversionFactorFromMetric(EUnit eUnit) const
00262 {
00263 return Float(1) / getConversionFactorToMetric(eUnit);
00264 }
00265
00266
00267
00278
00279 inline Float TUnitSystemsManager::getConversionToMetric(const Float& fValue, EUnit eUnit,
00280 bool bRound, bool bExcludeZero ) const
00281 {
00282 Float fRetval = fValue;
00283 convertToMetric(fRetval, eUnit, bRound, bExcludeZero);
00284 return fRetval;
00285 }
00286
00287
00288
00299
00300 inline Float TUnitSystemsManager::getConversionFromMetric(const Float& fValue, EUnit eUnit,
00301 bool bRound, bool bExcludeZero ) const
00302 {
00303 Float fRetval = fValue;
00304 convertFromMetric(fRetval, eUnit, bRound, bExcludeZero);
00305 return fRetval;
00306 }
00307
00308
00309 END_NAMESPACE_Zeus
00310
00311 #endif
00312