normalize driver api

This commit is contained in:
Stewart Allen 2020-06-09 18:12:59 -04:00
commit 2f5cf932e8
9 changed files with 64 additions and 129 deletions

View file

@ -1082,6 +1082,12 @@
text: $('alert-text')
},
act: {
slice: $('act-slice'),
preview: $('act-preview'),
export: $('act-export')
},
load: $('load-file'),
focuser: $('focuser'),
@ -1817,9 +1823,9 @@
$('file-import').onclick = () => { API.event.import() };
$('lt-back').onclick = API.platform.layout;
$('lt-action').onclick = API.platform.layout;
$('act-slice').onclick = (ev) => { ev.stopPropagation(); API.function.slice() };
$('act-preview').onclick = (ev) => { ev.stopPropagation(); API.function.print() };
$('act-export').onclick = (ev) => { ev.stopPropagation(); API.function.export() };
UI.act.slice.onclick = (ev) => { ev.stopPropagation(); API.function.slice() };
UI.act.preview.onclick = (ev) => { ev.stopPropagation(); API.function.print() };
UI.act.export.onclick = (ev) => { ev.stopPropagation(); API.function.export() };
$('view-arrange').onclick = API.platform.layout;
$('view-top').onclick = SPACE.view.top;
$('view-home').onclick = SPACE.view.home;

View file

@ -757,6 +757,9 @@
API.view.snapshot = snap.substring(snap.indexOf(",")+1);
KIRI.work.snap(API.view.snapshot);
}
if (MODE === MODES.SLA && !callback) {
callback = preparePrint;
}
hideSlider(true);
clearPrint();
@ -1915,6 +1918,7 @@
$('app-mode-name').innerHTML = mode;
$('set-tools').style.display = mode === 'CAM' ? '' : 'none';
settings.mode = mode;
MODE = MODES[mode];
// restore cached device profile for this mode
if (settings.cdev[mode]) {
settings.device = clone(settings.cdev[mode]);
@ -1925,7 +1929,11 @@
} else {
SPACE.platform.setColor(0xcccccc);
}
MODE = MODES[mode];
if (MODE === MODES.SLA) {
UI.act.preview.classList.add('hide');
} else {
UI.act.preview.classList.remove('hide');
}
// updates right-hand menu by enabling/disabling fields
setViewMode(VIEWS.ARRANGE);
UC.setMode(MODE);

View file

@ -328,26 +328,12 @@
};
PRO.render = function() {
let scope = this,
settings = scope.settings,
process = settings.process,
let settings = this.settings,
origin = settings.origin,
mode = settings.mode,
driver = KIRI.driver[mode];
switch (mode) {
case 'SLA':
driver.printRender(scope);
break;
case 'CAM':
case 'FDM':
driver.printRender(scope);
// scope.renderMoves(true, 0x888888);
break;
case 'LASER':
scope.renderMoves(false, 0x0088aa);
break;
}
driver.printRender(this);
};
function pref(a,b) {
@ -427,69 +413,6 @@
return out;
}
PRO.renderMoves = function(showMoves, moveColor, firstPoint) {
let debug = KIRI.api.const.LOCAL;
let scope = this, emits, moves, last = firstPoint;
// render layered output
scope.lines = 0;
scope.output.forEach(function(layerout) {
let move = [], print = {}, z;
layerout.forEach(function(out, index) {
let point = out.point;
if (last) {
if (UTIL.distSq(last, point) < 0.001 && point.z === last.z) {
return;
}
if (out.emit > 0) {
let spd = out.speed || 4000;
let arr = print[spd] || [];
print[spd] = arr;
arr.push(last);
arr.push(point);
} else {
move.push(last);
move.push(point);
}
if (debug && showMoves && last.z == point.z) {
let rs = BASE.newSlope(
{x: point.x, y: point.y},
{x: last.x, y: last.y}
);
let ao1 = BASE.newSlopeFromAngle(rs.angle + 25);
let ao2 = BASE.newSlopeFromAngle(rs.angle - 25);
let sp = BASE.newPoint(point.x, point.y, point.z);
move.push(sp);
move.push(sp.projectOnSlope(ao1, 0.5));
move.push(sp);
move.push(sp.projectOnSlope(ao2, 0.5));
}
} else {
z = point.z;
}
last = point;
});
emits = KIRI.newLayer(scope.group);
scope.printView.push(emits);
if (showMoves) {
moves = KIRI.newLayer(scope.group);
moves.lines(move, moveColor);
scope.movesView.push(moves);
moves.render();
}
for (let speed in print) {
let sint = Math.min(6000, parseInt(speed));
let rgb = hsv2rgb({h:sint/6000, s:1, v:0.6});
emits.lines(print[speed],
((rgb.r * 0xff) << 16) |
((rgb.g * 0xff) << 8) |
((rgb.b * 0xff) << 0)
);
}
emits.render();
scope.lines += print.length;
});
}
PRO.getLayerCount = function() {
return this.output.length;
}

View file

@ -711,34 +711,9 @@
/**
* render all slice and processed data
* @param {number} renderMode
* @param {boolean} cam mode
*/
PRO.render = function(renderMode, cam) {
let slices = this.slices;
if (!slices) return;
let settings = this.settings,
driver = DRIVERS[settings.mode.toUpperCase()];
// allow driver to override widget slice rendering (new in SLA)
if (driver.sliceRender) return driver.sliceRender(this, renderMode);
let extruder = this.getExtruder(settings);
// render outline
slices.forEach(function(s) { s.renderOutline(renderMode,extruder) });
// render shells
slices.forEach(function(s) { s.renderShells(renderMode) });
// render diff
if (!cam) slices.forEach(function(s) { s.renderDiff() });
// render solid fill (include solid flats/bridges)
slices.forEach(function(s) { s.renderSolidFill() });
// render solid fill outlines
if (!cam) slices.forEach(function(s) { s.renderSolidOutlines() });
// render sparse fill
if (!cam) slices.forEach(function(s) { s.renderSparseFill() });
// render supports
if (!cam) slices.forEach(function(s) { s.renderSupport() });
PRO.render = function() {
DRIVERS[this.settings.mode.toUpperCase()].sliceRender(this);
};
PRO.hideSlices = function() {