add optional speed chart in preview mode

This commit is contained in:
Stewart Allen 2020-11-10 21:48:04 -05:00
commit 2c646352ad
9 changed files with 102 additions and 9 deletions

View file

@ -166,7 +166,7 @@ KIRI.work = {
update(reply.progress, reply.message);
}
if (reply.done) {
done(reply.output);
done(reply.output, reply.speedColors);
}
});
},

View file

@ -608,6 +608,7 @@
reverseZoom: true,
showOrigin: false,
showRulers: false,
showSpeeds: true,
freeLayout: true,
autoLayout: true,
alignTop: true,

View file

@ -104,6 +104,11 @@
}
}
function speedSave() {
settings().controller.showSpeeds = UI.showSpeeds.checked;
API.platform.update_speeds();
}
function booleanSave() {
let control = settings().controller;
let isDark = control.dark;
@ -1222,7 +1227,8 @@
},
load: $('load-file'),
// focuser: $('focuser'),
speeds: $('speeds'),
speedbar: $('speedbar'),
container: container,
rotate: $('lt-rotate'),
@ -1354,20 +1360,23 @@
(UI.gcodePost = UC.newGCode(LANG.dv_foot_s, {title:LANG.dv_foot_l, modes:GCODE, area:gcode})).button
], {modes:GCODE, class:"ext-buttons f-row"}),
lprefs: UC.newGroup(LANG.op_menu, $('prefs-gen'), {inline: true}),
lprefs: UC.newGroup(LANG.op_menu, $('prefs-gen1'), {inline: true}),
expert: UC.newBoolean(LANG.op_xprt_s, booleanSave, {title:LANG.op_xprt_l}),
hoverPop: UC.newBoolean(LANG.op_hopo_s, booleanSave, {title:LANG.op_hopo_l}),
dark: UC.newBoolean(LANG.op_dark_s, booleanSave, {title:LANG.op_dark_l}),
reverseZoom: UC.newBoolean(LANG.op_invr_s, booleanSave, {title:LANG.op_invr_l}),
thinRender: UC.newBoolean(LANG.op_thin_s, booleanSave, {title:LANG.op_thin_l}),
layout: UC.newGroup(LANG.lo_menu, $('prefs-lay'), {inline: true}),
lprefs: UC.newGroup(LANG.op_menu, $('prefs-gen2'), {inline: true}),
thinRender: UC.newBoolean(LANG.op_thin_s, booleanSave, {title:LANG.op_thin_l, modes:FDM}),
showOrigin: UC.newBoolean(LANG.op_shor_s, booleanSave, {title:LANG.op_shor_l}),
showRulers: UC.newBoolean(LANG.op_shru_s, booleanSave, {title:LANG.op_shru_l}),
showSpeeds: UC.newBoolean(LANG.op_sped_s, speedSave, {title:LANG.op_sped_l}),
layout: UC.newGroup(LANG.lo_menu, $('prefs-lay'), {inline: true}),
alignTop: UC.newBoolean(LANG.op_alig_s, booleanSave, {title:LANG.op_alig_l}),
autoLayout: UC.newBoolean(LANG.op_auto_s, booleanSave, {title:LANG.op_auto_l}),
freeLayout: UC.newBoolean(LANG.op_free_s, booleanSave, {title:LANG.op_free_l}),
units: UC.newSelect(LANG.op_unit_s, {title: LANG.op_unit_l, action:unitsSave}, "units"),
units: UC.newSelect(LANG.op_unit_s, {title: LANG.op_unit_l, action:unitsSave, modes:CAM}, "units"),
export: UC.newGroup(LANG.xp_menu, $('prefs-xpo'), {inline: true}),
exportOcto: UC.newBoolean(`OctoPrint`, booleanSave),
@ -1901,6 +1910,7 @@
// restore UI state from settings
UI.showOrigin.checked = control.showOrigin;
UI.showRulers.checked = control.showRulers;
UI.showSpeeds.checked = control.showSpeeds;
UI.freeLayout.checked = control.freeLayout;
UI.autoLayout.checked = control.autoLayout;
UI.alignTop.checked = control.alignTop;

View file

@ -102,6 +102,7 @@
update_size: platformUpdateSize,
update_top_z: platformUpdateTopZ,
update_selected: platformUpdateSelected,
update_speeds: updateSpeeds,
load_files: platformLoadFiles,
group: platformGroup,
group_done: platformGroupDone,
@ -663,6 +664,23 @@
// UI.setMenu.style.display = andmenu ? 'none' : 'flex';
}
function updateSpeeds(speedColors) {
UI.speeds.style.display = viewMode === VIEWS.PREVIEW && UI.showSpeeds.checked ? 'block' : '';
if (speedColors) {
const list = [];
Object.keys(speedColors).map(v => parseInt(v)).sort((a,b) => b-a).forEach(speed => {
const color = speedColors[speed];
const hex = color.toString(16).padStart(6,0);
const r = (color >> 16) & 0xff;
const g = (color >> 8) & 0xff;
const b = (color >> 0) & 0xff;
const style = `background-color:#${hex}`;
list.push(`<label style="${style}">${speed}</label>`);
});
UI.speedbar.innerHTML = list.join('');
}
}
function prepareSlices(callback) {
if (viewMode == VIEWS.ARRANGE) {
let snap = SPACE.screenshot();
@ -802,7 +820,7 @@
KIRI.client.prepare(settings, function(progress, message) {
API.show.progress(progress, message);
}, function (output) {
}, function (output, speedColors) {
API.show.progress(0);
if (!isCam) setOpacity(0);
@ -822,6 +840,7 @@
SPACE.update();
updateSliderMax(true);
setVisibleLayer(-1, 0);
updateSpeeds(speedColors);
}
if (typeof(callback) === 'function') {
@ -1927,12 +1946,14 @@
KIRI.work.clear();
STACKS.clear();
hideSlider();
updateSpeeds();
setVisibleLayer();
setWidgetVisibility(true);
setOpacity(1);
break;
case VIEWS.SLICE:
$('lt-back').style.display = 'flex';
updateSpeeds();
updateSliderMax();
setWidgetVisibility(true);
break;

View file

@ -126,7 +126,21 @@ KIRI.worker = {
send.data({ progress, message });
});
send.done({ done: true, output: KIRI.codec.encode(layers) });
const maxSpeed = (current.print || {}).maxSpeed || undefined;
let speedColors = {};
if (maxSpeed) {
const FDM = KIRI.driver.FDM;
for (let i=0, sd=maxSpeed/19, so=0; i<20; i++) {
speedColors[Math.round(so)] = FDM.colorFunc(so/(maxSpeed+1));
so += sd;
}
}
send.done({
done: true,
output: KIRI.codec.encode(layers),
speedColors
});
},
export: function(data, send) {