CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
OdUnitsFormatter.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _OD_UNITSFORMATTER_H_INCLUDED_
25#define _OD_UNITSFORMATTER_H_INCLUDED_
26
27#include "OdPlatform.h"
28#include "RxObject.h"
29#include "OdString.h"
30#include "OdDToStr.h"
31#include "SharedPtr.h"
32
33class OdCmColorBase;
34class OdGePoint3d;
35
57
62{
63public:
65
66 enum LUnits
67 {
70 kEngineering = 3, // feet and decimal inches
71 kArchitectural = 4, // feet and fractional inches
74 };
75
101
106 virtual OdString formatCmColor(const OdCmColorBase& value) const = 0;
107
112 virtual OdSharedPtr<OdCmColorBase> unformatCmColor(const OdString& string) const = 0;
113
120 virtual OdString formatLinear(double value) const = 0;
121
128 virtual double unformatLinear(const OdString& string) const = 0;
129
138 virtual OdString formatAngle(double value) const = 0;
139
148 virtual double unformatAngle(const OdString& string) const = 0;
149
155 static bool isZeroFeetSuppressed(int dimzin);
156
162 static bool isZeroInchesSuppressed(int dimzin);
163
169 static bool isZeroFeetSuppressed2(int dimzin);
170
176 static bool isZeroInchesSuppressed2(int dimzin);
177
195 static OdString formatL(double value, LUnits lUnits, int precision, int dimzin, int unitMode, const OdChar* decsep = 0, const OdChar* thsep = 0, bool useStdRound = true);
196
211 static OdString formatArea(double value, LUnits lUnits, int precision, int dimzin, int unitMode, const OdChar* decsep = 0, const OdChar* thsep = 0);
212
217 static double unformatL(const OdString& string);
218
220 {
226 };
227
246
261 static OdString formatA(double value, AUnits aUnits, int precision, int dimazin, int unitMode, const OdChar* decsep = 0);
262
278 static OdString formatA_unnorm(double value, AUnits aUnits, int precision, int dimazin, int unitMode, const OdChar* decsep = 0);
279
287 static double unformatA(const OdString& string);
288
298 static double unformatA_unnorm(const OdString& string, bool refuseDots = false);
299
300private:
301 static void roundValue(double& value, int precision);
302 static OdString _formatL(double value, bool isItArea, LUnits lUnits, int precision, int dimzin, int unitMode, const OdChar* decsep = 0, const OdChar* thsep = 0, bool useStdRound = true);
303 static OdString _formatA(double value, AUnits aUnits, int precision, int dimazin, int unitMode, const OdChar* decsep = 0);
304};
305
310
311
318{
319public:
322
323 static OdString formatDecimal(double value, int precision, int dimzin, const OdChar* decsep, const OdChar* thsep = 0);
324 static double angle(const OdChar*& buf, bool refuseDots = false);
325 static int toInt(const OdString& sValue, int nMinValid = INT_MIN, int nMaxValid = INT_MAX);
326 static bool isZero(double v, int precision);
327 static OdString formatArchitectural(bool isNegative, int feet, int entier, int numerator, int denominator, int dimzin, int mode);
328 static bool negative(const OdChar*& buf);
329 static double integer(const OdChar*& buf);
330 static double number(const OdChar*& buf, bool* pHasDot = 0, bool* pHasExponent = 0);
331 static void fraction(double value, int& entier, int& numerator, int& denominator, int precision)
332 {
333 denominator = 1 << precision;
334 value = double(floor(value * denominator + 0.5)) / double(denominator);
335 entier = int(floor(value));
336 numerator = int((value - entier) * double(denominator));
337 while((numerator % 2) == 0 && (numerator != 0))
338 {
339 numerator /= 2;
340 denominator /= 2;
341 }
342 }
343
344 static double base_denominator(int prec, double base)
345 {
346 double denom = 1.;
347 for(int i = 0; i < prec; ++i)
348 denom *= base;
349 return denom;
350 }
351
352 static double linear_denominator(int prec)
353 {
354 return base_denominator(prec, 10.);
355 }
356
357 static bool digit(OdChar c)
358 {
359 return (c >= '0' && c <= '9');
360 }
361
362 static double denominator(int prec)
363 {
364 double denom = 1.;
365 switch(prec)
366 {
367 default:
368 {
369 for(int i = prec; i >= 5; i--)
370 denom *= 10.;
371 }
372 //case 8: // 19d58'58.8889"
373 // denom *= 10;
374 //case 7: // 19d58'58.889"
375 // denom *= 10;
376 //case 6: // 19d58'58.89"
377 // denom *= 10;
378 //case 5: // 19d58'58.9"
379 // denom *= 10;
380 case 4: // 19d58'59"
381 case 3:
382 denom *= 60;
383 case 2: // 19d59'
384 case 1:
385 denom *= 60;
386 case 0: // 20d
387 break;
388 }
389 return denom;
390 }
391
392 static void decomp(double v, int& degs, int& mins, double& secs, int prec);
393
394 static OdString format(int degs, int mins, double secs, int prec)
395 {
396 OdString res;
397 switch (prec)
398 {
399 case 0:
400 res.format(OD_T("%dd"), degs);
401 break;
402 case 1:
403 case 2:
404 res.format(OD_T("%dd%d'"), degs, mins);
405 break;
406 case 3:
407 prec = 4;
408 // no break
409 default:
410 prec -= 4;
411 OdString s = odDToStr(secs, 'f', prec);
412 res.format(OD_T("%dd%d'%ls\""), degs, mins, s.c_str());
413 break;
414 }
415
416 return res;
417 }
418
419 static OdString next(OdString& list, const OdChar* delim = OD_T(","))
420 {
421 OdString res = list.spanExcluding(delim);
422 if(res.getLength() != list.getLength())
423 {
424 list = list.mid(res.getLength()+1);
425 }
426 else
427 {
428 list.empty();
429 }
430 return res;
431 }
432
433 static int countOccurences(const OdString& string, OdChar delim = ',')
434 {
435 int nOccurences = 0;
436 int nDigits = 0;
437 int nSpec = 0;
438 const OdChar *pBuffer = string.c_str();
439 while (*pBuffer)
440 {
441 if (*pBuffer >= '0' && *pBuffer <= '9')
442 nDigits++;
443 else if (*pBuffer == '+' || *pBuffer == '-')
444 {
445 nSpec++;
446 if (nDigits > 0)
447 break;
448 }
449 else if (*pBuffer == delim && nDigits > 0 && nSpec <= 1)
450 {
451 nDigits = nSpec = 0;
452 nOccurences++;
453 }
454 else
455 break;
456 pBuffer++;
457 }
458 return nOccurences;
459 }
460};
461
462#endif //#ifndef _OD_UNITSFORMATTER_H_INCLUDED_
FIRSTDLL_EXPORT void odDToStr(char *dst, double val, char fmt, int prec, int cropzeros=0)
#define OD_T(x)
#define ODRX_ABSTRACT
wchar_t OdChar
OdSmartPtr< OdUnitsFormatter > OdUnitsFormatterPtr
#define FIRSTDLL_EXPORT
Definition RootExport.h:39
OdString mid(int startIndex, int length) const
OdString & format(const OdChar *formatString,...)
void empty()
const OdChar * c_str() const
Definition OdString.h:205
OdString spanExcluding(const OdChar *charSet) const
int getLength() const
Definition OdString.h:135
virtual OdSharedPtr< OdCmColorBase > unformatCmColor(const OdString &string) const =0
static bool isZeroFeetSuppressed2(int dimzin)
virtual OdString formatLinear(double value) const =0
virtual double unformatAngle(const OdString &string) const =0
static OdString formatA_unnorm(double value, AUnits aUnits, int precision, int dimazin, int unitMode, const OdChar *decsep=0)
static OdString formatArea(double value, LUnits lUnits, int precision, int dimzin, int unitMode, const OdChar *decsep=0, const OdChar *thsep=0)
virtual OdString formatCmColor(const OdCmColorBase &value) const =0
static OdString formatL(double value, LUnits lUnits, int precision, int dimzin, int unitMode, const OdChar *decsep=0, const OdChar *thsep=0, bool useStdRound=true)
static double unformatA_unnorm(const OdString &string, bool refuseDots=false)
static bool isZeroInchesSuppressed2(int dimzin)
static bool isZeroFeetSuppressed(int dimzin)
static double unformatA(const OdString &string)
virtual double unformatLinear(const OdString &string) const =0
ODRX_DECLARE_MEMBERS(OdUnitsFormatter)
virtual OdString formatAngle(double value) const =0
static double unformatL(const OdString &string)
static OdString formatA(double value, AUnits aUnits, int precision, int dimazin, int unitMode, const OdChar *decsep=0)
static bool isZeroInchesSuppressed(int dimzin)
static OdString formatArchitectural(bool isNegative, int feet, int entier, int numerator, int denominator, int dimzin, int mode)
static double integer(const OdChar *&buf)
static int countOccurences(const OdString &string, OdChar delim=',')
static void fraction(double value, int &entier, int &numerator, int &denominator, int precision)
static OdString next(OdString &list, const OdChar *delim=OD_T(","))
static double number(const OdChar *&buf, bool *pHasDot=0, bool *pHasExponent=0)
static OdString formatDecimal(double value, int precision, int dimzin, const OdChar *decsep, const OdChar *thsep=0)
static double denominator(int prec)
static double base_denominator(int prec, double base)
static void decomp(double v, int &degs, int &mins, double &secs, int prec)
static bool digit(OdChar c)
static double linear_denominator(int prec)
static OdString format(int degs, int mins, double secs, int prec)
static bool isZero(double v, int precision)
static int toInt(const OdString &sValue, int nMinValid=INT_MIN, int nMaxValid=INT_MAX)
static bool negative(const OdChar *&buf)
static double angle(const OdChar *&buf, bool refuseDots=false)
static FeetInchesProcessing getFeetInchesProcessing()
static void setFeetInchesProcessing(FeetInchesProcessing type)
const GLfloat * v
Definition gles2_ext.h:315
GLuint GLsizei GLsizei GLint GLenum * type
Definition gles2_ext.h:274
GLenum GLint GLint * precision
Definition gles2_ext.h:563
GLsizei const GLfloat * value
Definition gles2_ext.h:302