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

View file

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

View file

@ -328,26 +328,12 @@
}; };
PRO.render = function() { PRO.render = function() {
let scope = this, let settings = this.settings,
settings = scope.settings,
process = settings.process,
origin = settings.origin, origin = settings.origin,
mode = settings.mode, mode = settings.mode,
driver = KIRI.driver[mode]; driver = KIRI.driver[mode];
switch (mode) { driver.printRender(this);
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;
}
}; };
function pref(a,b) { function pref(a,b) {
@ -427,69 +413,6 @@
return out; 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() { PRO.getLayerCount = function() {
return this.output.length; return this.output.length;
} }

View file

@ -711,34 +711,9 @@
/** /**
* render all slice and processed data * render all slice and processed data
* @param {number} renderMode
* @param {boolean} cam mode
*/ */
PRO.render = function(renderMode, cam) { PRO.render = function() {
let slices = this.slices; DRIVERS[this.settings.mode.toUpperCase()].sliceRender(this);
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.hideSlices = function() { PRO.hideSlices = function() {

View file

@ -16,8 +16,7 @@
sliceRender, sliceRender,
printSetup, printSetup,
printExport, printExport,
// printDownload, printRender,
// printRender
getToolById, getToolById,
getToolDiameter, getToolDiameter,
}, },
@ -1924,4 +1923,8 @@
return online ? null : output.join("\n"); return online ? null : output.join("\n");
}; };
function printRender(print) {
return KIRI.driver.FDM.printRender(print, {aslines: true});
}
})(); })();

View file

@ -18,7 +18,6 @@
sliceRender, sliceRender,
printSetup, printSetup,
printExport, printExport,
// printDownload,
printRender printRender
}, },
SLICER = KIRI.slicer, SLICER = KIRI.slicer,
@ -1230,10 +1229,12 @@
return base.newPoint(obj.x, obj.y, obj.z); return base.newPoint(obj.x, obj.y, obj.z);
} }
function printRender(print) { function printRender(print, options) {
let debug = KIRI.api.const.LOCAL; let debug = KIRI.api.const.LOCAL;
let scope = print, emits, moves, last; let scope = print, emits, last,
let moving = true; moves, moving = true,
opt = options || {},
showmoves = !opt.nomoves;
// render layered output // render layered output
scope.lines = 0; scope.lines = 0;
scope.output.forEach(function(layerout) { scope.output.forEach(function(layerout) {
@ -1276,8 +1277,10 @@
last = point; last = point;
}); });
emits = KIRI.newLayer(scope.group); emits = KIRI.newLayer(scope.group);
if (showmoves) {
moves = KIRI.newLayer(scope.group); moves = KIRI.newLayer(scope.group);
moves.lines(move, 0x888888); moves.lines(move, 0x888888);
}
emits.setTransparent(false); emits.setTransparent(false);
// emit printing shapes // emit printing shapes
print.forEach(segment => { print.forEach(segment => {
@ -1287,15 +1290,19 @@
let color = ((rgb.r * 0xff) << 16) | let color = ((rgb.r * 0xff) << 16) |
((rgb.g * 0xff) << 8) | ((rgb.g * 0xff) << 8) |
((rgb.b * 0xff) << 0); ((rgb.b * 0xff) << 0);
// emits.poly(poly, color, false, true); if (opt.aslines) {
emits.poly(poly, color, false, true);
} else {
emits.noodle_open(poly, 0.2, color, 0x0, poly.getZ()); emits.noodle_open(poly, 0.2, color, 0x0, poly.getZ());
}
}); });
moves.render();
emits.renderAll(); emits.renderAll();
scope.lines += print.length; if (showmoves) {
// for slider hide/show moves.render();
scope.printView.push(emits);
scope.movesView.push(moves); scope.movesView.push(moves);
}
scope.printView.push(emits);
scope.lines += print.length;
}); });
} }

View file

@ -14,7 +14,9 @@
DBUG = BASE.debug, DBUG = BASE.debug,
LASER = KIRI.driver.LASER = { LASER = KIRI.driver.LASER = {
slice, slice,
sliceRender,
printSetup, printSetup,
printRender,
exportGCode, exportGCode,
exportSVG, exportSVG,
exportDXF exportDXF
@ -51,9 +53,10 @@
}); });
}; };
/** function sliceRender(widget) {
* return KIRI.driver.CAM.sliceRender(widget);
*/ }
function sliceEmitObjects(print, slice, groups) { function sliceEmitObjects(print, slice, groups) {
let start = newPoint(0,0,0); let start = newPoint(0,0,0);
let process = print.settings.process; let process = print.settings.process;
@ -455,4 +458,8 @@
return lines.join('\n'); return lines.join('\n');
}; };
function printRender(print) {
return KIRI.driver.FDM.printRender(print, {aslines: true, nomoves: true});
}
})(); })();

View file

@ -672,6 +672,9 @@
// runs in browser main // runs in browser main
function sliceRender(widget) { function sliceRender(widget) {
// legacy debug
return;
widget.slices.forEach(slice => { widget.slices.forEach(slice => {
let layers = slice.layers, let layers = slice.layers,
outline = layers.outline, outline = layers.outline,
@ -743,7 +746,7 @@
if (count === 0) { if (count === 0) {
// TODO fix with contract for exposing layer count // TODO fix with contract for exposing layer count
// hack uses expected gcode output array in print object // hack uses expected gcode output array in print object
// print.output = print.printView; print.output = print.printView;
return; return;
} }

View file

@ -101,6 +101,9 @@ th, tr, td {
user-select: none; user-select: none;
} }
.hide {
display: none !important;
}
.noshow { .noshow {
display: none; display: none;
} }