-
-
Notifications
You must be signed in to change notification settings - Fork 557
/
Copy pathgcodeviewparse.cpp
149 lines (125 loc) · 4.22 KB
/
gcodeviewparse.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// This file is a part of "grblControl" application.
// This file was originally ported from "GcodeViewParse.java" class
// of "Universal GcodeSender" application written by Will Winder
// (https://github.com/winder/Universal-G-Code-Sender)
// Copyright 2015 Hayrullin Denis Ravilevich
#include <QDebug>
#include "gcodeviewparse.h"
GcodeViewParse::GcodeViewParse(QObject *parent) :
QObject(parent)
{
absoluteMode = true;
absoluteIJK = false;
currentLine = 0;
debug = true;
m_min = QVector3D(NAN, NAN, NAN);
m_max = QVector3D(NAN, NAN, NAN);
}
GcodeViewParse::~GcodeViewParse()
{
foreach (LineSegment *ls, lines) delete ls;
}
QVector3D GcodeViewParse::getMinimumExtremes()
{
return m_min;
}
QVector3D GcodeViewParse::getMaximumExtremes()
{
return m_max;
}
void GcodeViewParse::testExtremes(QVector3D p3d)
{
this->testExtremes(p3d.x(), p3d.y(), p3d.z());
}
void GcodeViewParse::testExtremes(double x, double y, double z)
{
m_min.setX(Util::nMin(m_min.x(), x));
m_min.setY(Util::nMin(m_min.y(), y));
m_min.setZ(Util::nMin(m_min.z(), z));
m_max.setX(Util::nMax(m_max.x(), x));
m_max.setY(Util::nMax(m_max.y(), y));
m_max.setZ(Util::nMax(m_max.z(), z));
}
QList<LineSegment*> GcodeViewParse::toObjRedux(QList<QString> gcode, double arcPrecision, bool arcDegreeMode)
{
GcodeParser gp;
foreach (QString s, gcode) {
gp.addCommand(s);
}
return getLinesFromParser(&gp, arcPrecision, arcDegreeMode);
}
QList<LineSegment *> GcodeViewParse::getLineSegmentList()
{
return lines;
}
void GcodeViewParse::reset()
{
foreach (LineSegment *ls, lines) delete ls;
lines.clear();
currentLine = 0;
m_min = QVector3D(NAN, NAN, NAN);
m_max = QVector3D(NAN, NAN, NAN);
}
QList<LineSegment *> GcodeViewParse::getLinesFromParser(GcodeParser *gp, double arcPrecision, bool arcDegreeMode)
{
QList<PointSegment*> psl = gp->getPointSegmentList();
// For a line segment list ALL arcs must be converted to lines.
double minArcLength = 0.1;
// Point3d start = null;
// Point3d end = null;
QVector3D *start, *end;
start = NULL;
end = NULL;
LineSegment *ls;
int num = 0;
foreach (PointSegment *segment, psl) {
PointSegment *ps = segment;
bool isMetric = ps->isMetric();
ps->convertToMetric();
end = ps->point();
// start is null for the first iteration.
if (start != NULL) {
// Expand arc for graphics.
if (ps->isArc()) {
QList<QVector3D> points =
GcodePreprocessorUtils::generatePointsAlongArcBDring(ps->plane(),
*start, *end, *ps->center(), ps->isClockwise(), ps->getRadius(), minArcLength, arcPrecision, arcDegreeMode);
// Create line segments from points.
if (points.length() > 0) {
QVector3D startPoint = *start;
foreach (QVector3D nextPoint, points) {
if (nextPoint == startPoint) continue;
ls = new LineSegment(startPoint, nextPoint, num);
ls->setIsArc(ps->isArc());
ls->setIsFastTraverse(ps->isFastTraverse());
ls->setIsZMovement(ps->isZMovement());
ls->setIsMetric(isMetric);
ls->setIsAbsolute(ps->isAbsolute());
ls->setSpeed(ps->getSpeed());
this->testExtremes(nextPoint);
lines.append(ls);
startPoint = nextPoint;
}
num++;
}
// Line
} else {
ls = new LineSegment(*start, *end, num++);
ls->setIsArc(ps->isArc());
ls->setIsFastTraverse(ps->isFastTraverse());
ls->setIsZMovement(ps->isZMovement());
ls->setIsMetric(isMetric);
ls->setIsAbsolute(ps->isAbsolute());
ls->setSpeed(ps->getSpeed());
this->testExtremes(*end);
lines.append(ls);
}
}
start = end;
}
return lines;
}
QList<LineSegment *> *GcodeViewParse::getLines()
{
return &lines;
}