-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunitutilities.cpp
47 lines (41 loc) · 1003 Bytes
/
unitutilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "unitutilities.h"
#include <QString>
qreal UnitUtilities::milToMm(qreal mil)
{
return mil * 0.0254;
}
qreal UnitUtilities::inchToMm(qreal inch)
{
return inch * 25.4;
}
qreal UnitUtilities::stringToMm(const QString &val)
{
qreal ret = 0;
if (val.endsWith("mil")) {
bool ok = false;
ret = val.left(val.length() - 3).toDouble(&ok);
if (!ok)
ret = 0;
else
ret = milToMm(ret);
} else if (val.endsWith("inch")) {
bool ok = false;
ret = val.left(val.length() - 4).toDouble(&ok);
if (!ok)
ret = 0;
else
ret = milToMm(ret);
} else {
bool ok = false;
ret = val.toDouble(&ok);
if (!ok)
ret = 0;
}
return ret;
}
int UnitUtilities::mmToU(const qreal mm)
{
// EAGLE stores all coordinate and size values as int values with a
// resolution of 1/320000mm (0.003125µ).
return static_cast<int>(mm * 32000.0);
}