QCAD
Open Source 2D CAD
RUnit.h
Go to the documentation of this file.
1 
20 #ifndef RUNIT_H
21 #define RUNIT_H
22 
23 #include "core_global.h"
24 
25 #include "RS.h"
26 #include "RVector.h"
27 
28 #ifndef RDEFAULT_MIN1
29 #define RDEFAULT_MIN1 -1
30 #endif
31 
32 class RDocument;
33 
40 public:
41  //static RS::Unit stringToUnit(const QString& u);
42 
43  static QString formatLinear(double length, RS::Unit unit,
44  RS::LinearFormat format,
45  int prec, bool showUnit=false,
46  bool showLeadingZeroes=true,
47  bool showTrailingZeroes=false,
48  bool onlyPreciseResult=false);
49  static QString formatScientific(double length, RS::Unit unit,
50  int prec, bool showUnit=false,
51  bool showLeadingZeroes=true,
52  bool showTrailingZeroes=false,
53  bool onlyPreciseResult=false);
54  static QString formatDecimal(double length, RS::Unit unit,
55  int prec, bool showUnit=false,
56  bool showLeadingZeroes=true,
57  bool showTrailingZeroes=false,
58  bool onlyPreciseResult=false);
59  static QString formatEngineering(double length, RS::Unit unit,
60  int prec, bool showUnit=false,
61  bool showLeadingZeroes=true,
62  bool showTrailingZeroes=false,
63  bool onlyPreciseResult=false);
64  static QString formatArchitectural(double length, RS::Unit unit,
65  int prec, bool showUnit=false,
66  bool showLeadingZeroes=true,
67  bool showTrailingZeroes=false,
68  bool onlyPreciseResult=false);
69  static QString formatFractional(double length, RS::Unit unit,
70  int prec, bool showUnit=false,
71  bool showLeadingZeroes=true,
72  bool showTrailingZeroes=false,
73  bool onlyPreciseResult=false);
74 
75  static QString formatAngle(double angle, RS::AngleFormat format,
76  int prec,
77  bool showLeadingZeroes=true,
78  bool showTrailingZeroes=false);
79 
80  /*
81  static RVector paperFormatToSize(RS::PaperFormat p);
82  static RS::PaperFormat paperSizeToFormat(const RVector s);
83 
84  static QString paperFormatToString(RS::PaperFormat p);
85  static RS::PaperFormat stringToPaperFormat(const QString& p);
86  */
87 
88  static bool isMetric(RS::Unit unit);
89  static double convert(double value, RS::Unit source, RS::Unit dest);
90  static RVector convert(const RVector& value, RS::Unit source, RS::Unit dest);
91  static double getFactorToM(RS::Unit unit);
92  static RS::Unit parseUnit(const QString& str);
93  static QString unitToSymbol(RS::Unit unit, bool asText=false);
94  static QString unitToName(RS::Unit unit, bool tr=true);
95  static QString getLabel(double v, RDocument& document,
96  int precisionOverride=RDEFAULT_MIN1,
97  bool forceSuppressTrailingZeroes=false,
98  bool onlyPreciseResult=false);
99 
100  static QString doubleToString(double value, double prec,
101  bool showLeadingZeroes=true, bool showTrailingZeroes=false);
102  static QString doubleToString(double value, int prec,
103  bool showLeadingZeroes=true, bool showTrailingZeroes=false);
104 
105  // workaround: make the second version also accessible by scripts:
106  static QString doubleToStringDec(double value, int prec,
107  bool showLeadingZeroes=true, bool showTrailingZeroes=false) {
108 
109  return doubleToString(value, prec, showLeadingZeroes, showTrailingZeroes);
110  }
111 };
112 
114 
115 #endif
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
#define QCADCORE_EXPORT
Definition: core_global.h:10
static QString doubleToStringDec(double value, int prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false)
Definition: RUnit.h:106
AngleFormat
Angle format for printing angles.
Definition: RS.h:260
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
LinearFormat
Format for length values.
Definition: RS.h:276
Conversion methods for units.
Definition: RUnit.h:39
Unit
Enum of supported units (values correspond to DXF spec).
Definition: RS.h:231
#define RDEFAULT_MIN1
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RUnit.h:29