Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:19:36

0001 // Created on: 1995-11-15
0002 // Created by: Jean-Louis Frenkel <rmi@pernox>
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _UnitsAPI_HeaderFile
0018 #define _UnitsAPI_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_CString.hxx>
0025 #include <UnitsAPI_SystemUnits.hxx>
0026 class Units_Dimensions;
0027 
0028 //! The UnitsAPI global functions are used to
0029 //! convert a value from any unit into another unit.
0030 //! Principles
0031 //! Conversion is executed among three unit systems:
0032 //! -   the SI System
0033 //! -   the user's Local System
0034 //! -   the user's Current System.
0035 //! The SI System is the standard international unit
0036 //! system. It is indicated by SI in the synopses of
0037 //! the UnitsAPI functions.
0038 //! The MDTV System corresponds to the SI
0039 //! international standard but the length unit and all
0040 //! its derivatives use millimeters instead of the meters.
0041 //! Both systems are proposed by Open CASCADE;
0042 //! the SI System is the standard option. By
0043 //! selecting one of these two systems, the user
0044 //! defines his Local System through the
0045 //! SetLocalSystem function. The Local System is
0046 //! indicated by LS in the synopses of the UnitsAPI functions.
0047 //! The user's Local System units can be modified in
0048 //! the working environment. The user defines his
0049 //! Current System by modifying its units through
0050 //! the SetCurrentUnit function. The Current
0051 //! System is indicated by Current in the synopses
0052 //! of the UnitsAPI functions.
0053 class UnitsAPI
0054 {
0055 public:
0056   DEFINE_STANDARD_ALLOC
0057 
0058   //! Converts the current unit value to the local system units value.
0059   //! Example: CurrentToLS(1.,"LENGTH") returns 1000. if the current length unit
0060   //! is meter and LocalSystem is MDTV.
0061   Standard_EXPORT static double CurrentToLS(const double aData, const char* const aQuantity);
0062 
0063   //! Converts the current unit value to the SI system units value.
0064   //! Example: CurrentToSI(1.,"LENGTH") returns 0.001 if current length unit
0065   //! is millimeter.
0066   Standard_EXPORT static double CurrentToSI(const double aData, const char* const aQuantity);
0067 
0068   //! Converts the local system units value to the current unit value.
0069   //! Example: CurrentFromLS(1000.,"LENGTH") returns 1. if current length unit
0070   //! is meter and LocalSystem is MDTV.
0071   Standard_EXPORT static double CurrentFromLS(const double aData, const char* const aQuantity);
0072 
0073   //! Converts the SI system units value to the current unit value.
0074   //! Example: CurrentFromSI(0.001,"LENGTH") returns 1 if current length unit
0075   //! is millimeter.
0076   Standard_EXPORT static double CurrentFromSI(const double aData, const char* const aQuantity);
0077 
0078   //! Converts the local unit value to the local system units value.
0079   //! Example: AnyToLS(1.,"in.") returns 25.4 if the LocalSystem is MDTV.
0080   Standard_EXPORT static double AnyToLS(const double aData, const char* const aUnit);
0081 
0082   //! Converts the local unit value to the local system units value.
0083   //! and gives the associated dimension of the unit
0084   Standard_EXPORT static double AnyToLS(const double                   aData,
0085                                         const char* const              aUnit,
0086                                         occ::handle<Units_Dimensions>& aDim);
0087 
0088   //! Converts the local unit value to the SI system units value.
0089   //! Example: AnyToSI(1.,"in.") returns 0.0254
0090   Standard_EXPORT static double AnyToSI(const double aData, const char* const aUnit);
0091 
0092   //! Converts the local unit value to the SI system units value.
0093   //! and gives the associated dimension of the unit
0094   Standard_EXPORT static double AnyToSI(const double                   aData,
0095                                         const char* const              aUnit,
0096                                         occ::handle<Units_Dimensions>& aDim);
0097 
0098   //! Converts the local system units value to the local unit value.
0099   //! Example: AnyFromLS(25.4,"in.") returns 1. if the LocalSystem is MDTV.
0100   //! Note: aUnit is also used to identify the type of physical quantity to convert.
0101   Standard_EXPORT static double AnyFromLS(const double aData, const char* const aUnit);
0102 
0103   //! Converts the SI system units value to the local unit value.
0104   //! Example: AnyFromSI(0.0254,"in.") returns 0.001
0105   //! Note: aUnit is also used to identify the type of physical quantity to convert.
0106   Standard_EXPORT static double AnyFromSI(const double aData, const char* const aUnit);
0107 
0108   //! Converts the aData value expressed in the
0109   //! current unit for the working environment, as
0110   //! defined for the physical quantity aQuantity by the
0111   //! last call to the SetCurrentUnit function, into the unit aUnit.
0112   Standard_EXPORT static double CurrentToAny(const double      aData,
0113                                              const char* const aQuantity,
0114                                              const char* const aUnit);
0115 
0116   //! Converts the aData value expressed in the unit
0117   //! aUnit, into the current unit for the working
0118   //! environment, as defined for the physical quantity
0119   //! aQuantity by the last call to the SetCurrentUnit function.
0120   Standard_EXPORT static double CurrentFromAny(const double      aData,
0121                                                const char* const aQuantity,
0122                                                const char* const aUnit);
0123 
0124   //! Converts the local unit value to another local unit value.
0125   //! Example: AnyToAny(0.0254,"in.","mm") returns 1. ;
0126   Standard_EXPORT static double AnyToAny(const double      aData,
0127                                          const char* const aUnit1,
0128                                          const char* const aUnit2);
0129 
0130   //! Converts the local system units value to the SI system unit value.
0131   //! Example: LSToSI(1.,"LENGTH") returns 0.001 if the local system
0132   //! length unit is millimeter.
0133   Standard_EXPORT static double LSToSI(const double aData, const char* const aQuantity);
0134 
0135   //! Converts the SI system unit value to the local system units value.
0136   //! Example: SIToLS(1.,"LENGTH") returns 1000. if the local system
0137   //! length unit is millimeter.
0138   Standard_EXPORT static double SIToLS(const double aData, const char* const aQuantity);
0139 
0140   //! Sets the local system units.
0141   //! Example: SetLocalSystem(UnitsAPI_MDTV)
0142   Standard_EXPORT static void SetLocalSystem(const UnitsAPI_SystemUnits aSystemUnit = UnitsAPI_SI);
0143 
0144   //! Returns the current local system units.
0145   Standard_EXPORT static UnitsAPI_SystemUnits LocalSystem();
0146 
0147   //! Sets the current unit dimension <aUnit> to the unit quantity <aQuantity>.
0148   //! Example: SetCurrentUnit("LENGTH","mm")
0149   Standard_EXPORT static void SetCurrentUnit(const char* const aQuantity, const char* const aUnit);
0150 
0151   //! Returns the current unit dimension <aUnit> from the unit quantity <aQuantity>.
0152   Standard_EXPORT static const char* CurrentUnit(const char* const aQuantity);
0153 
0154   //! saves the units in the file .CurrentUnits of the directory pointed by the
0155   //! CSF_CurrentUnitsUserDefaults environment variable.
0156   Standard_EXPORT static void Save();
0157 
0158   Standard_EXPORT static void Reload();
0159 
0160   //! return the dimension associated to the quantity
0161   Standard_EXPORT static occ::handle<Units_Dimensions> Dimensions(const char* const aQuantity);
0162 
0163   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionLess();
0164 
0165   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionMass();
0166 
0167   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionLength();
0168 
0169   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionTime();
0170 
0171   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionElectricCurrent();
0172 
0173   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionThermodynamicTemperature();
0174 
0175   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionAmountOfSubstance();
0176 
0177   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionLuminousIntensity();
0178 
0179   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionPlaneAngle();
0180 
0181   //! Returns the basic dimensions.
0182   Standard_EXPORT static occ::handle<Units_Dimensions> DimensionSolidAngle();
0183 
0184   //! Checks the coherence between the quantity <aQuantity>
0185   //! and the unit <aUnits> in the current system and
0186   //! returns FALSE when it's WRONG.
0187   Standard_EXPORT static bool Check(const char* const aQuantity, const char* const aUnit);
0188 
0189 private:
0190   Standard_EXPORT static void CheckLoading(const UnitsAPI_SystemUnits aSystemUnit);
0191 };
0192 
0193 #endif // _UnitsAPI_HeaderFile