QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
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#ifndef RDEFAULT_DOT
33#define RDEFAULT_DOT '.'
34#endif
35
36class RDocument;
37
44public:
45 //static RS::Unit stringToUnit(const QString& u);
46
47 static QString formatLinear(double length, RS::Unit unit,
48 RS::LinearFormat format,
49 int prec, bool showUnit=false,
50 bool showLeadingZeroes=true,
51 bool showTrailingZeroes=false,
52 bool onlyPreciseResult=false,
53 char decimalSeparator=RDEFAULT_DOT);
54 static QString formatScientific(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 formatDecimal(double length, RS::Unit unit,
60 int prec, bool showUnit=false,
61 bool showLeadingZeroes=true,
62 bool showTrailingZeroes=false,
63 bool onlyPreciseResult=false,
64 char decimalSeparator=RDEFAULT_DOT);
65 static QString formatEngineering(double length, RS::Unit unit,
66 int prec, bool showUnit=false,
67 bool showLeadingZeroes=true,
68 bool showTrailingZeroes=false,
69 bool onlyPreciseResult=false);
70 static QString formatArchitectural(double length, RS::Unit unit,
71 int prec, bool showUnit=false,
72 bool showLeadingZeroes=true,
73 bool showTrailingZeroes=false,
74 bool onlyPreciseResult=false);
75 static QString formatFractional(double length, RS::Unit unit,
76 int prec, bool showUnit=false,
77 bool showLeadingZeroes=true,
78 bool showTrailingZeroes=false,
79 bool onlyPreciseResult=false);
80
81 static QString formatAngle(double angle, RS::AngleFormat format,
82 int prec,
83 bool showLeadingZeroes=true,
84 bool showTrailingZeroes=false,
85 char decimalSeparator=RDEFAULT_DOT);
86
87 /*
88 static RVector paperFormatToSize(RS::PaperFormat p);
89 static RS::PaperFormat paperSizeToFormat(const RVector s);
90
91 static QString paperFormatToString(RS::PaperFormat p);
92 static RS::PaperFormat stringToPaperFormat(const QString& p);
93 */
94
95 static bool isMetric(RS::Unit unit);
96 static double convert(double value, RS::Unit source, RS::Unit dest);
97 static RVector convert(const RVector& value, RS::Unit source, RS::Unit dest);
98 static double getFactorToM(RS::Unit unit);
99 static RS::Unit parseUnit(const QString& str);
100 static QString unitToSymbol(RS::Unit unit, bool asText=false);
101 static QString unitToName(RS::Unit unit, bool tr=true);
102 static QString getLabel(double v, RDocument& document,
103 int precisionOverride=RDEFAULT_MIN1,
104 bool forceSuppressTrailingZeroes=false,
105 bool onlyPreciseResult=false,
106 char decimalSeparator=RDEFAULT_DOT);
107
108 static QString doubleToString(double value, double prec,
109 bool showLeadingZeroes=true, bool showTrailingZeroes=false,
110 char decimalSeparator=RDEFAULT_DOT);
111 static QString doubleToString(double value, int prec,
112 bool showLeadingZeroes=true, bool showTrailingZeroes=false,
113 char decimalSeparator=RDEFAULT_DOT);
114
115 // workaround: make the second version also accessible by scripts:
116 static QString doubleToStringDec(double value, int prec,
117 bool showLeadingZeroes=true, bool showTrailingZeroes=false,
118 char decimalSeparator=RDEFAULT_DOT) {
119
120 return doubleToString(value, prec, showLeadingZeroes, showTrailingZeroes, decimalSeparator);
121 }
122};
123
125
126#endif
#define RDEFAULT_MIN1
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RExplodable.h:30
Q_DECLARE_METATYPE(RMath *)
#define RDEFAULT_DOT
Definition RUnit.h:33
A graphics document contains and owns entities, layers, user coordinate systems, variables,...
Definition RDocument.h:78
AngleFormat
Angle format for printing angles.
Definition RS.h:454
LinearFormat
Format for length values.
Definition RS.h:470
Unit
Enum of supported units (values correspond to DXF spec).
Definition RS.h:425
Conversion methods for units.
Definition RUnit.h:43
static QString doubleToStringDec(double value, int prec, bool showLeadingZeroes=true, bool showTrailingZeroes=false, char decimalSeparator=RDEFAULT_DOT)
Definition RUnit.h:116
Represents a 3d vector (x/y/z).
Definition RVector.h:47
#define QCADCORE_EXPORT
Definition core_global.h:10