-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgcode.h
211 lines (159 loc) · 4.95 KB
/
gcode.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
#ifndef GCODE_H
#define GCODE_H
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <QString>
#include <iostream>
#include "mgl/pather.h"
#include "mgl/miracle.h"
#include "mgl/configuration.h"
using namespace std;
// Object that represents a single parsed line of GCode.
class gcode {
private:
class gCodeParameter {
public:
char code;
double value;
gCodeParameter(char code, double value) {
this->code = code;
this->value = value;
}
};
// These are the letter codes that we understand
static char codes[];
// The actual GCode command string
string command;
// Parsed out comment
string comment;
// The set of parameters in this GCode
vector<gCodeParameter> parameters;
// Find any comments, store them, then remove them from the command
void parseComments();
// Find any codes, and store them
void parseCodes();
public:
gcode(string command);
string getCommand();
string getComment();
bool hasCode(char searchCode);
double getCodeValue(char searchCode);
};
// stab at representing all of the layers in an object
class layerMap {
private:
// vector containing all of the layer heights we know about
vector<float> heights;
public:
// Record that we've seen a specific z height. If it's already in the list, it is ignored, otherwise it is added.
void recordHeight(float height);
// Get the height corresponding to a given layer
float getLayerHeight(int layer);
// Test if a height is in a given layer
bool heightInLayer(int layer, float height);
// Test if a height is higher than a given layer
bool heightGreaterThanLayer(int layer, float height);
// Test if a height is lower than a given later
bool heightLessThanLayer(int layer, float height);
// Return the number of layers that we know about
int size();
void clear();
};
template <class T>
class minMax {
private:
T min;
T max;
bool initialized;
public:
minMax() : initialized(false) {}
void evaluate(T dataPoint) {
if (!initialized) {
initialized = true;
min = dataPoint;
max = dataPoint;
}
else {
if (dataPoint < min) {
min = dataPoint;
}
if (dataPoint > max) {
max = dataPoint;
}
}
}
T getMin () { return min; }
T getMax () { return max; }
};
enum PointKind { unknown, travel, shell, perimeter, infill, roofing, flooring, surface, invisible};
// TODO: Use whatever the equivalent class here should be.
// TODO: This is also unravelling the state machine into individual events- maybe it's overkill? Is there a better model?
struct point {
public:
PointKind kind;
int nb;
// Destination of this instruction
float x;
float y;
float z;
// true if the toolhead is on during this move
//bool toolEnabled;
// Feedrate of this instruction
float feedrate;
// Flowrate of this instruction
float flowrate;
point(PointKind kind, int nb, float x, float y, float z, float feedrate, float flowrate) :
kind(kind), nb(nb), x(x), y(y), z(z), feedrate(feedrate), flowrate(flowrate)
{
// if(kind == travel) cout << "#";
}
};
// Object that can open a file containing GCode and turn it into a series of lines
class gcodeModel
{
bool toolEnabled;
public:
//mgl::Tomograph tomograph;
//mgl::Regions regions;
std::string modelFile;
mgl::GCoderConfig gcoderCfg;
std::vector<mgl::SliceData> slices;
mgl::LayerPaths slicePaths;
mgl::LayerMeasure layerMeasure;
vector<point> points;
layerMap map;
unsigned int getMapSize(){return map.size();}
unsigned int getPointCount(){return points.size();}
minMax<float> feedrateBounds;
minMax<float> flowrateBounds;
minMax<float> zHeightBounds;
bool viewSurfs;
bool viewRoofs;
bool viewFloors;
bool viewLoops;
bool viewInfills;
public:
gcodeModel();
~gcodeModel();
void loadSliceData(const mgl::Tomograph &tomograph,
const mgl::RegionList ®ions,
const std::vector<mgl::SliceData> &sliceData);
void loadSliceData(const mgl::LayerLoops& layerloops,
const mgl::RegionList ®ions,
const mgl::Grid &grid,
const mgl::LayerPaths& layerpaths);
void loadRegions(const mgl::Tomograph &tomograph,
const mgl::RegionList ®ions);
void loadRegions(const mgl::LayerLoops& layerloops,
const mgl::RegionList& regions,
const mgl::Grid &grid);
void loadGCode(QString filename);
void exportGCode(QString filename);
void saveMiracleGcode(const char *filename, void *prog);
float getModelZCenter();
private:
void loadGcodeLine(const char* lineStr);
};
#endif // GCODE_H