forked from apsystems/GrblHoming
-
Notifications
You must be signed in to change notification settings - Fork 190
/
options.cpp
286 lines (247 loc) · 10.1 KB
/
options.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/****************************************************************
* options.cpp
* GrblHoming - zapmaker fork on github
*
* 15 Nov 2012
* GPL License (see LICENSE file)
* Software is provided AS-IS
****************************************************************/
#include "options.h"
#include "ui_options.h"
Options::Options(QWidget *parent) :
QDialog(parent),
ui(new Ui::Options)
{
ui->setupUi(this);
connect(ui->checkBoxUseMmManualCmds,SIGNAL(toggled(bool)),this,SLOT(toggleUseMm(bool)));
connect(ui->chkLimitZRate,SIGNAL(toggled(bool)),this,SLOT(toggleLimitZRate(bool)));
connect(ui->checkBoxFourAxis,SIGNAL(toggled(bool)),this,SLOT(toggleFourAxis(bool)));
connect(ui->checkBoxPositionReportEnabled,SIGNAL(toggled(bool)),this,SLOT(togglePosReporting(bool)));
QSettings settings;
QString invX = settings.value(SETTINGS_INVERSE_X, "false").value<QString>();
QString invY = settings.value(SETTINGS_INVERSE_Y, "false").value<QString>();
QString invZ = settings.value(SETTINGS_INVERSE_Z, "false").value<QString>();
QString invFourth = settings.value(SETTINGS_INVERSE_FOURTH, "false").value<QString>();
ui->chkInvFourth->setChecked(invFourth == "true");
ui->chkInvX->setChecked(invX == "true");
ui->chkInvY->setChecked(invY == "true");
ui->chkInvZ->setChecked(invZ == "true");
// enable logging by default
QString enDebugLog = settings.value(SETTINGS_ENABLE_DEBUG_LOG, "true").value<QString>();
// default aggressive preload behavior to 'true'!
QString enAggressivePreload = settings.value(SETTINGS_USE_AGGRESSIVE_PRELOAD, "true").value<QString>();
QString waitForJogToComplete = settings.value(SETTINGS_WAIT_FOR_JOG_TO_COMPLETE, "true").value<QString>();
QString useMmManualCmds = settings.value(SETTINGS_USE_MM_FOR_MANUAL_CMDS, "true").value<QString>();
QString enFourAxis = settings.value(SETTINGS_FOUR_AXIS_USE, "false").value<QString>();
char fourthAxisType = settings.value(SETTINGS_FOUR_AXIS_TYPE, FOURTH_AXIS_A).value<char>();
if (enFourAxis == "false")
{
ui->chkInvFourth->hide();
ui->chkInvFourth->setAttribute(Qt::WA_DontShowOnScreen, true);
ui->groupBoxFourthAxis->setEnabled(false);
}
else
{
ui->chkInvFourth->show();
ui->chkInvFourth->setAttribute(Qt::WA_DontShowOnScreen, false);
ui->groupBoxFourthAxis->setEnabled(true);
switch (fourthAxisType)
{
case FOURTH_AXIS_A:
default:
ui->radioButtonFourthAxisA->setChecked(true);
break;
case FOURTH_AXIS_B:
ui->radioButtonFourthAxisB->setChecked(true);
break;
case FOURTH_AXIS_C:
ui->radioButtonFourthAxisC->setChecked(true);
break;
/// LETARTARE
case FOURTH_AXIS_U:
ui->radioButtonFourthAxisU->setChecked(true);
break;
case FOURTH_AXIS_V:
ui->radioButtonFourthAxisV->setChecked(true);
break;
case FOURTH_AXIS_W:
ui->radioButtonFourthAxisW->setChecked(true);
break;
/// <--
}
}
ui->checkBoxEnableDebugLog->setChecked(enDebugLog == "true");
ui->chkAggressivePreload->setChecked(enAggressivePreload == "true");
//ui->checkBoxWaitForJogToComplete->setChecked(waitForJogToComplete == "true");
ui->checkBoxWaitForJogToComplete->hide();
ui->checkBoxUseMmManualCmds->setChecked(useMmManualCmds == "true");
ui->checkBoxFourAxis->setChecked(enFourAxis == "true");
int waitTime = settings.value(SETTINGS_RESPONSE_WAIT_TIME, DEFAULT_WAIT_TIME_SEC).value<int>();
ui->spinResponseWaitSec->setValue(waitTime);
double zJogRate = settings.value(SETTINGS_Z_JOG_RATE, DEFAULT_Z_JOG_RATE).value<double>();
ui->doubleSpinZJogRate->setValue(zJogRate);
QString zRateLimit = settings.value(SETTINGS_Z_RATE_LIMIT, "false").value<QString>();
ui->chkLimitZRate->setChecked(zRateLimit == "true");
double zRateLimitAmount = settings.value(SETTINGS_Z_RATE_LIMIT_AMOUNT, DEFAULT_Z_LIMIT_RATE).value<double>();
ui->doubleSpinZRateLimit->setValue(zRateLimitAmount);
double xyRateAmount = settings.value(SETTINGS_XY_RATE_AMOUNT, DEFAULT_XY_RATE).value<double>();
ui->doubleSpinXYRate->setValue(xyRateAmount);
if (!ui->chkLimitZRate->isChecked())
{
ui->doubleSpinZRateLimit->setEnabled(false);
ui->doubleSpinXYRate->setEnabled(false);
}
QString ffCmd = settings.value(SETTINGS_FILTER_FILE_COMMANDS, "false").value<QString>();
ui->chkFilterFileCommands->setChecked(ffCmd == "true");
QString rPrecision = settings.value(SETTINGS_REDUCE_PREC_FOR_LONG_LINES, "false").value<QString>();
ui->checkBoxReducePrecForLongLines->setChecked(rPrecision == "true");
ui->spinBoxGrblLineBufferSize->setValue(settings.value(SETTINGS_GRBL_LINE_BUFFER_LEN, DEFAULT_GRBL_LINE_BUFFER_LEN).value<int>());
ui->spinBoxCharSendDelay->setValue(settings.value(SETTINGS_CHAR_SEND_DELAY_MS, DEFAULT_CHAR_SEND_DELAY_MS).value<int>());
QString enPosReq = settings.value(SETTINGS_ENABLE_POS_REQ, "true").value<QString>();
QString posReqType = settings.value(SETTINGS_TYPE_POS_REQ, PREQ_NOT_WHEN_MANUAL).value<QString>();
double posRateFreqSec = settings.value(SETTINGS_POS_REQ_FREQ_SEC, DEFAULT_POS_REQ_FREQ_SEC).value<double>();
ui->checkBoxPositionReportEnabled->setChecked(enPosReq == "true");
ui->doubleSpinBoxPosRequestFreqSec->setValue(posRateFreqSec);
if (posReqType == PREQ_NOT_WHEN_MANUAL)
{
ui->radioButton_ReqNotDuringManual->setChecked(true);
}
else if (posReqType == PREQ_ALWAYS)
{
ui->radioButton_ReqAlways->setChecked(true);
}
else
{
ui->radioButton_ReqAlwaysNoIdleCheck->setChecked(true);
}
togglePosReporting(enPosReq == "true");
}
Options::~Options()
{
delete ui;
}
void Options::accept()
{
QSettings settings;
settings.setValue(SETTINGS_INVERSE_X, ui->chkInvX->isChecked());
settings.setValue(SETTINGS_INVERSE_Y, ui->chkInvY->isChecked());
settings.setValue(SETTINGS_INVERSE_Z, ui->chkInvZ->isChecked());
settings.setValue(SETTINGS_INVERSE_FOURTH, ui->chkInvFourth->isChecked());
settings.setValue(SETTINGS_ENABLE_DEBUG_LOG, ui->checkBoxEnableDebugLog->isChecked());
settings.setValue(SETTINGS_USE_AGGRESSIVE_PRELOAD, ui->chkAggressivePreload->isChecked());
settings.setValue(SETTINGS_WAIT_FOR_JOG_TO_COMPLETE, ui->checkBoxWaitForJogToComplete->isChecked());
settings.setValue(SETTINGS_USE_MM_FOR_MANUAL_CMDS, ui->checkBoxUseMmManualCmds->isChecked());
settings.setValue(SETTINGS_FOUR_AXIS_USE, ui->checkBoxFourAxis->isChecked());
settings.setValue(SETTINGS_FOUR_AXIS_TYPE, getFourthAxisType());
settings.setValue(SETTINGS_RESPONSE_WAIT_TIME, ui->spinResponseWaitSec->value());
settings.setValue(SETTINGS_Z_JOG_RATE, ui->doubleSpinZJogRate->value());
settings.setValue(SETTINGS_Z_RATE_LIMIT, ui->chkLimitZRate->isChecked());
settings.setValue(SETTINGS_Z_RATE_LIMIT_AMOUNT, ui->doubleSpinZRateLimit->value());
settings.setValue(SETTINGS_XY_RATE_AMOUNT, ui->doubleSpinXYRate->value());
settings.setValue(SETTINGS_FILTER_FILE_COMMANDS, ui->chkFilterFileCommands->isChecked());
settings.setValue(SETTINGS_REDUCE_PREC_FOR_LONG_LINES, ui->checkBoxReducePrecForLongLines->isChecked());
settings.setValue(SETTINGS_GRBL_LINE_BUFFER_LEN, ui->spinBoxGrblLineBufferSize->value());
settings.setValue(SETTINGS_CHAR_SEND_DELAY_MS, ui->spinBoxCharSendDelay->value());
settings.setValue(SETTINGS_ENABLE_POS_REQ, ui->checkBoxPositionReportEnabled->isChecked());
settings.setValue(SETTINGS_TYPE_POS_REQ, getPosReqType());
settings.setValue(SETTINGS_POS_REQ_FREQ_SEC, ui->doubleSpinBoxPosRequestFreqSec->value());
connect(this, SIGNAL(setSettings()), parentWidget(), SLOT(setSettings()));
emit setSettings();
this->close();
}
void Options::toggleUseMm(bool useMm)
{
double zJogRate = ui->doubleSpinZJogRate->value();
double zRateLimit = ui->doubleSpinZRateLimit->value();
double xyRate = ui->doubleSpinXYRate->value();
if (useMm)
{
ui->doubleSpinZJogRate->setValue(zJogRate * MM_IN_AN_INCH);
ui->doubleSpinZRateLimit->setValue(zRateLimit * MM_IN_AN_INCH);
ui->doubleSpinXYRate->setValue(xyRate * MM_IN_AN_INCH);
}
else
{
ui->doubleSpinZJogRate->setValue(zJogRate / MM_IN_AN_INCH);
ui->doubleSpinZRateLimit->setValue(zRateLimit / MM_IN_AN_INCH);
ui->doubleSpinXYRate->setValue(xyRate / MM_IN_AN_INCH);
}
}
void Options::toggleLimitZRate(bool limitZ)
{
ui->doubleSpinZRateLimit->setEnabled(limitZ);
ui->doubleSpinXYRate->setEnabled(limitZ);
}
void Options::toggleFourAxis(bool four)
{
if (four)
{
ui->chkInvFourth->show();
ui->chkInvFourth->setAttribute(Qt::WA_DontShowOnScreen, false);
ui->groupBoxFourthAxis->setEnabled(true);
}
else
{
ui->chkInvFourth->hide();
ui->chkInvFourth->setAttribute(Qt::WA_DontShowOnScreen, true);
ui->groupBoxFourthAxis->setEnabled(false);
}
}
void Options::togglePosReporting(bool usePosReporting)
{
if (usePosReporting)
{
ui->groupBox_ReqPos->setEnabled(true);
}
else
{
ui->groupBox_ReqPos->setEnabled(false);
}
}
char Options::getFourthAxisType()
{
char type = FOURTH_AXIS_A;
if (ui->radioButtonFourthAxisA->isChecked())
{
type = FOURTH_AXIS_A;
}
else
if (ui->radioButtonFourthAxisB->isChecked())
{
type = FOURTH_AXIS_B;
}
else
if (ui->radioButtonFourthAxisC->isChecked())
{
type = FOURTH_AXIS_C;
}
/// LETATARE
if (ui->radioButtonFourthAxisU->isChecked())
{
type = FOURTH_AXIS_U;
}
else
if (ui->radioButtonFourthAxisV->isChecked())
{
type = FOURTH_AXIS_V;
}
else
if (ui->radioButtonFourthAxisW->isChecked())
{
type = FOURTH_AXIS_W;
}
/// <--
return type;
}
QString Options::getPosReqType()
{
if (ui->radioButton_ReqAlways->isChecked())
{
return PREQ_ALWAYS;
}
else if (ui->radioButton_ReqNotDuringManual->isChecked())
{
return PREQ_NOT_WHEN_MANUAL;
}
return PREQ_ALWAYS_NO_IDLE_CHK;
}