add layer order laser output option

This commit is contained in:
Stewart Allen 2020-10-14 17:18:14 -04:00
commit c1b44e4301
6 changed files with 51 additions and 14 deletions

View file

@ -486,6 +486,7 @@
outputLaserPower: 100,
outputLaserSpeed: 1000,
outputLaserGroup: true,
outputLaserLayer: false,
outputLaserMerged: false,
outputOriginCenter: true,
outputInvertX: false,

View file

@ -1456,6 +1456,7 @@
outputLaserSpeed: UC.newInput(LANG.ou_sped_s, {title:LANG.ou_sped_l, convert:UC.toInt, modes:LASER}),
outputLaserMerged: UC.newBoolean(LANG.ou_mrgd_s, onBooleanClick, {title:LANG.ou_mrgd_l, modes:LASER}),
outputLaserGroup: UC.newBoolean(LANG.ou_grpd_s, onBooleanClick, {title:LANG.ou_grpd_l, modes:LASER}),
outputLaserLayer: UC.newBoolean(LANG.ou_layr_s, onBooleanClick, {title:LANG.ou_layr_l, modes:LASER}),
outputTemp: UC.newInput(LANG.ou_nozl_s, {title:LANG.ou_nozl_l, convert:UC.toInt, modes:FDM}),
outputBedTemp: UC.newInput(LANG.ou_bedd_s, {title:LANG.ou_bedd_l, convert:UC.toInt, modes:FDM}),
outputFeedrate: UC.newInput(LANG.ou_feed_s, {title:LANG.ou_feed_l, convert:UC.toInt, modes:FDM}),

View file

@ -1291,13 +1291,12 @@
let i, m, sz = SPACE.platform.size(),
mp = [sz.x, sz.y],
ms = [mp[0] / 2, mp[1] / 2],
mi = mp[0] > mp[1] ? [(mp[0] / mp[1]) * 10, 10] : [10, (mp[1] / mp[1]) * 10],
c = Widget.Groups.blocks().sort(function (a, b) { return (b.w * b.h) - (a.w * a.h) }),
c = Widget.Groups.blocks().sort(MOTO.Sort),
p = new MOTO.Pack(ms[0], ms[1], gap).fit(c);
while (!p.packed) {
ms[0] += mi[0];
ms[1] += mi[1];
ms[0] *= 1.1;
ms[1] *= 1.1;
p = new MOTO.Pack(ms[0], ms[1], gap).fit(c);
}

View file

@ -181,18 +181,18 @@
// do object layout packing
let i, m, e,
MOTO = self.moto,
mp = [device.bedWidth, device.bedDepth],
ms = [mp[0] / 2, mp[1] / 2],
mi = mp[0] > mp[1] ? [(mp[0] / mp[1]) * 10, 10] : [10, (mp[1] / mp[1]) * 10],
// sort objects by size
c = output.sort(function (a, b) { return (b.w * b.h) - (a.w * a.h) }),
p = new MOTO.Pack(ms[0], ms[1], process.outputTileSpacing).fit(c);
dw = device.bedWidth / 2,
dh = device.bedDepth / 2,
sort = !process.outputLaserLayer,
// sort objects by size when not using laser layer ordering
c = sort ? output.sort(MOTO.Sort) : output,
p = new MOTO.Pack(dw, dh, process.outputTileSpacing).fit(c, !sort);
// test different ratios until packed
while (!p.packed) {
ms[0] += mi[0];
ms[1] += mi[1];
p = new MOTO.Pack(ms[0], ms[1], process.outputTileSpacing).fit(c);
dw *= 1.1;
dh *= 1.1;
p = new MOTO.Pack(dw, dh, process.outputTileSpacing).fit(c ,!sort);
}
for (i = 0; i < c.length; i++) {

View file

@ -13,6 +13,15 @@
if (self.moto.Pack) return;
self.moto.Pack = Packer;
self.moto.Sort = function (a, b) {
let aa = (a.w * a.h);
let ab = (b.w * b.h);
if (Math.abs(aa-ab) < 1) {
return (b.w / b.h) - (a.w / a.h);
} else {
return ab - aa;
}
};
function Packer (w, h, spacing) {
this.root = { x: 0, y: 0, w: w, h: h };
@ -24,7 +33,32 @@
Packer.prototype = {
fit: function (blocks) {
simple: function (blocks) {
let n = 0, block, x = 0, y = 0, mh = 0;
while (n < blocks.length) {
block = blocks[n++];
block.fit = { x, y };
this.max.w = Math.max(this.max.w, x + block.w);
this.max.h = Math.max(this.max.h, y + block.h);
mh = Math.max(mh, block.h);
x += block.w + this.spacing;
if (x > this.root.w) {
x = 0;
y += mh + this.spacing;
mh = 0;
}
if (y > this.root.h) {
return this;
}
}
this.packed = true;
return this;
},
fit: function (blocks, simple) {
if (simple) {
return this.simple(blocks);
}
let n = 0, node, block, w, h;
while (n < blocks.length) {
block = blocks[n++];