-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcodeparser.cpp
55 lines (45 loc) · 1.01 KB
/
gcodeparser.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
#include "gcodeparser.h"
#include <QTextStream>
#include <QDebug>
GCodeParser::GCodeParser(QFile& file) :
_file(file),
_lastBlock(NULL)
{
}
void
GCodeParser::parse()
{
if (!_file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// Log an error???
qWarning("Unable to open file");
return;
}
QTextStream in(&_file);
int numLines = 0;
_lastBlock = NULL;
while (!in.atEnd())
{
QString line = in.readLine();
process_line(line, numLines+1);
numLines++;
}
_file.close();
qDebug() << "Processed" << numLines << "lines";
}
void
GCodeParser::process_line(QString& line, int lineNum)
{
CodeBlock* block = new CodeBlock(line, lineNum, _lastBlock);
_lastBlock = block;
_blocks.append(block);
// if (block->hasError())
// {
// QVector<QParse*> list = block->errors();
// for(int i=0; i<list.size(); i++)
// {
// qDebug() << *(list.at(i));
// }
// }
// qDebug() << line;
}