mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 05:37:55 +01:00
add support for start and end code
This commit is contained in:
parent
43af4e05ab
commit
10fb3714c7
@ -122,6 +122,15 @@ export default class {
|
||||
return this;
|
||||
}
|
||||
|
||||
addGCode(gcode, { temperature, bedTemperature, heatedbed }) {
|
||||
gcode = gcode
|
||||
.replace(/{temperature}/gi, temperature)
|
||||
.replace(/{bedTemperature}/gi, bedTemperature)
|
||||
.replace(/{if heatedBed}/gi, heatedbed ? '' : ';');
|
||||
|
||||
this._addGCode(gcode);
|
||||
}
|
||||
|
||||
getGCode() {
|
||||
return {
|
||||
gcode: this._gcode,
|
||||
|
@ -76,16 +76,20 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev
|
||||
function gcodeToString(gcode) {
|
||||
const currentValues = {};
|
||||
return gcode.reduce((string, command) => {
|
||||
let first = true;
|
||||
for (const action in command) {
|
||||
const value = command[action];
|
||||
const currentValue = currentValues[action];
|
||||
if (first) {
|
||||
string += `${action}${value}`;
|
||||
first = false;
|
||||
} else if (currentValue !== value) {
|
||||
string += ` ${action}${value}`;
|
||||
currentValues[action] = value;
|
||||
if (typeof command === 'string') {
|
||||
string += command;
|
||||
} else {
|
||||
let first = true;
|
||||
for (const action in command) {
|
||||
const value = command[action];
|
||||
const currentValue = currentValues[action];
|
||||
if (first) {
|
||||
string += `${action}${value}`;
|
||||
first = false;
|
||||
} else if (currentValue !== value) {
|
||||
string += ` ${action}${value}`;
|
||||
currentValues[action] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
string += '\n';
|
||||
@ -101,7 +105,10 @@ function createGcodeGeometry(gcode) {
|
||||
|
||||
let lastPoint = [0, 0, 0];
|
||||
for (let i = 0; i < gcode.length; i ++) {
|
||||
const { G, F, X, Y, Z } = gcode[i];
|
||||
const command = gcode[i];
|
||||
if (typeof command === 'string') continue;
|
||||
|
||||
const { G, F, X, Y, Z } = command;
|
||||
|
||||
if (X || Y || Z) {
|
||||
if (G === 1) {
|
||||
|
@ -22,6 +22,8 @@ export default function slicesToGCode(slices, settings) {
|
||||
|
||||
const gcode = new GCode(nozzleToFilamentRatio);
|
||||
|
||||
if (settings.startCode) gcode.addGCode(settings.startCode, settings);
|
||||
|
||||
const defaultProfile = {
|
||||
travelProfile: travel,
|
||||
retractionProfile: retraction
|
||||
@ -77,6 +79,8 @@ export default function slicesToGCode(slices, settings) {
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.endCode) gcode.addGCode(settings.endCode, settings);
|
||||
|
||||
return gcode.getGCode();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user