factor device dialog out of init. remove Pallete3 support
This commit is contained in:
parent
05ea8a0b35
commit
f05bcbce4e
7 changed files with 402 additions and 649 deletions
|
|
@ -517,133 +517,6 @@ function exportGCodeDialog(gcode, sections, info, names) {
|
|||
})
|
||||
};
|
||||
|
||||
// in palette mode, show download button
|
||||
let downloadPalette = $('print-palette');
|
||||
downloadPalette.style.display = info.segments ? 'flex' : 'none';
|
||||
// generate MAFX downloadble file
|
||||
if (info.segments) {
|
||||
// todo: reduce segments to eliminate 0 lenghts and transitions before 150mm
|
||||
let { settings, segments } = info;
|
||||
let { device, bounds } = settings;
|
||||
let { min, max } = bounds;
|
||||
let extras = device.extras || {};
|
||||
let pinfo = extras.palette || {};
|
||||
// filter pings to those occuring after all tubes combined
|
||||
let pings = info.purges || [];
|
||||
let driveInfo = {};
|
||||
let volume = {};
|
||||
let length = {};
|
||||
// clean up and round pings
|
||||
pings.forEach(p => {
|
||||
p.length = p.length.round(3);
|
||||
// p.length = (p.length - pinfo.offset).round(2);
|
||||
// p.length = (p.length + pinfo.offset).round(2);
|
||||
p.extrusion = p.extrusion.round(3);
|
||||
});
|
||||
// add length of push filament to the last segment
|
||||
segments.peek().emitted += pinfo.push;
|
||||
let lastEmit = 0;
|
||||
let ratioVolume = (0.4 * 0.4) / (1.75 * 1.75);
|
||||
for (let seg of segments) {
|
||||
let seginfo = driveInfo[seg.tool] = driveInfo[seg.tool] || { length: 0, volume: 0 };
|
||||
seg.emitted += pinfo.offset;
|
||||
seginfo.length += seg.emitted - lastEmit;
|
||||
seginfo.volume = seginfo.length * ratioVolume;
|
||||
volume[seg.tool+1] = seginfo.volume.round(2);
|
||||
length[seg.tool+1] = seginfo.length.round(2);
|
||||
lastEmit = seg.emitted;
|
||||
}
|
||||
let totalLength = Object.values(length).reduce((a,v) => a+v).round(2);
|
||||
let totalVolume = Object.values(volume).reduce((a,v) => a+v).round(2);
|
||||
// console.log({info, device, pinfo, segments, volume, length, totalLength});
|
||||
let meta = {
|
||||
version: "3.2",
|
||||
printerProfile: {
|
||||
id: pinfo.printer,
|
||||
name: device.deviceName || "My Printer"
|
||||
},
|
||||
preheatTemperature: { nozzle: [0], bed: 0 },
|
||||
paletteNozzle: 0,
|
||||
time: info.time.round(1),
|
||||
volume,
|
||||
length,
|
||||
totalLength,
|
||||
totalVolume,
|
||||
inputsUsed: Object.keys(driveInfo).length,
|
||||
splices: segments.length,
|
||||
pings: pings.length,
|
||||
boundingBox: {
|
||||
min: [ min.x, min.y, min.z ],
|
||||
max: [ max.x, max.y, max.z ]
|
||||
},
|
||||
filaments: Object.keys(driveInfo).map(v => { return {
|
||||
name: `Color${v}`,
|
||||
type: "Filament",
|
||||
color: `#${v}0${v}0${v}0`,
|
||||
materialId: parseInt(v) + 1,
|
||||
filamentId: parseInt(v) + 1
|
||||
}}),
|
||||
};
|
||||
let lastDrive;
|
||||
let algokeys = {};
|
||||
let algorithms = [];
|
||||
let defaultSplice = {
|
||||
compression: pinfo.press,
|
||||
cooling: pinfo.cool,
|
||||
heat: pinfo.heat
|
||||
};
|
||||
for (let key of Object.keys(driveInfo)) {
|
||||
key = parseInt(key) + 1;
|
||||
algorithms.push({
|
||||
ingoingId: key,
|
||||
outgoingId: key,
|
||||
...defaultSplice
|
||||
});
|
||||
}
|
||||
let palette = {
|
||||
version: "3.0",
|
||||
drives: [0, 0, 0, 0, 0, 0, 0, 0].map((v,i) => {
|
||||
return driveInfo[i] ? i+1 : 0
|
||||
}),
|
||||
splices: segments.filter(r => {
|
||||
return r.emitted >= 150;
|
||||
}).map(r => {
|
||||
if (lastDrive >= 0 && lastDrive !== r.tool) {
|
||||
let key = `${lastDrive}+${r.tool}`;
|
||||
if (!algokeys[key]) {
|
||||
let rec = algokeys[key] = {
|
||||
ingoingId: lastDrive + 1,
|
||||
outgoingId: r.tool + 1,
|
||||
...defaultSplice
|
||||
};
|
||||
algorithms.push(rec);
|
||||
}
|
||||
}
|
||||
lastDrive = r.tool;
|
||||
return { id: r.tool + 1, length: r.emitted.round(2) }
|
||||
}),
|
||||
pings,
|
||||
algorithms
|
||||
};
|
||||
let png;
|
||||
kiri.client.png({}, data => {
|
||||
png = data.png;
|
||||
});
|
||||
console.log({meta,palette});
|
||||
downloadPalette.onclick = function() {
|
||||
kiri.client.zip([
|
||||
{name:"meta.json", data:JSON.stringify(meta,undefined,4)},
|
||||
{name:"palette.json", data:JSON.stringify(palette,undefined,4)},
|
||||
{name:"thumbnail.png", data:png.buffer}
|
||||
], progress => {
|
||||
api.show.progress(progress.percent/100, "generating palette files");
|
||||
}, output => {
|
||||
api.show.progress(0);
|
||||
api.util.download(output, `${$('print-filename').value}.mafx`);
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
// octoprint setup
|
||||
$('send-to-octohead').style.display = octo ? '' : 'none';
|
||||
$('send-to-octoprint').style.display = octo ? '' : 'none';
|
||||
|
|
|
|||
Loading…
Reference in a new issue