add preliminary MAFX file output for palette3

This commit is contained in:
Stewart Allen 2021-11-11 11:29:51 -05:00
commit c83945b07f
6 changed files with 105 additions and 5 deletions

View file

@ -106,6 +106,10 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
$('print-filename').value + ".gcode"); $('print-filename').value + ".gcode");
} }
function download_palette() {
console.log('todo');
}
API.ajax("/kiri/output-laser.html", function(html) { API.ajax("/kiri/output-laser.html", function(html) {
let segments = 0; let segments = 0;
data.forEach(layer => { segments += layer.length }); data.forEach(layer => { segments += layer.length });
@ -454,6 +458,98 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
calcWeight(); calcWeight();
} }
// 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 { bounds } = settings;
let { min, max } = bounds;
let driveInfo = {};
let volume = {};
let length = {};
for (let seg of segments) {
let seginfo = driveInfo[seg.tool] = driveInfo[seg.tool] || { length: 0, volume: 0 };
seginfo.length += seg.emitted;
seginfo.volume += seg.emitted * Math.PI;
volume[seg.tool+1] = seginfo.volume;
length[seg.tool+1] = seginfo.length;
}
let totalVolume = Object.values(volume).reduce((a,v) => a+v);
let meta = {
version: "3.2",
printerProfile: {
id: settings.extras.palette.printer,
name: "my printer"
},
preheatTemperature: { nozzle: [0], bed: 0 },
paletteNozzle: 0,
time: info.time.round(1),
volume,
length,
totalLength: info.distance.round(1),
totalVolume,
inputsUsed: Object.keys(driveInfo).length,
splices: segments.length,
pings: 0,
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: 1,
filamentId: parseInt(v)+1
}}),
};
let lastDrive;
let algokeys = {};
let algorithms = [];
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,
compression: 0,
cooling: 0,
heat: 0
};
algorithms.push(rec);
}
}
lastDrive = r.tool;
return { id: r.tool + 1, length: r.emitted.round(2) }
}),
pings: [],
algorithms
};
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)}
], progress => {
API.show.progress(progress.percent/100, "generating palette files");
}, output => {
API.show.progress(0);
API.util.download(output, `${name}.mafx`);
})
};
}
// octoprint setup // octoprint setup
$('send-to-octohead').style.display = octo ? '' : 'none'; $('send-to-octohead').style.display = octo ? '' : 'none';
$('send-to-octoprint').style.display = octo ? '' : 'none'; $('send-to-octoprint').style.display = octo ? '' : 'none';

View file

@ -641,14 +641,14 @@
let work = $('incwork').checked; let work = $('incwork').checked;
let json = API.conf.export({work, clear:true}); let json = API.conf.export({work, clear:true});
KIRI.client.zip([{ KIRI.client.zip([
name:"workspace.json", data:JSON.stringify(json)} {name:"workspace.json", data:JSON.stringify(json)}
], progress => { ], progress => {
API.show.progress(progress.percent/100, "compressing workspace"); API.show.progress(progress.percent/100, "compressing workspace");
}, output => { }, output => {
API.show.progress(0); API.show.progress(0);
API.util.download(output, `${name}.kmz`); API.util.download(output, `${name}.kmz`);
}) });
} }
}); });
} }

View file

@ -822,7 +822,7 @@
// force emit of buffer // force emit of buffer
append(); append();
print.segments = segments; print.segments = isPalette ? segments : undefined;
print.distance = emitted; print.distance = emitted;
print.lines = lines; print.lines = lines;
print.bytes = bytes + lines - 1; print.bytes = bytes + lines - 1;

View file

@ -1130,6 +1130,9 @@ th, tr, td, label {
#print-download { #print-download {
min-height: 4em !important; min-height: 4em !important;
} }
#print-palette {
display: none;
}
#code-preview-textarea { #code-preview-textarea {
width: 40em; width: 40em;
height: 12em; height: 12em;

View file

@ -216,7 +216,7 @@
</div> </div>
<div id="act-export"> <div id="act-export">
<i class="fas fa-file-download"></i> <i class="fas fa-file-download"></i>
<label id="label-export" title="generate downloadable files" lk="export">export</label> <label id="label-export" title="generate gcode" lk="export">export</label>
</div> </div>
</div> </div>
</div> </div>

View file

@ -20,6 +20,7 @@
<div class="header"><label>gcode</label></div> <div class="header"><label>gcode</label></div>
<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>
</div> </div>
<div id="send-to-octohead" class="header"><label>octoprint</label></div> <div id="send-to-octohead" class="header"><label>octoprint</label></div>