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) {

View file

@ -397,6 +397,10 @@
}
}
FDM.colorFunc = function(rate) {
return hsv2rgb({h: rate, s:1, v:0.75}, true);
};
FDM.prepareRender = function(levels, update, options) {
const opts = options || {};
const tools = opts.tools || {};
@ -410,6 +414,9 @@
return level.map(o => o.speed || 0).reduce((a, v) => Math.max(a,v));
}).reduce((a, v) => Math.max(a, v)) + 1;
// for reporting
self.worker.print.maxSpeed = maxspd - 1;
let lastOut = null;
let current = null;

View file

@ -895,6 +895,41 @@ th, tr, td, label {
text-align: center;
}
#speeds {
display: none;
position: absolute;
height: 100%;
top: 0;
right: 100%;
bottom: 0;
border: 0;
margin: 0;
padding: 0;
}
#speedbar {
position: absolute;
top: 3px;
right: 0;
bottom: 3px;
border-radius: 5px;
border: 3px solid rgba(200,200,200,0.5);
background-color: #888;
}
#speedbar label {
flex-grow: 1;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: monospace;
font-size: 12px;
padding: 0 5px 0 5px;
color: #fff;
}
#settings {
align-items: stretch;
}

View file

@ -325,7 +325,9 @@
</div>
</div>
<div id="mod-prefs" class="mdialog f-row">
<div id="prefs-gen" class="f-col"></div>
<div id="prefs-gen1" class="f-col"></div>
<div class="t-pad2"></div>
<div id="prefs-gen2" class="f-col"></div>
<div class="t-pad2"></div>
<div id="prefs-lay" class="f-col"></div>
<div class="t-pad2"></div>
@ -360,6 +362,7 @@
</div>
<div id="mid-rcol" class="f-col j-center noshow">
<div id="set-menu" class="f-col">
<div id="speeds"><div id="speedbar" class="f-col a-stretch j-center"></div></div>
<div id="set-top" class="set-group"><a>settings</a></div>
<div id="settings" class="f-col"></div>
<div id="set-end" class="set-group"></div>

View file

@ -125,6 +125,8 @@ kiri.lang['en-us'] = {
op_shor_l: "show device or process origin",
op_shru_s: "show rulers",
op_shru_l: "show axes rulers\non major gridlines",
op_sped_s: "show speeds",
op_sped_l: "show speed to color bar\nin preview mode",
op_alig_s: "align top",
op_alig_l: "align parts to the\ntallest part when\nno stock is set",
op_auto_s: "auto layout",