From 8fd32c033bcb3464efec5f7ccdb5dae45ecd36f8 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 25 Jul 2021 11:44:52 -0400 Subject: [PATCH] use widget name in more export dialogs --- src/kiri/export.js | 44 ++++++++++++++++++++++-------------------- src/mode/sla/client.js | 5 +++-- web/kiri/cxdlp.html | 2 -- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/kiri/export.js b/src/kiri/export.js index 563fe8e1..89d1b98d 100644 --- a/src/kiri/export.js +++ b/src/kiri/export.js @@ -20,19 +20,24 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ let printSeq = parseInt(SDB['kiri-print-seq'] || SDB['print-seq'] || "0") + 1; function exportFile(options) { - const mode = API.mode.get(); + let mode = API.mode.get(); + let names = API.widgets.all().map(w => w.meta ? w.meta.file : undefined) + .filter(v => v) + .map(v => v.replace(/ /g,'-')) + .map(v => v.substring(0,20)) + .map(v => v.split('.')[0]); API.event.emit('export', mode); switch (mode) { - case 'LASER': return callExportLaser(options); - case 'FDM': return callExport(options, mode); - case 'CAM': return callExport(options, mode); - case 'SLA': return callExportSLA(options); + case 'LASER': return callExportLaser(options, names); + case 'FDM': return callExport(options, mode, names); + case 'CAM': return callExport(options, mode, names); + case 'SLA': return callExportSLA(options, names); } } - function callExport(callback, mode) { + function callExport(callback, mode, names) { let alert = API.feature.work_alerts ? API.show.alert("Exporting") : null; - const gcode = []; + let gcode = []; KIRI.client.export(API.conf.get(), (line) => { gcode.push(line); }, (output, error) => { @@ -42,24 +47,24 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ } else if (callback) { callback(gcode.join('\r\n'), output); } else { - exportGCodeDialog(gcode.join('\r\n'), output); + exportGCodeDialog(gcode.join('\r\n'), output, names); } }); } - function callExportLaser(options) { + function callExportLaser(options, names) { KIRI.client.export(API.conf.get(), (line) => { console.log({unexpected_line: line}); }, (output, error) => { if (error) { API.show.alert(error, 5); } else { - exportLaserDialog(output); + exportLaserDialog(output, names); } }); } - function callExportSLA(options) { + function callExportSLA(options, names) { KIRI.client.export(API.conf.get(), (line) => { API.show.progress(line.progress, "exporting"); }, (output, error) => { @@ -67,13 +72,16 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ if (error) { API.show.alert(error, 5); } else { - KIRI.driver.SLA.printDownload(output, API); + KIRI.driver.SLA.printDownload(output, API, names); } }); } - function exportLaserDialog(data) { - const filename = "laser-"+(new Date().getTime().toString(36)); + function exportLaserDialog(data, names) { + SDB['kiri-print-seq'] = printSeq++; + + const fileroot = names[0] || "laser"; + const filename = `${fileroot}-${(printSeq.toString().padStart(3,"0"))}`; const settings = API.conf.get(); const driver = KIRI.driver.LASER; @@ -111,17 +119,11 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ }); } - function exportGCodeDialog(gcode, info) { + function exportGCodeDialog(gcode, info, names) { SDB['kiri-print-seq'] = printSeq++; let settings = API.conf.get(), MODE = API.mode.get_id(), - names = API.widgets.all() - .map(w => w.meta ? w.meta.file : undefined) - .filter(v => v) - .map(v => v.replace(/ /g,'-')) - .map(v => v.substring(0,20)) - .map(v => v.split('.')[0]), name = names[0] || (MODE === MODES.CAM ? "cnc" : "print"), pre = `${name}-${(printSeq.toString().padStart(3,"0"))}`, filename = pre,// + (new Date().getTime().toString(36)), diff --git a/src/mode/sla/client.js b/src/mode/sla/client.js index 38169f04..3bd2a84b 100644 --- a/src/mode/sla/client.js +++ b/src/mode/sla/client.js @@ -19,9 +19,10 @@ }); }; - SLA.printDownload = function(output, API) { + SLA.printDownload = function(output, API, names) { const { file, width, height, layers } = output; - const filename = `print-${new Date().getTime().toString(36)}`; + const fileroot = names[0] || "print"; + const filename = `${fileroot}-${new Date().getTime().toString(36)}`; API.ajax("/kiri/output-sla.html", html => { API.ui.print.innerHTML = html; diff --git a/web/kiri/cxdlp.html b/web/kiri/cxdlp.html index df0c6ed1..0e5dd1f9 100644 --- a/web/kiri/cxdlp.html +++ b/web/kiri/cxdlp.html @@ -30,13 +30,11 @@ reader.onloadend = (e) => { let cxdlp = window.cxdlp = new CXDLP(); cxdlp.read(new DataView(e.target.result), 0); - console.log({cxdlp}); slider.max = layers.value = cxdlp.layers.length - 1; render(slider.value = layer.value = 0); meta(cxdlp); }; reader.readAsArrayBuffer(files[0]); - console.log("drop", files); ev.stopPropagation(); ev.preventDefault(); }, false);