forked from Ultimaker/CuraEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcodeExport.h
212 lines (162 loc) · 4.92 KB
/
gcodeExport.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
212
/** Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License */
#ifndef GCODEEXPORT_H
#define GCODEEXPORT_H
#include <stdio.h>
#include "settings.h"
#include "comb.h"
#include "utils/intpoint.h"
#include "utils/polygon.h"
#include "timeEstimate.h"
class GCodeExport
{
private:
FILE* f;
double extrusionAmount;
double extrusionPerMM;
double retractionAmount;
double extruderSwitchRetraction;
double minimalExtrusionBeforeRetraction;
double extrusionAmountAtPreviousRetraction;
Point3 currentPosition;
Point extruderOffset[MAX_EXTRUDERS];
int currentSpeed, retractionSpeed;
int zPos;
bool isRetracted;
int extruderNr;
int currentFanSpeed;
int flavor;
double totalFilament[MAX_EXTRUDERS];
double totalPrintTime;
TimeEstimateCalculator estimateCalculator;
public:
GCodeExport();
~GCodeExport();
void replaceTagInStart(const char* tag, const char* replaceValue);
void setExtruderOffset(int id, Point p);
void setFlavor(int flavor);
int getFlavor();
void setFilename(const char* filename);
bool isValid();
void setExtrusion(int layerThickness, int filamentDiameter, int flow);
void setRetractionSettings(int retractionAmount, int retractionSpeed, int extruderSwitchRetraction, int minimalExtrusionBeforeRetraction);
void setZ(int z);
Point getPositionXY();
int getPositionZ();
int getExtruderNr();
double getTotalFilamentUsed(int e);
double getTotalPrintTime();
void updateTotalPrintTime();
void addComment(const char* comment, ...);
void addLine(const char* line, ...);
void resetExtrusionValue();
void addDelay(double timeAmount);
void addMove(Point p, int speed, int lineWidth);
void addRetraction();
void switchExtruder(int newExtruder);
void addCode(const char* str);
void addFanCommand(int speed);
int getFileSize();
void tellFileSize();
};
class GCodePathConfig
{
public:
int speed;
int lineWidth;
const char* name;
bool spiralize;
GCodePathConfig() : speed(0), lineWidth(0), name(NULL), spiralize(false) {}
GCodePathConfig(int speed, int lineWidth, const char* name) : speed(speed), lineWidth(lineWidth), name(name), spiralize(false) {}
void setData(int speed, int lineWidth, const char* name)
{
this->speed = speed;
this->lineWidth = lineWidth;
this->name = name;
}
};
class GCodePath
{
public:
GCodePathConfig* config;
bool retract;
int extruder;
vector<Point> points;
bool done;//Path is finished, no more moves should be added, and a new path should be started instead of any appending done to this one.
};
class GCodePlanner
{
private:
GCodeExport& gcode;
Point lastPosition;
vector<GCodePath> paths;
Comb* comb;
GCodePathConfig travelConfig;
int extrudeSpeedFactor;
int travelSpeedFactor;
int currentExtruder;
int retractionMinimalDistance;
bool forceRetraction;
bool alwaysRetract;
double extraTime;
double totalPrintTime;
private:
GCodePath* getLatestPathWithConfig(GCodePathConfig* config);
void forceNewPathStart();
public:
GCodePlanner(GCodeExport& gcode, int travelSpeed, int retractionMinimalDistance);
~GCodePlanner();
bool setExtruder(int extruder)
{
if (extruder == currentExtruder)
return false;
currentExtruder = extruder;
return true;
}
int getExtruder()
{
return currentExtruder;
}
void setCombBoundary(Polygons* polygons)
{
if (comb)
delete comb;
if (polygons)
comb = new Comb(*polygons);
else
comb = NULL;
}
void setAlwaysRetract(bool alwaysRetract)
{
this->alwaysRetract = alwaysRetract;
}
void forceRetract()
{
forceRetraction = true;
}
void setExtrudeSpeedFactor(int speedFactor)
{
if (speedFactor < 1) speedFactor = 1;
this->extrudeSpeedFactor = speedFactor;
}
int getExtrudeSpeedFactor()
{
return this->extrudeSpeedFactor;
}
void setTravelSpeedFactor(int speedFactor)
{
if (speedFactor < 1) speedFactor = 1;
this->travelSpeedFactor = speedFactor;
}
int getTravelSpeedFactor()
{
return this->travelSpeedFactor;
}
void addTravel(Point p);
void addExtrusionMove(Point p, GCodePathConfig* config);
void moveInsideCombBoundary(int distance);
void addPolygon(PolygonRef polygon, int startIdx, GCodePathConfig* config);
void addPolygonsByOptimizer(Polygons& polygons, GCodePathConfig* config);
void forceMinimalLayerTime(double minTime, int minimalSpeed);
void writeGCode(bool liftHeadIfNeeded, int layerThickness);
};
#endif//GCODEEXPORT_H