-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
G-code parser from winder/Universal-G-Code-Sender.
- Loading branch information
Showing
64 changed files
with
5,225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "arcproperties.h" | ||
|
||
ArcProperties::ArcProperties(QObject *parent) : QObject(parent) | ||
{ | ||
radius = 0; | ||
center = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ARCPROPERTIES_H | ||
#define ARCPROPERTIES_H | ||
|
||
#include <QObject> | ||
#include <QVector3D> | ||
|
||
class ArcProperties : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit ArcProperties(QObject *parent = 0); | ||
bool isClockwise; | ||
double radius; | ||
QVector3D *center; | ||
|
||
signals: | ||
|
||
public slots: | ||
|
||
}; | ||
|
||
#endif // ARCPROPERTIES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include <QFileDialog> | ||
#include <QTextStream> | ||
#include <QDebug> | ||
#include "frmmain.h" | ||
#include "ui_frmmain.h" | ||
|
||
frmMain::frmMain(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::frmMain) | ||
{ | ||
ui->setupUi(this); | ||
m_codeDrawer.setViewParser(&m_viewParser); | ||
m_toolDrawer.setToolPosition(QVector3D(0, 0, 10)); | ||
ui->glwVisualizator->addDrawable(&m_codeDrawer); | ||
ui->glwVisualizator->addDrawable(&m_toolDrawer); | ||
ui->glwVisualizator->fitDrawables(); | ||
ui->cmdFit->setParent(ui->glwVisualizator); | ||
|
||
connect(&m_tableModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_tblProgram_cellChanged(QModelIndex,QModelIndex))); | ||
|
||
ui->tblProgram->setModel(&m_tableModel); | ||
ui->tblProgram->setColumnWidth(0, 400); | ||
ui->tblProgram->setColumnWidth(1, 150); | ||
ui->tblProgram->horizontalHeader()->setStretchLastSection(true); | ||
|
||
m_programLoading = false; | ||
clearTable(); | ||
} | ||
|
||
frmMain::~frmMain() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void frmMain::showEvent(QShowEvent *se) | ||
{ | ||
QList<int> sizes; | ||
sizes.append(ui->grpProgram->height() - 100); | ||
sizes.append(100); | ||
ui->splitter->setSizes(sizes); | ||
ui->cmdFit->move(ui->glwVisualizator->width() - ui->cmdFit->width() - 10, 10); | ||
} | ||
|
||
void frmMain::resizeEvent(QResizeEvent *re) | ||
{ | ||
ui->cmdFit->move(ui->glwVisualizator->width() - ui->cmdFit->width() - 10, 10); | ||
} | ||
|
||
void frmMain::on_actFileExit_triggered() | ||
{ | ||
close(); | ||
} | ||
|
||
void frmMain::on_cmdFileOpen_clicked() | ||
{ | ||
QString fileName = QFileDialog::getOpenFileName(this, "Открыть", "", "Файлы G-Code (*.nc;*.ncc;*.tap)"); | ||
|
||
if (fileName != "") processFile(fileName); | ||
} | ||
|
||
void frmMain::processFile(QString fileName) | ||
{ | ||
QFile file(fileName); | ||
|
||
if (!file.open(QIODevice::ReadOnly)) return; | ||
QTextStream textStream(&file); | ||
QList<QString> commands; | ||
|
||
clearTable(); | ||
m_programLoading = true; | ||
ui->tblProgram->setModel(NULL); | ||
|
||
while (!textStream.atEnd()) | ||
{ | ||
commands.append(textStream.readLine()); | ||
|
||
m_tableModel.setData(m_tableModel.index(m_tableModel.rowCount() - 1, 0), commands.last()); | ||
m_tableModel.setData(m_tableModel.index(m_tableModel.rowCount() - 2, 1), "В очереди"); | ||
// ui->tblProgram->setItem(ui->tblProgram->rowCount() - 1, 0, new QTableWidgetItem(commands.last())); | ||
// ui->tblProgram->setItem(ui->tblProgram->rowCount() - 2, 1, new QTableWidgetItem("В очереди")); | ||
// ui->tblProgram->setItem(ui->tblProgram->rowCount() - 2, 2, new QTableWidgetItem("")); | ||
// ui->tblProgram->item(ui->tblProgram->rowCount() - 2, 1)->setFlags(Qt::ItemIsEnabled); | ||
// ui->tblProgram->item(ui->tblProgram->rowCount() - 2, 2)->setFlags(Qt::ItemIsEnabled); | ||
} | ||
|
||
m_programLoading = false; | ||
|
||
ui->tblProgram->setModel(&m_tableModel); | ||
ui->tblProgram->setColumnWidth(0, 400); | ||
ui->tblProgram->setColumnWidth(1, 150); | ||
ui->tblProgram->horizontalHeader()->setStretchLastSection(true); | ||
|
||
m_viewParser.reset(); | ||
m_viewParser.toObjRedux(commands, 1); | ||
ui->glwVisualizator->fitDrawables(); | ||
} | ||
|
||
void frmMain::clearTable() | ||
{ | ||
m_tableModel.clear(); | ||
m_tableModel.insertRow(0); | ||
} | ||
|
||
void frmMain::on_cmdFit_clicked() | ||
{ | ||
ui->glwVisualizator->fitDrawables(); | ||
} | ||
|
||
void frmMain::on_cmdFileSend_clicked() | ||
{ | ||
} | ||
|
||
void frmMain::on_tblProgram_cellChanged(QModelIndex i1, QModelIndex i2) | ||
{ | ||
if (i1.column() != 0) return; | ||
if (i1.row() == (m_tableModel.rowCount() - 1) && m_tableModel.data(m_tableModel.index(i1.row(), 0)).toString() != "") { | ||
m_tableModel.setData(m_tableModel.index(m_tableModel.rowCount() - 1, 1), "В очереди"); | ||
m_tableModel.insertRow(m_tableModel.rowCount()); | ||
if (!m_programLoading) ui->tblProgram->setCurrentIndex(m_tableModel.index(i1.row() + 1, 0)); | ||
} else if (i1.row() != (m_tableModel.rowCount() - 1) && m_tableModel.data(m_tableModel.index(i1.row(), 0)).toString() == "") { | ||
ui->tblProgram->setCurrentIndex(m_tableModel.index(i1.row() + 1, 0)); | ||
m_tableModel.removeRow(i1.row()); | ||
} | ||
|
||
if (!m_programLoading) { | ||
QList<QString> commands; | ||
|
||
for (int i = 0; i < m_tableModel.rowCount(); i++) { | ||
commands.append(m_tableModel.data(m_tableModel.index(i, 0)).toString()); | ||
} | ||
|
||
m_viewParser.reset(); | ||
m_viewParser.toObjRedux(commands, 1); | ||
//ui->glwVisualizator->fitDrawables(); | ||
ui->glwVisualizator->update(); | ||
} | ||
} | ||
|
||
void frmMain::on_cmdFileNew_clicked() | ||
{ | ||
clearTable(); | ||
m_viewParser.reset(); | ||
ui->glwVisualizator->fitDrawables(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef FRMMAIN_H | ||
#define FRMMAIN_H | ||
|
||
#include <QMainWindow> | ||
#include "gcodeviewparse.h" | ||
#include "gcodedrawer.h" | ||
#include "tooldrawer.h" | ||
#include "gcodetablemodel.h" | ||
|
||
namespace Ui { | ||
class frmMain; | ||
} | ||
|
||
class frmMain : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit frmMain(QWidget *parent = 0); | ||
~frmMain(); | ||
|
||
private slots: | ||
void on_actFileExit_triggered(); | ||
void on_cmdFileOpen_clicked(); | ||
void on_cmdFit_clicked(); | ||
void on_cmdFileSend_clicked(); | ||
|
||
void on_tblProgram_cellChanged(QModelIndex i1, QModelIndex i2); | ||
|
||
void on_cmdFileNew_clicked(); | ||
|
||
protected: | ||
void showEvent(QShowEvent *se); | ||
void resizeEvent(QResizeEvent *re); | ||
|
||
private: | ||
Ui::frmMain *ui; | ||
GcodeViewParse m_viewParser; | ||
GcodeDrawer m_codeDrawer; | ||
ToolDrawer m_toolDrawer; | ||
GCodeTableModel m_tableModel; | ||
bool m_programLoading; | ||
|
||
void processFile(QString fileName); | ||
void clearTable(); | ||
}; | ||
|
||
#endif // FRMMAIN_H |
Oops, something went wrong.