Skip to content

Commit 94f20c5

Browse files
committed
Settings updated
1 parent 1b8a2f2 commit 94f20c5

File tree

6 files changed

+171
-287
lines changed

6 files changed

+171
-287
lines changed

src/drawers/gcodedrawer.cpp

+64-15
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ GcodeDrawer::GcodeDrawer() : QObject()
77
{
88
m_geometryUpdated = false;
99
m_pointSize = 6;
10-
m_ignoreZ = true;
11-
m_colorizeSegments = true;
12-
m_colorizeType = GcodeDrawer::S;
10+
m_ignoreZ = false;
11+
m_grayscaleSegments = false;
12+
m_grayscaleCode = GcodeDrawer::S;
13+
m_grayscaleMin = 0;
14+
m_grayscaleMax = 255;
1315

1416
connect(&m_timerVertexUpdate, SIGNAL(timeout()), SLOT(onTimerVertexUpdate()));
1517
m_timerVertexUpdate.start(100);
@@ -48,7 +50,7 @@ bool GcodeDrawer::updateData()
4850
for (int i = 0; i < list->count(); i++) {
4951

5052
if (qIsNaN(list->at(i)->getEnd().z())) {
51-
qDebug() << "nan point" << list->at(i)->getEnd();
53+
// qDebug() << "nan point" << list->at(i)->getEnd();
5254
continue;
5355
}
5456

@@ -60,6 +62,7 @@ bool GcodeDrawer::updateData()
6062
// Draw first toolpath point
6163
vertex.color = Util::colorToVector(m_colorStart);
6264
vertex.position = list->at(i)->getEnd();
65+
if (m_ignoreZ) vertex.position.setZ(0);
6366
vertex.start = QVector3D(sNan, sNan, m_pointSize);
6467
m_points.append(vertex);
6568

@@ -100,16 +103,19 @@ bool GcodeDrawer::updateData()
100103

101104
// Line start
102105
vertex.position = list->at(j)->getStart();
106+
if (m_ignoreZ) vertex.position.setZ(0);
103107
m_lines.append(vertex);
104108

105109
// Line end
106110
vertex.position = list->at(i)->getEnd();
111+
if (m_ignoreZ) vertex.position.setZ(0);
107112
m_lines.append(vertex);
108113

109114
// Draw last toolpath point
110115
if (i == list->count() - 1) {
111116
vertex.color = Util::colorToVector(m_colorEnd);
112117
vertex.position = list->at(i)->getEnd();
118+
if (m_ignoreZ) vertex.position.setZ(0);
113119
vertex.start = QVector3D(sNan, sNan, m_pointSize);
114120
m_points.append(vertex);
115121
}
@@ -128,7 +134,7 @@ bool GcodeDrawer::updateData()
128134
int vertexIndexLast = qMax(list.at(*mm.second)->vertexIndex(), 0);
129135
int vertexCount = (vertexIndexLast - vertexIndexFirst) + 2;
130136

131-
qDebug() << "updating vertices" << vertexIndexFirst << vertexIndexLast << vertexCount;
137+
// qDebug() << "updating vertices" << vertexIndexFirst << vertexIndexLast << vertexCount;
132138

133139
// Allocate buffer
134140
VertexData *data = (VertexData*)malloc(vertexCount * sizeof(VertexData));
@@ -174,14 +180,11 @@ QVector3D GcodeDrawer::getSegmentColor(LineSegment *segment)
174180
else if (segment->isHightlight()) return Util::colorToVector(m_colorHighlight);//QVector3D(0.57, 0.51, 0.9);
175181
else if (segment->isFastTraverse()) return Util::colorToVector(m_colorNormal);// QVector3D(0.0, 0.0, 0.0);
176182
else if (segment->isZMovement()) return Util::colorToVector(m_colorZMovement);//QVector3D(1.0, 0.0, 0.0);
177-
else if (m_colorizeSegments) switch (m_colorizeType) {
178-
case ColorizeType::S:
179-
return Util::colorToVector(QColor::fromHsl(0, 0, 255 - segment->getSpindleSpeed()));
180-
case ColorizeType::Z:
181-
return Util::colorToVector(QColor::fromHsl(0, 0, 255 - segment->getStart().z()));
182-
case ColorizeType::P:
183-
return Util::colorToVector(QColor::fromHsl(0, 0, 255 - segment->getDwell()));
184-
break;
183+
else if (m_grayscaleSegments) switch (m_grayscaleCode) {
184+
case GrayscaleCode::S:
185+
return Util::colorToVector(QColor::fromHsl(0, 0, qBound<int>(0, 255 - 255 / (m_grayscaleMax - m_grayscaleMin) * segment->getSpindleSpeed(), 255)));
186+
case GrayscaleCode::Z:
187+
return Util::colorToVector(QColor::fromHsl(0, 0, qBound<int>(0, 255 - 255 / (m_grayscaleMax - m_grayscaleMin) * segment->getStart().z(), 255)));
185188
}
186189
return Util::colorToVector(m_colorNormal);//QVector3D(0.0, 0.0, 0.0);
187190
}
@@ -201,12 +204,18 @@ QVector3D GcodeDrawer::getSizes()
201204

202205
QVector3D GcodeDrawer::getMinimumExtremes()
203206
{
204-
return m_viewParser->getMinimumExtremes();;
207+
QVector3D v = m_viewParser->getMinimumExtremes();
208+
if (m_ignoreZ) v.setZ(0);
209+
210+
return v;
205211
}
206212

207213
QVector3D GcodeDrawer::getMaximumExtremes()
208214
{
209-
return m_viewParser->getMaximumExtremes();;
215+
QVector3D v = m_viewParser->getMaximumExtremes();
216+
if (m_ignoreZ) v.setZ(0);
217+
218+
return v;
210219
}
211220

212221
void GcodeDrawer::setViewParser(GcodeViewParse* viewParser)
@@ -313,6 +322,46 @@ void GcodeDrawer::onTimerVertexUpdate()
313322
if (!m_indexes.isEmpty()) ShaderDrawable::update();
314323
}
315324

325+
int GcodeDrawer::grayscaleMax() const
326+
{
327+
return m_grayscaleMax;
328+
}
329+
330+
void GcodeDrawer::setGrayscaleMax(int grayscaleMax)
331+
{
332+
m_grayscaleMax = grayscaleMax;
333+
}
334+
335+
int GcodeDrawer::grayscaleMin() const
336+
{
337+
return m_grayscaleMin;
338+
}
339+
340+
void GcodeDrawer::setGrayscaleMin(int grayscaleMin)
341+
{
342+
m_grayscaleMin = grayscaleMin;
343+
}
344+
345+
GcodeDrawer::GrayscaleCode GcodeDrawer::grayscaleCode() const
346+
{
347+
return m_grayscaleCode;
348+
}
349+
350+
void GcodeDrawer::setGrayscaleCode(const GrayscaleCode &grayscaleCode)
351+
{
352+
m_grayscaleCode = grayscaleCode;
353+
}
354+
355+
bool GcodeDrawer::getGrayscaleSegments() const
356+
{
357+
return m_grayscaleSegments;
358+
}
359+
360+
void GcodeDrawer::setGrayscaleSegments(bool grayscaleSegments)
361+
{
362+
m_grayscaleSegments = grayscaleSegments;
363+
}
364+
316365

317366

318367

src/drawers/gcodedrawer.h

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GcodeDrawer : public QObject, public ShaderDrawable
1414
{
1515
Q_OBJECT
1616
public:
17-
enum ColorizeType { S, Z, P };
17+
enum GrayscaleCode { S, Z };
1818

1919
explicit GcodeDrawer();
2020

@@ -58,6 +58,18 @@ class GcodeDrawer : public QObject, public ShaderDrawable
5858
bool getIgnoreZ() const;
5959
void setIgnoreZ(bool ignoreZ);
6060

61+
bool getGrayscaleSegments() const;
62+
void setGrayscaleSegments(bool grayscaleSegments);
63+
64+
GrayscaleCode grayscaleCode() const;
65+
void setGrayscaleCode(const GrayscaleCode &grayscaleCode);
66+
67+
int grayscaleMin() const;
68+
void setGrayscaleMin(int grayscaleMin);
69+
70+
int grayscaleMax() const;
71+
void setGrayscaleMax(int grayscaleMax);
72+
6173
signals:
6274

6375
public slots:
@@ -71,8 +83,10 @@ private slots:
7183
double m_simplifyPrecision;
7284

7385
bool m_ignoreZ;
74-
bool m_colorizeSegments;
75-
ColorizeType m_colorizeType;
86+
bool m_grayscaleSegments;
87+
GrayscaleCode m_grayscaleCode;
88+
int m_grayscaleMin;
89+
int m_grayscaleMax;
7690

7791
bool m_geometryUpdated;
7892

src/frmmain.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ void frmMain::loadSettings()
239239
m_settings.setZBuffer(set.value("zBuffer", false).toBool());
240240
m_settings.setSimplify(set.value("simplify", false).toBool());
241241
m_settings.setSimplifyPrecision(set.value("simplifyPrecision", 0).toDouble());
242+
m_settings.setGrayscaleSegments(set.value("grayscaleSegments", false).toBool());
243+
m_settings.setGrayscaleSCode(set.value("grayscaleSCode", true).toBool());
244+
m_settings.setIgnoreZ(set.value("ignoreZ", false).toBool());
242245
ui->txtJogStep->setValue(set.value("jogStep", 1).toDouble());
243246
m_programSpeed = true;
244247
ui->sliSpindleSpeed->setValue(set.value("spindleSpeed", 0).toInt());
@@ -253,6 +256,8 @@ void frmMain::loadSettings()
253256
m_settings.setShowUICommands(set.value("showUICommands", 0).toBool());
254257
m_settings.setSpindleSpeedMin(set.value("spindleSpeedMin", 0).toInt());
255258
m_settings.setSpindleSpeedMax(set.value("spindleSpeedMax", 100).toInt());
259+
m_settings.setLaserPowerMin(set.value("laserPowerMin", 0).toInt());
260+
m_settings.setLaserPowerMax(set.value("laserPowerMax", 100).toInt());
256261
m_settings.setRapidSpeed(set.value("rapidSpeed", 0).toInt());
257262
m_settings.setHeightmapProbingFeed(set.value("heightmapProbingFeed", 0).toInt());
258263
m_settings.setAcceleration(set.value("acceleration", 10).toInt());
@@ -357,6 +362,9 @@ void frmMain::saveSettings()
357362
set.setValue("zBuffer", m_settings.zBuffer());
358363
set.setValue("simplify", m_settings.simplify());
359364
set.setValue("simplifyPrecision", m_settings.simplifyPrecision());
365+
set.setValue("grayscaleSegments", m_settings.grayscaleSegments());
366+
set.setValue("grayscaleSCode", m_settings.grayscaleSCode());
367+
set.setValue("ignoreZ", m_settings.ignoreZ());
360368
set.setValue("jogStep", ui->txtJogStep->value());
361369
set.setValue("spindleSpeed", ui->txtSpindleSpeed->text());
362370
set.setValue("lineWidth", m_settings.lineWidth());
@@ -367,6 +375,8 @@ void frmMain::saveSettings()
367375
set.setValue("showUICommands", m_settings.showUICommands());
368376
set.setValue("spindleSpeedMin", m_settings.spindleSpeedMin());
369377
set.setValue("spindleSpeedMax", m_settings.spindleSpeedMax());
378+
set.setValue("laserPowerMin", m_settings.laserPowerMin());
379+
set.setValue("laserPowerMax", m_settings.laserPowerMax());
370380
set.setValue("moveOnRestore", m_settings.moveOnRestore());
371381
set.setValue("restoreMode", m_settings.restoreMode());
372382
set.setValue("rapidSpeed", m_settings.rapidSpeed());
@@ -1576,8 +1586,8 @@ QTime frmMain::updateProgramEstimatedTime(QList<LineSegment*> lines)
15761586
// ? (ls->getSpeed() * ui->txtFeed->value() / 100) : ls->getSpeed())
15771587
// << time;
15781588

1579-
if (qIsNaN(length)) qDebug() << "length nan:" << i << ls->getLineNumber() << ls->getStart() << ls->getEnd();
1580-
if (qIsNaN(ls->getSpeed())) qDebug() << "speed nan:" << ls->getSpeed();
1589+
// if (qIsNaN(length)) qDebug() << "length nan:" << i << ls->getLineNumber() << ls->getStart() << ls->getEnd();
1590+
// if (qIsNaN(ls->getSpeed())) qDebug() << "speed nan:" << ls->getSpeed();
15811591
}
15821592

15831593
time *= 60;
@@ -1870,6 +1880,11 @@ void frmMain::applySettings() {
18701880
m_codeDrawer->setColorZMovement(m_settings.colors("ToolpathZMovement"));
18711881
m_codeDrawer->setColorStart(m_settings.colors("ToolpathStart"));
18721882
m_codeDrawer->setColorEnd(m_settings.colors("ToolpathEnd"));
1883+
m_codeDrawer->setIgnoreZ(m_settings.ignoreZ());
1884+
m_codeDrawer->setGrayscaleSegments(m_settings.grayscaleSegments());
1885+
m_codeDrawer->setGrayscaleCode(m_settings.grayscaleSCode() ? GcodeDrawer::S : GcodeDrawer::Z);
1886+
m_codeDrawer->setGrayscaleMin(m_settings.laserPowerMin());
1887+
m_codeDrawer->setGrayscaleMax(m_settings.laserPowerMax());
18731888
m_codeDrawer->update();
18741889

18751890
// Adapt visualizer buttons colors

src/frmsettings.cpp

+57-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,26 @@ void frmSettings::setSpindleSpeedMax(int speed)
290290
ui->txtSpindleSpeedMax->setValue(speed);
291291
}
292292

293+
int frmSettings::laserPowerMin()
294+
{
295+
return ui->txtLaserPowerMin->value();
296+
}
297+
298+
void frmSettings::setLaserPowerMin(int value)
299+
{
300+
ui->txtLaserPowerMin->setValue(value);
301+
}
302+
303+
int frmSettings::laserPowerMax()
304+
{
305+
return ui->txtLaserPowerMax->value();
306+
}
307+
308+
void frmSettings::setLaserPowerMax(int value)
309+
{
310+
ui->txtLaserPowerMax->setValue(value);
311+
}
312+
293313
int frmSettings::rapidSpeed()
294314
{
295315
return ui->txtRapidSpeed->value();
@@ -491,6 +511,37 @@ void frmSettings::setFontSize(int fontSize)
491511
ui->cboFontSize->setCurrentText(QString::number(fontSize));
492512
}
493513

514+
bool frmSettings::grayscaleSegments()
515+
{
516+
return ui->chkGrayscale->isChecked();
517+
}
518+
519+
void frmSettings::setGrayscaleSegments(bool value)
520+
{
521+
ui->chkGrayscale->setChecked(value);
522+
}
523+
524+
bool frmSettings::grayscaleSCode()
525+
{
526+
return ui->radGrayscaleS->isChecked();
527+
}
528+
529+
void frmSettings::setGrayscaleSCode(bool value)
530+
{
531+
ui->radGrayscaleS->setChecked(value);
532+
ui->radGrayscaleZ->setChecked(!value);
533+
}
534+
535+
bool frmSettings::ignoreZ()
536+
{
537+
return ui->chkIgnoreZ->isChecked();
538+
}
539+
540+
void frmSettings::setIgnoreZ(bool value)
541+
{
542+
ui->chkIgnoreZ->setChecked(value);
543+
}
544+
494545
void frmSettings::showEvent(QShowEvent *se)
495546
{
496547
Q_UNUSED(se)
@@ -542,6 +593,8 @@ void frmSettings::on_cmdDefaults_clicked()
542593
setAcceleration(100);
543594
setSpindleSpeedMin(0);
544595
setSpindleSpeedMax(10000);
596+
setLaserPowerMin(0);
597+
setLaserPowerMax(100);
545598
setTouchCommand("G21G91G38.2Z-30F100; G0Z1; G38.2Z-2F10");
546599
setSafePositionCommand("G21G90; G53G0Z0");
547600
setMoveOnRestore(false);
@@ -560,6 +613,9 @@ void frmSettings::on_cmdDefaults_clicked()
560613
setSimplifyPrecision(0.0);
561614
setFps(60);
562615
setZBuffer(false);
616+
setGrayscaleSegments(false);
617+
setGrayscaleSCode(true);
618+
setIgnoreZ(false);
563619

564620
setToolType(1);
565621
setToolAngle(15.0);
@@ -572,7 +628,7 @@ void frmSettings::on_cmdDefaults_clicked()
572628
setPanelFeed(true);
573629
setPanelHeightmap(true);
574630
setPanelJog(true);
575-
setPanelSpindle(true);
631+
setPanelSpindle(true);
576632

577633
ui->clpTool->setColor(QColor(255, 153, 0));
578634

src/frmsettings.h

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class frmSettings : public QDialog
5959
void setSpindleSpeedMin(int speed);
6060
int spindleSpeedMax();
6161
void setSpindleSpeedMax(int speed);
62+
int laserPowerMin();
63+
void setLaserPowerMin(int value);
64+
int laserPowerMax();
65+
void setLaserPowerMax(int value);
6266
int rapidSpeed();
6367
void setRapidSpeed(int rapidSpeed);
6468
int heightmapProbingFeed();
@@ -99,6 +103,12 @@ class frmSettings : public QDialog
99103
QColor colors(QString name);
100104
int fontSize();
101105
void setFontSize(int fontSize);
106+
bool grayscaleSegments();
107+
void setGrayscaleSegments(bool value);
108+
bool grayscaleSCode();
109+
void setGrayscaleSCode(bool value);
110+
bool ignoreZ();
111+
void setIgnoreZ(bool value);
102112

103113
protected:
104114
void showEvent(QShowEvent *se);

0 commit comments

Comments
 (0)