forked from zalohasa/GrblHoming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
274 lines (243 loc) · 6.96 KB
/
mainwindow.h
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
/****************************************************************
* mainwindow.h
* GrblHoming - zapmaker fork on github
*
* 15 Nov 2012
* GPL License (see LICENSE file)
* Software is provided AS-IS
****************************************************************/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFileDialog>
#include <QMessageBox>
#include <QFile>
#include <QSettings>
#include <QCloseEvent>
#include <QItemDelegate>
#include <QScrollBar>
#include <QListView>
#include "about.h"
#include "definitions.h"
#include "grbldialog.h"
#include "options.h"
//#include "filesender.h"
#include "timer.h"
#include "positem.h"
#include "gcodecontroller.h"
#include "renderarea.h"
#include "log4qtdef.h"
#define COMPANY_NAME "zapmaker"
#define APPLICATION_NAME "GrblController"
#define DOMAIN_NAME "org.zapmaker"
#define TAB_AXIS_INDEX 0
#define TAB_VISUALIZER_INDEX 1
#define TAB_ADVANCED_INDEX 2
#define TAB_Z_LEVELING_INDEX 3
#define CENTER_POS 40
#define MAX_STATUS_LINES_WHEN_ACTIVE 200
/* testing optimizing scrollbar, doesn't work right
class MyItemDelegate : public QItemDelegate
{
private:
int width;
QAbstractItemView *parentWidget;
public:
MyItemDelegate(QAbstractItemView *p) : parentWidget(p) {}
void setWidth(int w)
{
width = w;
}
void drawDisplay(QPainter *painter,const
QStyleOptionViewItem &option,const QRect &rect,const QString &text) const{
QRect tempRect(rect);
tempRect.setWidth(parentWidget->width());
QItemDelegate::drawDisplay(painter,option,tempRect,text);
}
QSize sizeHint(const QStyleOptionViewItem & option, const
QModelIndex & index ) const {
QListView *list = qobject_cast<QListView*>(parentWidget);
QSize newSize(QItemDelegate::sizeHint(option,index));
if( list ) newSize.setWidth( width );
return newSize;
}
};
*/
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *event);
//variables
int delete_nr;
signals:
//threads
void openPort(QString port, QString baudRate);
void closePort(bool reopen);
void shutdown();
void sendGcode(QString line, bool recordResponseOnFail = false, int waitCount = SHORT_WAIT_SEC);
void sendFile(QString path);
void gotoXYZFourth(QString line);
void axisAdj(char axis, float coord, bool inv, bool absoluteAfterAxisAdj, int sliderZCount);
void setResponseWait(ControlParams controlParams);
void setProgress(int percent);
void setRuntime(QString runtime);
void sendSetHome();
void sendGrblReset();
void sendGrblUnlock();
void goToHome();
void setItems(QList<PosItem>);
void doTestLeveling(int levelingAlgorithm, QRect rect, int xSteps, int ySteps, double zStarting, double speed, double zHeight, double offset);
void changeInterpolator(int index);
void doRecomputeOffset(double speed, double zStarting);
private slots:
//buttons
void openPort();
void setGRBL();
//Adjust
void decX();
void decY();
void decZ();
void decFourth();
void incFourth();
void incX();
void incY();
void incZ();
void setHome();
//manual
void gotoXYZFourth();
//send Gcode
void begin();
void openFile();
void stop();
void stopSending();
void stopLeveling();
//
void portIsOpen(bool sendCode);
void portIsClosed(bool reopen);
void adjustedAxis();
//check boxes
void toggleSpindle();
void toggleRestoreAbsolute();
//communications
//options
void setSettings();
//thread
void receiveList(QString msg);
void receiveListFull(QStringList list);
void receiveListOut(QString msg);
void receiveMsg(QString msg);
//menu bar
void getOptions();
void showAbout();
void enableGrblDialogButton();
void grblReset();
void grblUnlock();
void updateCoordinates(Coord3D machineCoord, Coord3D workCoord);
void goHomeSafe();
void zJogSliderDisplay(int pos);
void zJogSliderPressed();
void zJogSliderReleased();
void doScroll();
void statusSliderPressed();
void statusSliderReleased();
void setQueuedCommands(int commandCount, bool running);
void testLeveling();
void setLcdState(bool valid);
void refreshPosition();
void comboStepChanged(const QString& text);
void setLevelingProgress(int progress);
void setLevelingEnded();
void useZLevelingDataToggle(bool checked);
void clearLevelingData();
void levelingAlgorithmChanged(int);
void recomputeOffset();
void recomputeOffsetEnded(double newOffset);
private:
// enums
enum
{
NO_ITEM = 0,
X_ITEM,
Y_ITEM,
I_ITEM,
J_ITEM,
};
enum
{
QCS_OK = 0,
QCS_WAITING_FOR_ITEMS
};
//objects
Ui::MainWindow *ui;
//FileSender fileSender;
//QThread fileSenderThread;
GCodeController * gcode;
QThread gcodeThread;
Timer runtimeTimer;
QThread runtimeTimerThread;
int currentController;
//variables
bool invX;
bool invY;
bool invZ;
bool invFourth;
/// for translation
QString open_button_text ;
QString close_button_text ;
bool mm;
QString styleSheet;
QString directory;
QString nameFilter;
QString lastOpenPort;
QString lastBaudRate;
QByteArray fileOpenDialogState;
Coord3D machineCoordinates;
Coord3D workCoordinates;
bool absoluteAfterAxisAdj;
bool checkLogWrite;
QTime scrollStatusTimer;
QTime queuedCommandsEmptyTimer;
QTime queuedCommandsRefreshTimer;
QList<PosItem> posList;
bool sliderPressed;
double sliderTo;
int sliderZCount;
bool promptedAggrPreload;
ControlParams controlParams;
QTimer *scrollTimer;
bool scrollRequireMove;
bool scrollPressed;
bool queuedCommandsStarved;
int lastQueueCount;
int queuedCommandState;
QStringList fullStatus;
bool lastLcdStateValid;
float jogStep;
QString jogStepStr;
//methods
int SendJog(QString strline);
void readSettings();
void writeSettings();
void addToStatusList(bool in, QString msg);
void addToStatusList(QStringList& list);
void disableAllButtons();
void openPortCtl(bool reopen);
void resetProgress();
void refreshLcd();
void lcdDisplay(char axis, bool workCoord, float value);
void updateSettingsFromOptionDlg(QSettings& settings);
int computeListViewMinimumWidth(QAbstractItemView* view);
void preProcessFile(QString filepath);
bool processGCode(QString inputLine, double& x, double& y, double& i, double& j, bool& arc, bool& cw, bool& mm, int& g);
double decodeLineItem(const QString& item, const int next, bool& valid, int& nextIsValue);
double decodeDouble(QString value, bool& valid);
void createGcodeConnects();
void deleteGcodeConnects();
};
#endif // MAINWINDOW_H