This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
controlpanel.cpp
397 lines (354 loc) · 14.8 KB
/
controlpanel.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#include "controlpanel.h"
#include "ui_controlpanel.h"
#include <QProcess>
#include <mainwindow.h>
#include <QDialog>
//#include <QSizeF>
#include <QPalette>
#include <QBitmap>
#include <QPainter>
#include <QTextBrowser>
#include <QDesktopWidget>
ControlPanel::ControlPanel(QWidget *parent) :
QDialog(parent),
ui(new Ui::ControlPanel)
{
ui->setupUi(this);
FUI = (MainWindow*)parent;//((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_Setting);
//使控件适应屏幕的大小
this->resize((int)(SizePercent.width()*800),(int)(SizePercent.height()*480)); //将控件大小固定为800*480
this->setMaximumSize((int)(SizePercent.width()*800),(int)(SizePercent.height()*480));
this->setFixedSize((int)(SizePercent.width()*800),(int)(SizePercent.height()*480));
//设置冷热按键的样式表
ui->Btn_Cool->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251);color: rgb(245, 246, 250);}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125);}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125); padding-right:4px;padding-bottom:4px;}");
ui->Btn_Heat->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6);color: rgb(245, 246, 250);}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3);}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3); padding-right:4px;padding-bottom:4px;}");
ui->Btn_Axle_Home->setStyleSheet("border-color: rgb(230, 230, 230);");
ui->Btn_Unlock->setStyleSheet("border-color: rgb(43, 166, 56);");
ui->Btn_Restore->setStyleSheet("border-color: rgb(205, 205, 205);");
ui->Btn_Shutdown->setStyleSheet("border-color: rgb(216, 30, 6);");
ui->Btn_Extruder_E->setStyleSheet("border-color: rgb(245, 246, 255);");
ui->Btn_Extruder_R->setStyleSheet("border-color: rgb(245, 246, 255);");
}
ControlPanel::~ControlPanel()
{
delete ui;
}
void ControlPanel::on_Btn_Back_clicked()
{
this->close();//关闭窗口
}
void ControlPanel::on_Btn_R_1_clicked()
{
MoveSpeed = 1;
ui->Btn_R_1->setStyleSheet(SelectKey);
ui->Btn_R_5->setStyleSheet(UnSelectKey);
ui->Btn_R_10->setStyleSheet(UnSelectKey);
ui->Btn_R_50->setStyleSheet(UnSelectKey);
ui->Btn_R_100->setStyleSheet(UnSelectKey);
}
void ControlPanel::on_Btn_R_5_clicked()
{
MoveSpeed = 5;
ui->Btn_R_1->setStyleSheet(UnSelectKey);
ui->Btn_R_5->setStyleSheet(SelectKey);
ui->Btn_R_10->setStyleSheet(UnSelectKey);
ui->Btn_R_50->setStyleSheet(UnSelectKey);
ui->Btn_R_100->setStyleSheet(UnSelectKey);
}
void ControlPanel::on_Btn_R_10_clicked()
{
MoveSpeed = 10;
ui->Btn_R_1->setStyleSheet(UnSelectKey);
ui->Btn_R_5->setStyleSheet(UnSelectKey);
ui->Btn_R_10->setStyleSheet(SelectKey);
ui->Btn_R_50->setStyleSheet(UnSelectKey);
ui->Btn_R_100->setStyleSheet(UnSelectKey);
}
void ControlPanel::on_Btn_R_50_clicked()
{
MoveSpeed = 50;
ui->Btn_R_1->setStyleSheet(UnSelectKey);
ui->Btn_R_5->setStyleSheet(UnSelectKey);
ui->Btn_R_10->setStyleSheet(UnSelectKey);
ui->Btn_R_50->setStyleSheet(SelectKey);
ui->Btn_R_100->setStyleSheet(UnSelectKey);
}
void ControlPanel::on_Btn_R_100_clicked()
{
MoveSpeed = 100;
ui->Btn_R_1->setStyleSheet(UnSelectKey);
ui->Btn_R_5->setStyleSheet(UnSelectKey);
ui->Btn_R_10->setStyleSheet(UnSelectKey);
ui->Btn_R_50->setStyleSheet(UnSelectKey);
ui->Btn_R_100->setStyleSheet(SelectKey);
}
void ControlPanel::on_Btn_Heat_toggled(bool checked)
{
if(checked)//如果升温按钮被点击,关闭降温按钮
{
ui->Btn_Cool->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251);}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125);}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125); padding-right:4px;padding-bottom:4px;}");
ui->Btn_Heat->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3); padding-right:4px;padding-bottom:4px;}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3); padding-right:4px;padding-bottom:4px;}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3); padding-right:4px;padding-bottom:4px;}");
if(ui->Btn_Cool->isChecked())
{
ui->Btn_Cool->setChecked(false);
//发送升温指令
QList<QString> _GCode_Setting;
_GCode_Setting.append("M140 S60");
_GCode_Setting.append("M104 S200");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_Setting);
}
}
}
void ControlPanel::on_Btn_Cool_toggled(bool checked)
{
if(checked)
{
ui->Btn_Heat->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6);}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3);}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(216, 30, 6); background-color: rgb(108, 15, 3); padding-right:4px;padding-bottom:4px;}");
ui->Btn_Cool->setStyleSheet("QPushButton {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125); padding-right:4px;padding-bottom:4px;}"\
"QPushButton:hover {padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125); padding-right:4px;padding-bottom:4px;}"\
"QPushButton:pressed{padding: 10px;border-style: solid;border-width: 5px;border-radius: 20px;border-color: rgb(36, 148, 251); background-color: rgb(18, 74, 125); padding-right:4px;padding-bottom:4px;}");
}
// ui->Btn_Cool->setStyleSheet(checked?ui->Btn_Cool->styleSheet()+"background-color:rgb(18, 74, 125);":"padding: 10px;\nborder-style: solid;\nborder-width: 5px;\nborder-radius: 20px;\nborder-color: rgb(36, 148, 251);");
QList<QString> _GCode_;
if(checked)//如果降下温按钮被点击,关闭升温按钮
{
if(ui->Btn_Heat->isChecked())
ui->Btn_Heat->setChecked(false);
//发送降温指令
_GCode_.append("M106 S255");
_GCode_.append("M104 S0");
_GCode_.append("M140 S0");
}
else
{
_GCode_.append("M106 S0");//?
}
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
//坐标归位按键按下所有坐标归位,按键变色
void ControlPanel::on_Btn_Axle_Home_clicked()
{
//发送归位指令
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G28");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
//Unlock Motors 锁定喷头温度和工床温度
void ControlPanel::on_Btn_Unlock_clicked()
{
QList<QString> _GCode_;
_GCode_.append("M18");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
//重启 OctoBTT、重启OctoPrint以及取消
void ControlPanel::on_Btn_Restore_clicked()
{
// StyleSheet_Temp = ui->Btn_Restore->styleSheet();//获取按键的样式表用以恢复颜色
// ui->Btn_Restore->setStyleSheet(StyleSheet_Temp+"\nbackground-color:rgb(128,128,128,128);");
QStringList btnName = {"Restart OctoBTT" , "Restart OctoPrint", "Cancel"} ;
CustomDialog *newDialog = new CustomDialog();
QObject::connect(newDialog, &CustomDialog::OutputEvent, newDialog,[=](QString instruct)
{
if(instruct == "Restart OctoBTT")
{
//重启OctoBTT
qApp->exit(Base_Restart);
}
else if(instruct == "Restart OctoPrint")
{
//重启Octoprint
QProcess P(0);
P.start("sudo service octoprint restart");
P.waitForStarted();
P.waitForFinished();
qApp->exit(Base_Restart);
}
});
newDialog->showCustomDialog("what do you want ?",":/assets/zhongzhi.svg",btnName,this);
}
//紧急制停、关机以及取消
void ControlPanel::on_Btn_Shutdown_clicked()
{
QStringList btnName = {"Emergency Stop" , "Shutdown", "Cancel"} ;
CustomDialog *newDialog = new CustomDialog();
QObject::connect(newDialog, &CustomDialog::OutputEvent, newDialog,[=](QString instruct)
{
if(instruct == "Emergency Stop")
{
//紧急制停
QList<QString> _GCode_;
// _GCode_.append("M110 N0");
_GCode_.append("M112");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
else if(instruct == "Shutdown")
{
//关机
QProcess P(0);
P.start("xset dpms force off");
P.waitForStarted();
P.waitForFinished();
qApp->exit(Base_Shutdown);
}
});
newDialog->showCustomDialog("what do you want ?",":/assets/hazard.svg",btnName,this);
}
void ControlPanel::on_Btn_Axle_X_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G28 X");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Axle_Y_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G28 Y");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Axle_Z_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G28 Z");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_XY_Res_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G28 X Y");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Y_Add_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 Y"+QString::number(MoveSpeed)+" F6000");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Y_Dec_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 Y-"+QString::number(MoveSpeed)+" F6000");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_X_Dec_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 X-"+QString::number(MoveSpeed)+" F6000");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_X_Add_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 X"+QString::number(MoveSpeed)+" F6000");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Z_Add_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 Z"+QString::number(MoveSpeed)+" F200");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Z_Dec_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 Z-"+QString::number(MoveSpeed)+" F200");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Extruder_R_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 E-"+QString::number(MoveSpeed)+" F300");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Extruder_E_clicked()
{
QList<QString> _GCode_;
_GCode_.append("G91");
_GCode_.append("G1 E"+QString::number(MoveSpeed)+" F300");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Z_BS_Add_clicked()
{
QList<QString> _GCode_;
// _GCode_.append("M110 N0");
_GCode_.append("G91");
_GCode_.append("M290 Z"+QString::number((double)MoveSpeed/100));
_GCode_.append("M500");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
void ControlPanel::on_Btn_Z_BS_Dec_clicked()
{
QList<QString> _GCode_;
// _GCode_.append("M110 N0");
_GCode_.append("G91");
_GCode_.append("M290 Z-"+QString::number((double)MoveSpeed/100));
_GCode_.append("M500");
_GCode_.append("G90");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
//自动调平按键
void ControlPanel::on_Btn_Level_clicked()
{
//如果点击退出,关闭弹窗
if(((MainWindow*)FUI)->octonetwork.ConnectState == "Operational")
{
QStringList btnName = {"Yes", "No"} ;
CustomDialog *newDialog = new CustomDialog();
QObject::connect(newDialog, &CustomDialog::OutputEvent, newDialog,[=](QString instruct)
{
if(instruct == "Yes")
{
QList<QString> _GCode_;
_GCode_.append("M502");
_GCode_.append("M500");
_GCode_.append("G91");
_GCode_.append("G28");
_GCode_.append("G29");
_GCode_.append("G90");
_GCode_.append("M500");
((MainWindow*)FUI)->octonetwork.SendGCode(_GCode_);
}
});
newDialog->showCustomDialog("Self-leveling",":/assets/kongzhimianban_B.svg",btnName,"Whether the automatic leveling sensor has been installed ?",this);
}
else
{
CustomDialog *newDialog = new CustomDialog();
newDialog->showCustomDialog("Self-leveling",":/assets/kongzhimianban_B.svg","Current state not supported !",this);
}
}