0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / UnitsAPI / UnitsAPI.hxx
CommitLineData
42cf5bc1 1// Created on: 1995-11-15
2// Created by: Jean-Louis Frenkel <rmi@pernox>
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
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
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _UnitsAPI_HeaderFile
18#define _UnitsAPI_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Real.hxx>
25#include <Standard_CString.hxx>
26#include <UnitsAPI_SystemUnits.hxx>
27#include <Standard_Boolean.hxx>
28class Units_Dimensions;
29
30
31//! The UnitsAPI global functions are used to
32//! convert a value from any unit into another unit.
33//! Principles
34//! Conversion is executed among three unit systems:
35//! - the SI System
36//! - the user's Local System
37//! - the user's Current System.
38//! The SI System is the standard international unit
39//! system. It is indicated by SI in the synopses of
40//! the UnitsAPI functions.
41//! The MDTV System corresponds to the SI
42//! international standard but the length unit and all
43//! its derivatives use millimeters instead of the meters.
44//! Both systems are proposed by Open CASCADE;
45//! the SI System is the standard option. By
46//! selecting one of these two systems, the user
47//! defines his Local System through the
48//! SetLocalSystem function. The Local System is
49//! indicated by LS in the synopses of the UnitsAPI functions.
50//! The user's Local System units can be modified in
51//! the working environment. The user defines his
52//! Current System by modifying its units through
53//! the SetCurrentUnit function. The Current
54//! System is indicated by Current in the synopses
55//! of the UnitsAPI functions.
56class UnitsAPI
57{
58public:
59
60 DEFINE_STANDARD_ALLOC
61
62
63 //! Converts the current unit value to the local system units value.
64 //! Example: CurrentToLS(1.,"LENGTH") returns 1000. if the current length unit
65 //! is meter and LocalSystem is MDTV.
66 Standard_EXPORT static Standard_Real CurrentToLS (const Standard_Real aData, const Standard_CString aQuantity);
67
68 //! Converts the current unit value to the SI system units value.
69 //! Example: CurrentToSI(1.,"LENGTH") returns 0.001 if current length unit
70 //! is millimeter.
71 Standard_EXPORT static Standard_Real CurrentToSI (const Standard_Real aData, const Standard_CString aQuantity);
72
73 //! Converts the local system units value to the current unit value.
74 //! Example: CurrentFromLS(1000.,"LENGTH") returns 1. if current length unit
75 //! is meter and LocalSystem is MDTV.
76 Standard_EXPORT static Standard_Real CurrentFromLS (const Standard_Real aData, const Standard_CString aQuantity);
77
78 //! Converts the SI system units value to the current unit value.
79 //! Example: CurrentFromSI(0.001,"LENGTH") returns 1 if current length unit
80 //! is millimeter.
81 Standard_EXPORT static Standard_Real CurrentFromSI (const Standard_Real aData, const Standard_CString aQuantity);
82
83 //! Converts the local unit value to the local system units value.
84 //! Example: AnyToLS(1.,"in.") returns 25.4 if the LocalSystem is MDTV.
85 Standard_EXPORT static Standard_Real AnyToLS (const Standard_Real aData, const Standard_CString aUnit);
86
87 //! Converts the local unit value to the local system units value.
88 //! and gives the associated dimension of the unit
89 Standard_EXPORT static Standard_Real AnyToLS (const Standard_Real aData, const Standard_CString aUnit, Handle(Units_Dimensions)& aDim);
90
91 //! Converts the local unit value to the SI system units value.
92 //! Example: AnyToSI(1.,"in.") returns 0.0254
93 Standard_EXPORT static Standard_Real AnyToSI (const Standard_Real aData, const Standard_CString aUnit);
94
95 //! Converts the local unit value to the SI system units value.
96 //! and gives the associated dimension of the unit
97 Standard_EXPORT static Standard_Real AnyToSI (const Standard_Real aData, const Standard_CString aUnit, Handle(Units_Dimensions)& aDim);
98
99 //! Converts the local system units value to the local unit value.
100 //! Example: AnyFromLS(25.4,"in.") returns 1. if the LocalSystem is MDTV.
101 //! Note: aUnit is also used to identify the type of physical quantity to convert.
102 Standard_EXPORT static Standard_Real AnyFromLS (const Standard_Real aData, const Standard_CString aUnit);
103
104 //! Converts the SI system units value to the local unit value.
105 //! Example: AnyFromSI(0.0254,"in.") returns 0.001
106 //! Note: aUnit is also used to identify the type of physical quantity to convert.
107 Standard_EXPORT static Standard_Real AnyFromSI (const Standard_Real aData, const Standard_CString aUnit);
108
109 //! Converts the aData value expressed in the
110 //! current unit for the working environment, as
111 //! defined for the physical quantity aQuantity by the
112 //! last call to the SetCurrentUnit function, into the unit aUnit.
113 Standard_EXPORT static Standard_Real CurrentToAny (const Standard_Real aData, const Standard_CString aQuantity, const Standard_CString aUnit);
114
115 //! Converts the aData value expressed in the unit
116 //! aUnit, into the current unit for the working
117 //! environment, as defined for the physical quantity
118 //! aQuantity by the last call to the SetCurrentUnit function.
119 Standard_EXPORT static Standard_Real CurrentFromAny (const Standard_Real aData, const Standard_CString aQuantity, const Standard_CString aUnit);
120
121 //! Converts the local unit value to another local unit value.
122 //! Example: AnyToAny(0.0254,"in.","millimeter") returns 1. ;
123 Standard_EXPORT static Standard_Real AnyToAny (const Standard_Real aData, const Standard_CString aUnit1, const Standard_CString aUnit2);
124
125 //! Converts the local system units value to the SI system unit value.
126 //! Example: LSToSI(1.,"LENGTH") returns 0.001 if the local system
127 //! length unit is millimeter.
128 Standard_EXPORT static Standard_Real LSToSI (const Standard_Real aData, const Standard_CString aQuantity);
129
130 //! Converts the SI system unit value to the local system units value.
131 //! Example: SIToLS(1.,"LENGTH") returns 1000. if the local system
132 //! length unit is millimeter.
133 Standard_EXPORT static Standard_Real SIToLS (const Standard_Real aData, const Standard_CString aQuantity);
134
135 //! Sets the local system units.
136 //! Example: SetLocalSystem(UnitsAPI_MDTV)
137 Standard_EXPORT static void SetLocalSystem (const UnitsAPI_SystemUnits aSystemUnit = UnitsAPI_SI);
138
139 //! Returns the current local system units.
140 Standard_EXPORT static UnitsAPI_SystemUnits LocalSystem();
141
142 //! Sets the current unit dimension <aUnit> to the unit quantity <aQuantity>.
143 //! Example: SetCurrentUnit("LENGTH","millimeter")
144 Standard_EXPORT static void SetCurrentUnit (const Standard_CString aQuantity, const Standard_CString aUnit);
145
146 //! Returns the current unit dimension <aUnit> from the unit quantity <aQuantity>.
147 Standard_EXPORT static Standard_CString CurrentUnit (const Standard_CString aQuantity);
148
149 //! saves the units in the file .CurrentUnits of the directory pointed by the
150 //! CSF_CurrentUnitsUserDefaults environment variable.
151 Standard_EXPORT static void Save();
152
153 Standard_EXPORT static void Reload();
154
155 //! return the dimension associated to the quantity
156 Standard_EXPORT static Handle(Units_Dimensions) Dimensions (const Standard_CString aQuantity);
157
158 Standard_EXPORT static Handle(Units_Dimensions) DimensionLess();
159
160 Standard_EXPORT static Handle(Units_Dimensions) DimensionMass();
161
162 Standard_EXPORT static Handle(Units_Dimensions) DimensionLength();
163
164 Standard_EXPORT static Handle(Units_Dimensions) DimensionTime();
165
166 Standard_EXPORT static Handle(Units_Dimensions) DimensionElectricCurrent();
167
168 Standard_EXPORT static Handle(Units_Dimensions) DimensionThermodynamicTemperature();
169
170 Standard_EXPORT static Handle(Units_Dimensions) DimensionAmountOfSubstance();
171
172 Standard_EXPORT static Handle(Units_Dimensions) DimensionLuminousIntensity();
173
174 Standard_EXPORT static Handle(Units_Dimensions) DimensionPlaneAngle();
175
176 //! Returns the basic dimensions.
177 Standard_EXPORT static Handle(Units_Dimensions) DimensionSolidAngle();
178
179 //! Checks the coherence between the quantity <aQuantity>
180 //! and the unit <aUnits> in the current system and
181 //! returns FALSE when it's WRONG.
182 Standard_EXPORT static Standard_Boolean Check (const Standard_CString aQuantity, const Standard_CString aUnit);
183
184
185
186
187protected:
188
189
190
191
192
193private:
194
195
196 Standard_EXPORT static void CheckLoading (const UnitsAPI_SystemUnits aSystemUnit);
197
198
199
200
201};
202
203
204
205
206
207
208
209#endif // _UnitsAPI_HeaderFile