OpendTect-6_4  6.4
unitofmeasure.h
Go to the documentation of this file.
1 #ifndef unitofmeasure_h
2 #define unitofmeasure_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: Feb 2004
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "propertyref.h"
17 #include "scaler.h"
18 #include "repos.h"
19 #include "survinfo.h"
20 
22 
24 
25 
37 public:
38 
40  : proptype_(PropertyRef::Other)
41  , source_(Repos::Temp) {}
42  UnitOfMeasure( const char* n, const char* s, double f,
44  : NamedObject(n), symbol_(s)
45  , scaler_(0,f), source_(Repos::Temp)
46  , proptype_(t) {}
48  : NamedObject(uom.name())
49  { *this = uom; }
50  UnitOfMeasure& operator =(const UnitOfMeasure&);
51 
52  const char* symbol() const { return symbol_.buf(); }
53  PropertyRef::StdType propType() const { return proptype_; }
54  const LinScaler& scaler() const { return scaler_; }
55 
56  void setSymbol( const char* s )
57  { symbol_ = s; }
58  void setScaler( const LinScaler& s )
59  { scaler_ = s; }
61  { proptype_ = t; }
62 
63  bool isImperial() const;
64 
65  template <class T>
66  T getSIValue( T inp ) const
67  { return ( T ) scaler_.scale(inp); }
68  template <class T>
69  T getUserValueFromSI( T inp ) const
70  { return ( T ) scaler_.unScale(inp); }
71  template <class T>
72  T internalValue(T inp) const;
73  template <class T>
74  T userValue(T inp) const;
75 
76  static const UnitOfMeasure* getGuessed(const char*);
77  Repos::Source source() const { return source_; }
78  void setSource( Repos::Source s ) { source_ = s; }
79 
80  static const UnitOfMeasure* surveyDefZUnit();
82  static const UnitOfMeasure* surveyDefZStorageUnit();
84  static const UnitOfMeasure* surveyDefTimeUnit();
86  static const UnitOfMeasure* surveyDefDepthUnit();
88  static const UnitOfMeasure* surveyDefDepthStorageUnit();
90  static const UnitOfMeasure* surveyDefVelUnit();
92  static uiString surveyDefZUnitAnnot(bool symbol,bool withparens);
93  static uiString surveyDefTimeUnitAnnot(bool symbol,bool withparens);
94  static uiString surveyDefDepthUnitAnnot(bool symbol,bool withparens);
95  static uiString surveyDefVelUnitAnnot(bool symbol,bool withparens);
96  static uiString zUnitAnnot(bool time,bool symbol,bool withparens);
97 
98  static IOPar& currentDefaults();
101  static void saveCurrentDefaults();
104 
105 protected:
106 
111 
112 };
113 
114 
117 template <class T> void convValue(T& val,
118  const UnitOfMeasure* oldunit, const UnitOfMeasure* newunit);
119 
120 template <class T> inline T getConvertedValue(T val,
121  const UnitOfMeasure* oldunit, const UnitOfMeasure* newunit);
122 
123 
136 {
137 public:
138 
139  const UnitOfMeasure* get(PropertyRef::StdType,const char* nm) const;
140  const UnitOfMeasure* get(const char* nm) const;
141  static const char* guessedStdName(const char*);
143 
144  const ObjectSet<const UnitOfMeasure>& all() const { return entries; }
145  void getRelevant(PropertyRef::StdType,
147  const UnitOfMeasure* getCurDefaultFor(const char* key) const;
148  const UnitOfMeasure* getInternalFor(PropertyRef::StdType) const;
149  const UnitOfMeasure* getDefault(const char* key,PropertyRef::StdType) const;
150 
151  bool add(const UnitOfMeasure&);
153  bool write(Repos::Source) const;
154 
155 private:
156 
158 
160 
161  void addUnitsFromFile(const char*,Repos::Source);
163  const char* nm) const;
165 
166  friend mGlobal(General) UnitOfMeasureRepository& UoMR();
167 
168 };
169 
170 
171 
172 template <class T> inline T UnitOfMeasure::internalValue( T inp ) const
173 {
174  if ( SI().zInFeet() )
175  {
176  if ( symbol_.contains("ft") )
177  return inp;
178  else if ( symbol_.contains("m") )
179  {
180  const UnitOfMeasure* feetunit = UoMR().get( "ft" );
181  return feetunit ? feetunit->getUserValueFromSI( inp ) : inp;
182  }
183  }
184 
185  return getSIValue( inp );
186 }
187 
188 
189 template <class T> inline T UnitOfMeasure::userValue( T inp ) const
190 {
191  if ( SI().zInFeet() )
192  {
193  if ( symbol_.contains("ft") )
194  return inp;
195  else if ( symbol_.contains("m") )
196  {
197  const UnitOfMeasure* feetunit = UoMR().get( "ft" );
198  return feetunit ? feetunit->getSIValue( inp ) : inp;
199  }
200  }
201 
202  return getUserValueFromSI( inp );
203 }
204 
205 
206 template <class T> void convValue( T& val,
207  const UnitOfMeasure* oldunit, const UnitOfMeasure* newunit )
208 { val = getConvertedValue( val, oldunit, newunit ); }
209 
210 
211 template <class T> inline T getConvertedValue( T val,
212  const UnitOfMeasure* oldunit, const UnitOfMeasure* newunit )
213 {
214  if ( oldunit == newunit || mIsUdf(val) )
215  return val;
216 
217  if ( oldunit )
218  val = oldunit->internalValue( val );
219  if ( newunit )
220  val = newunit->userValue( val );
221 
222  return val;
223 }
224 
225 #endif
#define mExpClass(module)
Definition: commondefs.h:160
void setSource(Repos::Source s)
Definition: unitofmeasure.h:78
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Definition: repos.h:22
bool add(const UnitOfMeasure &)
returns false when already present
const UnitOfMeasure * getInternalFor(PropertyRef::StdType) const
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
#define mGlobal(module)
Definition: commondefs.h:163
Repository of all Units of Measure in the system.
Definition: unitofmeasure.h:135
Ref Data for a (usually petrophysical) property.
Definition: propertyref.h:42
UnitOfMeasure(const char *n, const char *s, double f, PropertyRef::StdType t=PropertyRef::Other)
Definition: unitofmeasure.h:42
bool contains(char) const
Definition: odinst.h:42
Definition: uistring.h:89
const UnitOfMeasure * findBest(const ObjectSet< const UnitOfMeasure > &, const char *nm) const
Will try names first, then symbols, otherwise null.
const UnitOfMeasure * getDefault(const char *key, PropertyRef::StdType) const
PropertyRef::StdType proptype_
Definition: unitofmeasure.h:109
T getSIValue(T inp) const
Definition: unitofmeasure.h:66
Definition: propertyref.h:49
T getConvertedValue(T val, const UnitOfMeasure *oldunit, const UnitOfMeasure *newunit)
Definition: unitofmeasure.h:211
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
T userValue(T inp) const
Definition: unitofmeasure.h:189
const char * symbol() const
Definition: unitofmeasure.h:52
Source
Definition: repos.h:25
const UnitOfMeasure * getCurDefaultFor(const char *key) const
Definition: repos.h:25
void addUnitsFromFile(const char *, Repos::Source)
Repos::Source source_
Definition: unitofmeasure.h:110
const SurveyInfo & SI()
void setScaler(const LinScaler &s)
Definition: unitofmeasure.h:58
const UnitOfMeasure * get(PropertyRef::StdType, const char *nm) const
Repos::Source source() const
Definition: unitofmeasure.h:77
PropertyRef::StdType propType() const
Definition: unitofmeasure.h:53
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Object with a name.
Definition: namedobj.h:35
T internalValue(T inp) const
Definition: unitofmeasure.h:172
UnitOfMeasure(const UnitOfMeasure &uom)
Definition: unitofmeasure.h:47
bool write(Repos::Source) const
void getRelevant(PropertyRef::StdType, ObjectSet< const UnitOfMeasure > &) const
LinScaler scaler_
Definition: unitofmeasure.h:108
const LinScaler & scaler() const
Definition: unitofmeasure.h:54
T getUserValueFromSI(T inp) const
Definition: unitofmeasure.h:69
ManagedObjectSet< const UnitOfMeasure > entries
Definition: unitofmeasure.h:159
void setSymbol(const char *s)
Definition: unitofmeasure.h:56
StdType
Definition: propertyref.h:46
const ObjectSet< const UnitOfMeasure > & all() const
Definition: unitofmeasure.h:144
void setPropType(PropertyRef::StdType t)
Definition: unitofmeasure.h:60
BufferString symbol_
Definition: unitofmeasure.h:107
UnitOfMeasure()
Definition: unitofmeasure.h:39
void convValue(T &val, const UnitOfMeasure *oldunit, const UnitOfMeasure *newunit)
Definition: unitofmeasure.h:206
static const char * guessedStdName(const char *)
May return null.
Unit of Measure.
Definition: unitofmeasure.h:35
Linear scaling.
Definition: scaler.h:55
UnitOfMeasureRepository & UoMR()

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019