How to make a GUI for USBCNC with Qt4 - Femtotech
How to make a GUI for USBCNC with Qt4 - Femtotech
How to make a GUI for USBCNC with Qt4 - Femtotech
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
class MainWindow : public QMainWindow<br />
{<br />
Q_OBJECT<br />
public:<br />
explicit MainWindow(QWidget *parent = 0);<br />
~MainWindow();<br />
private:<br />
Ui::MainWindow *ui;<br />
QTimer *timer;<br />
private slots:<br />
void on_btnConnect_clicked();<br />
void on_btnLoadJob_clicked();<br />
void on_btnStartJob_clicked();<br />
void on_btnRewindJob_clicked();<br />
void on_btnHomeAll_clicked();<br />
void on_btnPause_clicked();<br />
void on_btnReset_clicked();<br />
void timer_ovf();<br />
};<br />
#endif // MAINWINDOW_H<br />
This is the mainwindow.cpp code:<br />
#include "mainwindow.h"<br />
#include "ui_mainwindow.h"<br />
MainWindow::MainWindow(QWidget *parent) :<br />
QMainWindow(parent),<br />
ui(new Ui::MainWindow)<br />
{<br />
ui->setupUi(this);<br />
timer = new QTimer(this);<br />
timer->setInterval(100);<br />
connect(timer, SIGNAL(timeout()), this, SLOT(timer_ovf()));<br />
}<br />
MainWindow::~MainWindow()<br />
{<br />
//CncDisConnectServer();<br />
delete ui;<br />
}<br />
void MainWindow::on_btnConnect_clicked()<br />
{<br />
CNC_RC rc = CncConnectServer(""); // ("cnc.ini");<br />
ui->txtServerStatus->setText(CncGetRCText(rc));<br />
if (rc == CNC_RC_OK || rc == CNC_RC_ALREADY_RUNS) timer->start();<br />
}<br />
void MainWindow::on_btnLoadJob_clicked()<br />
{<br />
QFileDialog *dialog = new QFileDialog();<br />
QString file = dialog->getOpenFileName(this, "Select job", "", "CNC Files (*.nc *.cnc *.ngc *.gc *.iso<br />
*.tap)");<br />
if (file.isEmpty()) return;<br />
int jobFileLength, macroFileLength, isLongJob, isSuperLongJob;<br />
qint64 sizeInBytes;<br />
QByteArray fileName = file.<strong>to</strong>Local8Bit();<br />
CNC_RC rc = CncLoadJob(fileName.data(), &jobFileLength, ¯oFileLength, &isLongJob, &isSuperLongJob,<br />
&sizeInBytes);<br />
ui->txtServerStatus->setText(CncGetRCText(rc));<br />
CncStartRenderGraph(1, 1);<br />
}<br />
void MainWindow::on_btnHomeAll_clicked()<br />
{<br />
CNC_RC rc = CncRunSingleLine("gosub home_all");<br />
ui->txtServerStatus->setText(CncGetRCText(rc));<br />
}<br />
void MainWindow::on_btnRewindJob_clicked()<br />
Fem<strong>to</strong>tech di Marco Trapanese Via Ripamonti, 14 – 22044 Inverigo (CO) tel. 031 5481112 / 347 9431074 fax 031 2280476<br />
info@fem<strong>to</strong>tech.it www.fem<strong>to</strong>tech.it C.F. TRP MRC 81S13 B639G P.IVA 03041740139<br />
10