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 class RDocument;
29 
36 public:
37  //static RS::Unit stringToUnit(const QString& u);
38 
39  static QString formatLinear(double length, RS::Unit unit,
40  RS::LinearFormat format,
41  int prec, bool showUnit=false,
42  bool showLeadingZeroes=true,
43  bool showTrailingZeroes=false,
44  bool onlyPreciseResult=false);
45  static QString formatScientific(double length, RS::Unit unit,
46  int prec, bool showUnit=false,
47  bool showLeadingZeroes=true,
48  bool showTrailingZeroes=false,
49  bool onlyPreciseResult=false);
50  static QString formatDecimal(double length, RS::Unit unit,
51  int prec, bool showUnit=false,
52  bool showLeadingZeroes=true,
53  bool showTrailingZeroes=false,
54  bool onlyPreciseResult=false);
55  static QString formatEngineering(double length, RS::Unit unit,
56  int prec, bool showUnit=false,
57  bool showLeadingZeroes=true,
58  bool showTrailingZeroes=false,
59  bool onlyPreciseResult=false);
60  static QString formatArchitectural(double length, RS::Unit unit,
61  int prec, bool showUnit=false,
62  bool showLeadingZeroes=true,
63  bool showTrailingZeroes=false,
64  bool onlyPreciseResult=false);
65  static QString formatFractional(double length, RS::Unit unit,
66  int prec, bool showUnit=false,
67  bool showLeadingZeroes=true,
68  bool showTrailingZeroes=false,
69  bool onlyPreciseResult=false);
70 
71  static QString formatAngle(double angle, RS::AngleFormat format,
72  int prec,
73  bool showLeadingZeroes=true,
74  bool showTrailingZeroes=false);
75 
76  /*
77  static RVector paperFormatToSize(RS::PaperFormat p);
78  static RS::PaperFormat paperSizeToFormat(const RVector s);
79 
80  static QString paperFormatToString(RS::PaperFormat p);
81  static RS::PaperFormat stringToPaperFormat(const QString& p);
82  */
83 
84  static bool isMetric(RS::Unit unit);
85  static double convert(double value, RS::Unit source, RS::Unit dest);
86  static RVector convert(const RVector& value, RS::Unit source, RS::Unit dest);
87  static double getFactorToM(RS::Unit unit);
88  static RS::Unit parseUnit(const QString& str);
89  static QString unitToSymbol(RS::Unit unit);
90  static QString unitToName(RS::Unit unit, bool tr=true);
91  static QString getLabel(double v, RDocument& document,
92  bool maxPrecision=false,
93  bool forceSuppressTrailingZeroes=false,
94  bool onlyPreciseResult=false);
95 
96  static QString doubleToString(double value, double prec,
97  bool showLeadingZeroes=true, bool showTrailingZeroes=false);
98  static QString doubleToString(double value, int prec,
99  bool showLeadingZeroes=true, bool showTrailingZeroes=false);
100 
101  // workaround: make the second version also accessible by scripts:
102  static QString doubleToStringDec(double value, int prec,
103  bool showLeadingZeroes=true, bool showTrailingZeroes=false) {
104 
105  return doubleToString(value, prec, showLeadingZeroes, showTrailingZeroes);
106  }
107 };
108 
110 
111 #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:102
AngleFormat
Angle format for printing angles.
Definition: RS.h:258
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:274
Conversion methods for units.
Definition: RUnit.h:35
Unit
Enum of supported units (values correspond to DXF spec).
Definition: RS.h:229