add option to export gcode as a zip file with discrete operations

This commit is contained in:
Stewart Allen 2022-01-24 15:22:20 -05:00
commit 5788b800a8
3 changed files with 50 additions and 18 deletions

View file

@ -22,6 +22,7 @@
time = 0, time = 0,
lines = 0, lines = 0,
bytes = 0, bytes = 0,
opnum = 0,
factor = 1, factor = 1,
output = [], output = [],
spindle = 0, spindle = 0,
@ -70,10 +71,14 @@
time_sec: 0, time_sec: 0,
time_ms: 0, time_ms: 0,
time: 0 time: 0
}, }
append;
append = function(line) { function section(section) {
append();
online({ section });
}
function append(line) {
if (line) { if (line) {
lines++; lines++;
bytes += line.length; bytes += line.length;
@ -83,7 +88,7 @@
online(output.join("\r\n")); online(output.join("\r\n"));
output = []; output = [];
} }
}; }
function filterEmit(array, consts) { function filterEmit(array, consts) {
if (!array) return; if (!array) return;
@ -234,6 +239,7 @@
points++; points++;
} }
section('header');
if (!stripComments) { if (!stripComments) {
append(`; Generated by Kiri:Moto ${KIRI.version}`); append(`; Generated by Kiri:Moto ${KIRI.version}`);
append(`; ${new Date().toString()}`); append(`; ${new Date().toString()}`);
@ -291,6 +297,7 @@
if (mode !== layerout.mode) { if (mode !== layerout.mode) {
if (mode && !stripComments) append("; ending " + mode + " op after " + Math.round(time/60) + " seconds"); if (mode && !stripComments) append("; ending " + mode + " op after " + Math.round(time/60) + " seconds");
mode = layerout.mode; mode = layerout.mode;
if (mode) section(`op-${opnum++}-${mode}`);
if (!stripComments) append("; starting " + mode + " op"); if (!stripComments) append("; starting " + mode + " op");
} }
if (layerout.spindle && layerout.spindle !== spindle) { if (layerout.spindle && layerout.spindle !== spindle) {
@ -312,6 +319,7 @@
if (mode && !stripComments) append("; ending " + mode + " op after " + Math.round(time/60) + " seconds"); if (mode && !stripComments) append("; ending " + mode + " op after " + Math.round(time/60) + " seconds");
// emit gcode post // emit gcode post
section('footer');
filterEmit(gcodes.gcodePost, consts); filterEmit(gcodes.gcodePost, consts);
// flush buffered gcode // flush buffered gcode

View file

@ -38,8 +38,17 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
function callExport(callback, mode, names) { function callExport(callback, mode, names) {
let alert = API.feature.work_alerts ? API.show.alert("Exporting") : null; let alert = API.feature.work_alerts ? API.show.alert("Exporting") : null;
let gcode = []; let gcode = [];
let section = [];
let sections = { };
KIRI.client.export(API.conf.get(), (line) => { KIRI.client.export(API.conf.get(), (line) => {
if (typeof line !== 'string') {
if (line.section) {
sections[line.section] = section = [];
}
return;
}
gcode.push(line); gcode.push(line);
section.push(line);
}, (output, error) => { }, (output, error) => {
API.hide.alert(alert); API.hide.alert(alert);
if (error) { if (error) {
@ -47,7 +56,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
} else if (callback) { } else if (callback) {
callback(gcode.join('\r\n'), output); callback(gcode.join('\r\n'), output);
} else { } else {
exportGCodeDialog(gcode.join('\r\n'), output, names); exportGCodeDialog(gcode, mode === 'CAM' ? sections : undefined, output, names);
} }
}); });
} }
@ -90,10 +99,6 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
driver.exportSVG(settings, data), driver.exportSVG(settings, data),
$('print-filename').value + ".svg" $('print-filename').value + ".svg"
); );
// saveAs(new Blob(
// [driver.exportSVG(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".svg");
} }
function download_dxf() { function download_dxf() {
@ -101,10 +106,6 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
driver.exportDXF(settings, data), driver.exportDXF(settings, data),
$('print-filename').value + ".dxf" $('print-filename').value + ".dxf"
); );
// saveAs(new Blob(
// [driver.exportDXF(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".dxf");
} }
function download_gcode() { function download_gcode() {
@ -112,10 +113,6 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
driver.exportGCode(settings, data), driver.exportGCode(settings, data),
$('print-filename').value + ".gcode" $('print-filename').value + ".gcode"
); );
// saveAs(new Blob(
// [driver.exportGCode(settings, data)],
// {type:"application/octet-stream"}),
// $('print-filename').value + ".gcode");
} }
API.ajax("/kiri/output-laser.html", function(html) { API.ajax("/kiri/output-laser.html", function(html) {
@ -131,7 +128,7 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
}); });
} }
function exportGCodeDialog(gcode, info, names) { function exportGCodeDialog(gcode, sections, info, names) {
SDB['kiri-print-seq'] = printSeq++; SDB['kiri-print-seq'] = printSeq++;
let settings = API.conf.get(), let settings = API.conf.get(),
@ -150,6 +147,9 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
grid_local, grid_local,
grid_uuid; grid_uuid;
// join gcode array into a string
gcode = gcode.join('\r\n');
// run gcode post processor function (when supplied and valid) // run gcode post processor function (when supplied and valid)
if (codeproc && self[codeproc]) { if (codeproc && self[codeproc]) {
gcode = self[codeproc](gcode); gcode = self[codeproc](gcode);
@ -467,6 +467,29 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
calcWeight(); calcWeight();
} }
// in cam mode, show zip file option
let downloadZip = $('print-zip');
downloadZip.style.display = sections ? 'flex' : 'none';
downloadZip.onclick = function() {
let files = [];
for (let [ name, data ] of Object.entries(sections)) {
if (name.indexOf('op-') === 0) {
let head = sections.header || [];
let foot = sections.footer || [];
files.push({
name: `${name}.${fileext}`,
data: [ ...head, ...data, ...foot ].join('\r\n')
})
}
}
KIRI.client.zip(files, progress => {
API.show.progress(progress.percent/100, "generating zip files");
}, output => {
API.show.progress(0);
API.util.download(output, `${$('print-filename').value}.zip`);
})
};
// in palette mode, show download button // in palette mode, show download button
let downloadPalette = $('print-palette'); let downloadPalette = $('print-palette');
downloadPalette.style.display = info.segments ? 'flex' : 'none'; downloadPalette.style.display = info.segments ? 'flex' : 'none';

View file

@ -21,6 +21,7 @@
<div class="f-row box"> <div class="f-row box">
<button id="print-download" class="grow">download</button> <button id="print-download" class="grow">download</button>
<button id="print-palette" class="grow">palette</button> <button id="print-palette" class="grow">palette</button>
<button id="print-zip" class="grow">zip file</button>
</div> </div>
<div id="send-to-octohead" class="header"><label>octoprint</label></div> <div id="send-to-octohead" class="header"><label>octoprint</label></div>