-
-
Notifications
You must be signed in to change notification settings - Fork 557
/
Copy pathpointsegment.cpp
222 lines (179 loc) · 5.65 KB
/
pointsegment.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// This file is a part of "grblControl" application.
// This file was originally ported from "PointSegment.java" class
// of "Universal GcodeSender" application written by Will Winder
// (https://github.com/winder/Universal-G-Code-Sender)
// Copyright 2015 Hayrullin Denis Ravilevich
#include <QVector>
#include "pointsegment.h"
PointSegment::PointSegment(QObject *parent) : QObject(parent)
{
m_toolhead = 0;
m_isMetric = true;
m_isAbsolute = true;
m_isZMovement = false;
m_isArc = false;
m_isFastTraverse = false;
m_lineNumber = -1;
m_arcProperties = NULL;
m_speed = 0;
m_plane = XY;
}
PointSegment::PointSegment(PointSegment *ps) : PointSegment(ps->point(), ps->getLineNumber())
{
this->setToolHead(ps->getToolhead());
this->setSpeed(ps->getSpeed());
this->setIsMetric(ps->isMetric());
this->setIsZMovement(ps->isZMovement());
this->setIsFastTraverse(ps->isFastTraverse());
this->setIsAbsolute(ps->isAbsolute());
if (ps->isArc()) {
this->setArcCenter(ps->center());
this->setRadius(ps->getRadius());
this->setIsClockwise(ps->isClockwise());
this->setPlane(ps->plane());
}
}
PointSegment::PointSegment(const QVector3D *b, int num) : PointSegment()
{
this->m_point = new QVector3D(b->x(), b->y(), b->z());
this->m_lineNumber = num;
}
PointSegment::PointSegment(QVector3D *point, int num, QVector3D *center, double radius, bool clockwise) : PointSegment(point, num)
{
this->m_isArc = true;
this->m_arcProperties = new ArcProperties();
this->m_arcProperties->center = new QVector3D(center->x(), center->y(), center->z());
this->m_arcProperties->radius = radius;
this->m_arcProperties->isClockwise = clockwise;
}
PointSegment::~PointSegment()
{
if (this->m_arcProperties != NULL && this->m_arcProperties->center != NULL) delete this->m_arcProperties->center;
if (this->m_arcProperties != NULL) delete this->m_arcProperties;
if (this->m_point != NULL) delete this->m_point;
}
void PointSegment::setPoint(QVector3D point) {
this->m_point = new QVector3D(point.x(), point.y(), point.z());
}
QVector3D *PointSegment::point()
{
return m_point;
}
QVector<double> PointSegment::points()
{
QVector<double> points;
points.append(m_point->x());
points.append(m_point->y());
return points;
}
void PointSegment::setToolHead(int head) {
this->m_toolhead = head;
}
int PointSegment::getToolhead()
{
return m_toolhead;
}
void PointSegment::setLineNumber(int num) {
this->m_lineNumber = num;
}
int PointSegment::getLineNumber() {
return m_lineNumber;
}
void PointSegment::setSpeed(double s) {
this->m_speed = s;
}
double PointSegment::getSpeed()
{
return m_speed;
}
void PointSegment::setIsZMovement(bool isZ) {
this->m_isZMovement = isZ;
}
bool PointSegment::isZMovement() {
return m_isZMovement;
}
void PointSegment::setIsMetric(bool isMetric) {
this->m_isMetric = isMetric;
}
bool PointSegment::isMetric() {
return m_isMetric;
}
void PointSegment::setIsArc(bool isA) {
this->m_isArc = isA;
}
bool PointSegment::isArc() {
return m_isArc;
}
void PointSegment::setIsFastTraverse(bool isF) {
this->m_isFastTraverse = isF;
}
bool PointSegment::isFastTraverse() {
return m_isFastTraverse;
}
// Arc properties.
void PointSegment::setArcCenter(QVector3D *center) {
if (this->m_arcProperties == NULL) this->m_arcProperties = new ArcProperties();
this->m_arcProperties->center = new QVector3D(center->x(), center->y(), center->z());
this->setIsArc(true);
}
QVector<double> PointSegment::centerPoints()
{
QVector<double> points;
if (this->m_arcProperties != NULL && this->m_arcProperties->center != NULL) {
points.append(m_arcProperties->center->x());
points.append(m_arcProperties->center->y());
points.append(m_arcProperties->center->z());
}
return points;
}
QVector3D *PointSegment::center() {
if (this->m_arcProperties != NULL && this->m_arcProperties->center != NULL) return this->m_arcProperties->center;
return NULL;
}
void PointSegment::setIsClockwise(bool clockwise) {
if (this->m_arcProperties == NULL) this->m_arcProperties = new ArcProperties();
this->m_arcProperties->isClockwise = clockwise;
}
bool PointSegment::isClockwise() {
if (this->m_arcProperties != NULL && this->m_arcProperties->center != NULL) return this->m_arcProperties->isClockwise;
return false;
}
void PointSegment::setRadius(double rad) {
if (this->m_arcProperties == NULL) this->m_arcProperties = new ArcProperties();
this->m_arcProperties->radius = rad;
}
double PointSegment::getRadius() {
if (this->m_arcProperties != NULL && this->m_arcProperties->center != NULL) return this->m_arcProperties->radius;
return 0;
}
void PointSegment::convertToMetric() {
if (this->m_isMetric) {
return;
}
this->m_isMetric = true;
this->m_point->setX(this->m_point->x() * 25.4);
this->m_point->setY(this->m_point->y() * 25.4);
this->m_point->setZ(this->m_point->z() * 25.4);
if (this->m_isArc && this->m_arcProperties != NULL) {
this->m_arcProperties->center->setX(this->m_arcProperties->center->x() * 25.4);
this->m_arcProperties->center->setY(this->m_arcProperties->center->y() * 25.4);
this->m_arcProperties->center->setZ(this->m_arcProperties->center->z() * 25.4);
this->m_arcProperties->radius *= 25.4;
}
}
bool PointSegment::isAbsolute() const
{
return m_isAbsolute;
}
void PointSegment::setIsAbsolute(bool isAbsolute)
{
m_isAbsolute = isAbsolute;
}
PointSegment::planes PointSegment::plane() const
{
return m_plane;
}
void PointSegment::setPlane(const planes &plane)
{
m_plane = plane;
}