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

View file

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

View file

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

View file

@ -14,7 +14,9 @@
DBUG = BASE.debug,
LASER = KIRI.driver.LASER = {
slice,
sliceRender,
printSetup,
printRender,
exportGCode,
exportSVG,
exportDXF
@ -51,9 +53,10 @@
});
};
/**
*
*/
function sliceRender(widget) {
return KIRI.driver.CAM.sliceRender(widget);
}
function sliceEmitObjects(print, slice, groups) {
let start = newPoint(0,0,0);
let process = print.settings.process;
@ -455,4 +458,8 @@
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
function sliceRender(widget) {
// legacy debug
return;
widget.slices.forEach(slice => {
let layers = slice.layers,
outline = layers.outline,
@ -743,7 +746,7 @@
if (count === 0) {
// TODO fix with contract for exposing layer count
// hack uses expected gcode output array in print object
// print.output = print.printView;
print.output = print.printView;
return;
}

View file

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