-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathg2m.hpp
More file actions
132 lines (116 loc) · 5.46 KB
/
Copy pathg2m.hpp
File metadata and controls
132 lines (116 loc) · 5.46 KB
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
/***************************************************************************
* Copyright (C) 2010 by Mark Pictor *
* mpictor@gmail.com *
* modifications Copyright (C) 2011 by Anders Wallin *
* anders.e.e.wallin@gmail.com *
* modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/// \file
/// G-code to tool path: drives the interpreter and collects canon lines.
#ifndef GTOM_HH
#define GTOM_HH
#include <vector>
#include <limits.h>
#include <iostream>
#include <fstream>
#include <QString>
#include <QObject>
#include "canonLine.hpp"
namespace g2m {
/// \brief This class runs the embedded rs274ngc interpreter, and creates a canonLine object
/// for each canonical command generated by the interpreter.
class g2m : public QObject {
Q_OBJECT;
public:
/// Starts at the origin, with no origin offset and debug off.
g2m() { debug = false; initialPos = Pose( Point(0,0,0), Point(0,0,0) ); userOrigin = Pose( Point(0,0,0), Point(0,0,0) ); total_gcode_lines = 0; }
/// \returns every canon line of the last run
std::vector<canonLine*> getCanonLines() { return lineVector; }
/// \param init the pose the machine starts from
void setInitialPos(Pose init) { initialPos = init; }
/// \param origin the active origin offset
void setOrigin(Pose origin) { userOrigin = origin; }
/// \returns the active origin offset
Pose getOrigin() { return userOrigin; }
/*
int toGcodeLineNo(int canonLineNo) {
if ((unsigned)canonLineNo + 1 >= lineTable.size())
return ++canonLineNo;
else
return lineTable[canonLineNo];
}
*/
public slots:
/// run the interpreter (async wrapper)
void interpret_file();
/// actual interpreter implementation
void interpret_file_async();
/// set the path to the .ngc g-code file
void setFile(QString infile) {
emit debugMessage( tr("g2m: setting file %1").arg(infile) );
file = infile;
}
/// set the path to the tootable
void setToolTable(QString tbl_file) {
emit debugMessage( tr("g2m: setting tooltable %1").arg(tbl_file) );
tooltable = tbl_file;
}
/// set debug mode on/off
void setDebug(bool d) {debug = d;}
signals:
/// debug messages
void debugMessage(QString s);
/// emitted while .ngc g-code file is read. the g-code line read.
void gcodeLineMessage(QString s);
/// emitted during interpret(), the canon line as a string
void canonLineMessage(QString s);
/// emitted during interpret(), the current canonLine object
void signalCanonLine(canonLine* line);
// emitted when M2 is reached
/// the program's end marker has been reached
void signalNCend();
// emitted when interpreter errored
/// the interpreter stopped early \param s the message to show
void signalError(QString s);
// emitted when parsing complete with all canon lines
/// the finished tool path \param lines every canon line of the run
void signalCanonLines(QVector<canonLine*> lines);
protected:
/// tool table to hand the interpreter; empty means use its built-in default
QString toolTablePath();
void interpret(QString tempFile);
bool processCanonLine(std::string l);
void infoMsg(std::string s);
/// the canonLines produced when interpreting g-code
std::vector<canonLine*> lineVector;
/// path to .ngc g-code file
QString file;
/// path to tooltable
QString tooltable;
/// flag for debug mode
bool debug;
/// number of lines in the .ngc g-code file
int gcode_lines;
private:
Pose initialPos; ///< pose the machine starts from
Pose userOrigin; ///< active origin offset
int total_gcode_lines; ///< line-number comments seen in the output
//std::vector<int> lineTable; not used for now
};
} // end namespace
#endif //GTOM_HH