store fdm and cam gcode output

This commit is contained in:
Stewart Allen 2020-11-08 17:35:40 -05:00
commit c78fedfbdc
7 changed files with 68 additions and 91 deletions

View file

@ -171,22 +171,22 @@ KIRI.work = {
});
},
printExport : function(settings, online, ondone) {
export : function(settings, online, ondone) {
let lines = [];
send("printExport", {settings:settings}, function(reply) {
send("export", {settings:settings}, function(reply) {
if (reply.line) {
online(reply.line);
}
if (reply.done) {
ondone(reply.done);
ondone(reply.output);
}
});
},
printGCode : function(callback) {
gcode : function(callback) {
let gcode = [];
let start = BASE.util.time();
send("printGCode", {}, function(reply) {
send("gcode", {}, function(reply) {
if (reply.line) {
gcode.push(reply.line);
} else {
@ -195,19 +195,6 @@ KIRI.work = {
callback(reply);
}
});
},
sliceToGCode : function(settings, vertices, callback) {
vertices = widget.getGeoVertices().buffer.slice(0);
let wid = new Date().toString(36);
send("slice", {settings:settings, id:wiwd, vertices:vertices, position:{x:0,y:0,z:0}}, function(reply) {
send("printSetup", {settings:settings}, function(reply) {
send("printGCode", {}, function(reply) {
callback(reply);
});
}, [vertices]);
callback(reply);
});
}
};

View file

@ -15,27 +15,45 @@
STATS = API.stats,
MODES = API.const.MODES;
KIRI.export = exportPrint;
KIRI.export = exportFile;
let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1;
function exportPrint(options) {
let currentPrint = API.print.get();
if (currentPrint) {
function isPrepared() {
return API.view.get() === API.const.VIEWS.PREVIEW;
}
function exportFile(options) {
if (isPrepared()) {
API.event.emit('export', API.mode.get());
switch (API.mode.get()) {
case 'LASER': return exportPrintLaser(currentPrint);
case 'FDM': return exportPrintGCODE(currentPrint, options);
case 'CAM': return exportPrintGCODE(currentPrint, options);
case 'SLA': return exportPrintSLA(currentPrint);
case 'LASER': return callExport();
case 'FDM': return callExport(options);
case 'CAM': return callExport(options);
case 'SLA': return exportSLA();
}
} else {
API.function.print(function() { exportPrint(options) });
API.function.prepare(function() {
exportFile(options)
});
}
}
function exportPrintSLA(currentPrint) {
if (currentPrint) {
function callExport(options) {
if (isPrepared()) {
const gcode = [];
KIRI.client.export(API.conf.get(), (line) => {
gcode.push(line);
}, (output) => {
exportGCodeDialog(gcode.join('\n'), output);
});
} else {
API.function.prepare(function() { exportPrint(options) });
}
}
function exportSLADialog(currentPrint) {
if (isPrepared()) {
if (currentPrint.exported) {
KIRI.driver.SLA.printDownload(currentPrint);
return;
@ -69,27 +87,13 @@
KIRI.driver.SLA.printDownload(currentPrint);
});
} else {
API.function.print(exportPrintSLA);
API.function.prepare(exportSLA);
}
}
function exportPrintGCODE(currentPrint, options) {
if (currentPrint) {
currentPrint.exportGCode(true, function(gcode) {
if (typeof(options) === 'function') {
options(gcode, currentPrint);
} else {
exportGCode(gcode, currentPrint);
}
});
} else {
API.function.print(function() { exportPrint(options) });
}
}
function exportPrintLaser(currentPrint) {
if (!currentPrint) {
return API.function.print(exportPrintLaser);
function exportLaserDialog(currentPrint) {
if (!isPrepared()) {
return API.function.prepare(exportLaser);
}
let filename = "laser-"+(new Date().getTime().toString(36));
@ -128,7 +132,7 @@
});
}
function exportGCode(gcode, currentPrint) {
function exportGCodeDialog(gcode, currentPrint) {
SDB['kiri-print-seq'] = printSeq++;
let settings = API.conf.get(),

View file

@ -43,7 +43,6 @@
STACKS = KIRI.stacks,
DRIVER = undefined,
onEvent = {},
currentPrint = null,
selectedMeshes = [],
localFilterKey ='kiri-gcode-filters',
localFilters = js2o(SDB.getItem(localFilterKey)) || [],
@ -229,9 +228,10 @@
function: {
slice: prepareSlices,
print: preparePrint,
prepare: preparePrint,
export: function() { KIRI.export(...arguments) },
cancel: cancelWorker,
clear: clearWidgetCache
clear: () => { console.log("api.function.clear unimplemented") }
},
hide: {
alert: function(rec) { alert2cancel(rec) },
@ -252,10 +252,6 @@
switch: switchMode,
set_expert: setExpert
},
print: {
get: function() { return currentPrint },
clear: clearPrint
},
probe: {
live : "https://live.grid.space",
grid : function() { return false },
@ -580,13 +576,11 @@
}
function hideSlices() {
let showing = false;
setOpacity(color.model_opacity);
STACKS.clear();
setOpacity(color.model_opacity);
forAllWidgets(function(widget) {
widget.setWireframe(false);
});
return showing;
}
function setWidgetVisibility(bool) {
@ -634,8 +628,9 @@
}
function loadCode(code, type) {
return alert2('currently unavailable');
setViewMode(VIEWS.PREVIEW);
clearPrint();
setOpacity(0);
currentPrint = kiri.newPrint(settings, []);
let center = settings.process.outputOriginCenter;
@ -682,7 +677,6 @@
if (feature.preview) {
setViewMode(VIEWS.PREVIEW);
clearPrint();
}
API.conf.save();
API.event.emit('preview.begin', pMode);
@ -730,25 +724,6 @@
if (KIRI.work.isSlicing()) KIRI.work.restart();
}
function clearWidgetCache() {
hideSlices();
clearSlices();
clearPrint();
}
function clearPrint() {
if (currentPrint) {
SPACE.platform.remove(currentPrint.group);
currentPrint = null;
}
}
function clearSlices() {
forAllWidgets(function(widget) {
widget.slices = null;
});
}
function showSlider() {
UI.layers.style.display = 'flex';
UI.slider.style.display = 'flex';
@ -777,7 +752,6 @@
}
hideSlider(true);
clearPrint();
platform.deselect();
setViewMode(VIEWS.SLICE);
@ -1954,10 +1928,11 @@
case VIEWS.ARRANGE:
$('lt-back').style.display = '';
KIRI.work.clear();
STACKS.clear();
hideSlider();
clearWidgetCache();
updateSliderMax();
setWidgetVisibility(true);
setOpacity(1);
break;
case VIEWS.SLICE:
$('lt-back').style.display = 'flex';
@ -2028,7 +2003,6 @@
API.conf.load();
API.conf.save();
// other housekeeping
clearWidgetCache();
triggerSettingsEvent();
platformUpdateSelected();
updateFields();

View file

@ -220,9 +220,9 @@
if (KIRI.client) {
// executed from kiri.js
KIRI.client.printExport(this.settings, online, ondone);
KIRI.client.export(this.settings, online, ondone);
} else {
if (!(driver && driver.printExport)) {
if (!(driver && driver.export)) {
console.log({missing_export_driver: mode});
ondone(null);
return;

View file

@ -129,15 +129,27 @@ KIRI.worker = {
send.done({ done: true, output: KIRI.codec.encode(layers) });
},
printExport: function(data, send) {
current.print.export(false, function(line, direct) {
send.data({line}, direct);
}, function(done, direct) {
send.done({done}, direct);
export: function(data, send) {
const mode = data.settings.mode;
const driver = KIRI.driver[mode];
if (!(driver && driver.export)) {
console.log({missing_export_driver: mode});
return send.done()
}
const output = driver.export(current.print, function(line) {
send.data({line});
});
const { time, lines, bytes, bounds } = current.print;
send.done({
done: true,
output: { time, lines, bytes, bounds }
});
},
printGCode: function(data, send) {
gcode: function(data, send) {
current.print.exportGCode(false, function(gcode) {
send.done({
gcode: gcode,

View file

@ -24,7 +24,7 @@
/**
* @returns {Array} gcode lines
*/
CAM.printExport = function printExport(print, online) {
CAM.export = function printExport(print, online) {
let widget = print.widgets[0];
if (!widget) return;

View file

@ -12,7 +12,7 @@
/**
* @returns {Array} gcode lines
*/
FDM.printExport = function(print, online) {
FDM.export = function(print, online) {
let layers = print.output,
settings = FDM.fixExtruders(print.settings),
device = settings.device,