update (fix?) laser DXF output format. fix layer grouping option
This commit is contained in:
parent
6495905a7d
commit
5797f4fb2a
3 changed files with 75 additions and 61 deletions
|
|
@ -11,7 +11,6 @@ gapp.register("kiri-mode.laser.driver", [], (root, exports) => {
|
|||
|
||||
const { base, kiri } = root;
|
||||
const { driver, newSlice } = kiri;
|
||||
const { FDM, CAM } = driver;
|
||||
const { polygons, newPoint } = base;
|
||||
|
||||
const POLY = polygons;
|
||||
|
|
@ -26,7 +25,7 @@ const LASER = driver.LASER = {
|
|||
};
|
||||
|
||||
function init(kiri, api) {
|
||||
api.event.on("settings.saved", (settings) => {
|
||||
api.event.on("settings.saved", settings => {
|
||||
let ui = kiri.api.ui;
|
||||
});
|
||||
}
|
||||
|
|
@ -89,7 +88,7 @@ function slice(settings, widget, onupdate, ondone) {
|
|||
onupdate(v);
|
||||
}
|
||||
}).then(output => {
|
||||
let slices = widget.slices = output.slices.map(data => {
|
||||
widget.slices = output.slices.map(data => {
|
||||
let { z, lines, groups } = data;
|
||||
let tops = POLY.nest(groups);
|
||||
let slice = newSlice(z).addTops(tops);
|
||||
|
|
@ -111,24 +110,21 @@ function polyLabel(poly, label) {
|
|||
function sliceEmitObjects(print, slice, groups, opt = { }) {
|
||||
let start = newPoint(0,0,0);
|
||||
let process = print.settings.process;
|
||||
let grouped = process.outputLaserGroup;
|
||||
let stacked = process.outputLaserStack;
|
||||
let grouped = stacked || process.outputLaserGroup;
|
||||
let label = false && process.outputLaserLabel;
|
||||
let simple = opt.simple || false;
|
||||
let group = [];
|
||||
let emit = { in: [], out: [], mark: [] };
|
||||
let lastEmit = opt.lastEmit;
|
||||
let zcolor = print.settings.process.outputLaserZColor;
|
||||
|
||||
group.thick = slice.thick;
|
||||
|
||||
function laserOut(poly, group, type, index) {
|
||||
function laserOut(poly, group, type, indexed) {
|
||||
if (!poly) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(poly)) {
|
||||
poly.forEach((pi, index) => {
|
||||
laserOut(pi, group, type, offset.length > 1 ? index : undefined);
|
||||
laserOut(pi, group, type, indexed ? index : undefined);
|
||||
});
|
||||
} else {
|
||||
let pathOpt = zcolor ? {extrude: slice.z, rate: slice.z} : {extrude: 1, rate: 1};
|
||||
|
|
@ -153,22 +149,24 @@ function sliceEmitObjects(print, slice, groups, opt = { }) {
|
|||
}
|
||||
}
|
||||
|
||||
if (grouped) {
|
||||
let group = [];
|
||||
group.thick = slice.thick;
|
||||
let offset = slice.offset;
|
||||
let inner = offset.map(poly => poly.inner || []).flat();
|
||||
|
||||
// cut inside before outside
|
||||
laserOut(inner, group, "in");
|
||||
laserOut(offset, group, "out");
|
||||
|
||||
if (!grouped) {
|
||||
laserOut(inner, group, "in", offset.length > 1);
|
||||
laserOut(offset, group, "out", offset.length > 1);
|
||||
groups.push(group);
|
||||
group = [];
|
||||
} else {
|
||||
for (let top of slice.offset) {
|
||||
let group = [];
|
||||
group.thick = slice.thick;
|
||||
}
|
||||
|
||||
if (grouped) {
|
||||
laserOut([ top ], group, "in");
|
||||
laserOut(top.inner || [], group, "out");
|
||||
groups.push(group);
|
||||
}
|
||||
}
|
||||
|
||||
return emit;
|
||||
};
|
||||
|
|
@ -184,8 +182,8 @@ async function prepare(widgets, settings, update) {
|
|||
process = settings.process,
|
||||
print = self.worker.print = kiri.newPrint(settings, widgets),
|
||||
knifeOn = process.knifeOn,
|
||||
knifeDepth = process.outputKnifeDepth,
|
||||
knifePasses = process.outputKnifePasses,
|
||||
// knifeDepth = process.outputKnifeDepth,
|
||||
// knifePasses = process.outputKnifePasses,
|
||||
knifeTipOff = process.outputKnifeTip,
|
||||
output = print.output = [],
|
||||
totalSlices = 0,
|
||||
|
|
@ -259,16 +257,16 @@ async function prepare(widgets, settings, update) {
|
|||
}
|
||||
|
||||
// find max layers (for updates)
|
||||
widgets.forEach(function(widget) {
|
||||
widgets.forEach(widget => {
|
||||
totalSlices += widget.slices.length;
|
||||
});
|
||||
|
||||
// emit objects from each slice into output array
|
||||
widgets.forEach(function(widget) {
|
||||
widgets.forEach(widget => {
|
||||
// slice stack merging
|
||||
if (process.outputLaserMerged) {
|
||||
let merged = [];
|
||||
widget.slices.forEach(function(slice) {
|
||||
widget.slices.forEach(slice => {
|
||||
let polys = [];
|
||||
slice.offset.clone(true).forEach(p => p.flattenTo(polys));
|
||||
polys.forEach(p => {
|
||||
|
|
@ -322,9 +320,9 @@ async function prepare(widgets, settings, update) {
|
|||
let pack = true;
|
||||
|
||||
// compute tile width / height
|
||||
output.forEach(function(layerout) {
|
||||
output.forEach(layerout => {
|
||||
let min = {w:Infinity, h:Infinity}, max = {w:-Infinity, h:-Infinity}, p;
|
||||
layerout.forEach(function(out) {
|
||||
layerout.forEach(out => {
|
||||
p = out.point;
|
||||
out.point = p.clone(); // b/c first/last point are often shared
|
||||
min.w = Math.min(min.w, p.x);
|
||||
|
|
@ -336,7 +334,7 @@ async function prepare(widgets, settings, update) {
|
|||
layerout.h = max.h - min.h;
|
||||
// shift objects to top/left of w/h bounds
|
||||
if (pack)
|
||||
layerout.forEach(function(out) {
|
||||
layerout.forEach(out => {
|
||||
p = out.point;
|
||||
p.x -= min.w;
|
||||
p.y -= min.h;
|
||||
|
|
@ -622,38 +620,48 @@ function exportDXF(settings, data) {
|
|||
data,
|
||||
function(min, max) {
|
||||
lines.appendAll([
|
||||
' 0',
|
||||
'SECTION',
|
||||
' 2',
|
||||
'HEADER',
|
||||
' 9',
|
||||
'$ACADVER',
|
||||
'1',
|
||||
'AC1014',
|
||||
' 0',
|
||||
'ENDSEC',
|
||||
' 0',
|
||||
'SECTION',
|
||||
' 2',
|
||||
'ENTITIES',
|
||||
" 0",
|
||||
"SECTION",
|
||||
" 2",
|
||||
"HEADER",
|
||||
" 0",
|
||||
"ENDSEC",
|
||||
" 0",
|
||||
"SECTION",
|
||||
" 2",
|
||||
"TABLES",
|
||||
" 0",
|
||||
"ENDSEC",
|
||||
" 0",
|
||||
"SECTION",
|
||||
" 2",
|
||||
"BLOCKS",
|
||||
" 0",
|
||||
"ENDSEC",
|
||||
" 0",
|
||||
"SECTION",
|
||||
" 2",
|
||||
"ENTITIES",
|
||||
]);
|
||||
},
|
||||
function(poly) {
|
||||
lines.appendAll([
|
||||
' 0',
|
||||
'LWPOLYLINE',
|
||||
'100', // subgroup required
|
||||
'AcDbPolyline',
|
||||
' 90', // poly vertices
|
||||
poly.length,
|
||||
' 70', // open
|
||||
'0',
|
||||
' 43', // constant width line
|
||||
'0.0'
|
||||
" 0",
|
||||
"POLYLINE",
|
||||
" 8",
|
||||
"0",
|
||||
" 66",
|
||||
"1",
|
||||
" 70",
|
||||
"1",
|
||||
]);
|
||||
|
||||
poly.forEach(function(point) {
|
||||
poly.forEach(point => {
|
||||
lines.appendAll([
|
||||
' 0',
|
||||
'VERTEX',
|
||||
' 8',
|
||||
'0',
|
||||
' 10',
|
||||
point.x,
|
||||
' 20',
|
||||
|
|
@ -668,6 +676,12 @@ function exportDXF(settings, data) {
|
|||
},
|
||||
function() {
|
||||
lines.appendAll([
|
||||
' 0',
|
||||
'ENDSEC',
|
||||
' 0',
|
||||
'SECTION',
|
||||
' 2',
|
||||
'OBJECTS',
|
||||
' 0',
|
||||
'ENDSEC',
|
||||
' 0',
|
||||
|
|
|
|||
|
|
@ -1691,10 +1691,10 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
extNozzle: newInput(LANG.dv_nozl_s, {title:LANG.dv_nozl_l, convert:toFloat, modes:FDM}),
|
||||
extOffsetX: newInput(LANG.dv_exox_s, {title:LANG.dv_exox_l, convert:toFloat, modes:FDM}),
|
||||
extOffsetY: newInput(LANG.dv_exoy_s, {title:LANG.dv_exoy_l, convert:toFloat, modes:FDM}),
|
||||
_____: newDiv({ class: "f-col t-body t-inset", addto: $('dev-config'), set:true, modes:GCODE }),
|
||||
_____: newDiv({ class: "f-col t-body t-inset", addto: $('dev-config'), set:true, modes:FDM_CAM }),
|
||||
_____: newGroup(LANG.dv_gr_too, null, {group:"dext", inline:true}),
|
||||
extSelect: newText(LANG.dv_exts_s, {title:LANG.dv_exts_l, size:14, height:3, area:gcode, modes:GCODE}),
|
||||
extDeselect: newText(LANG.dv_dext_s, {title:LANG.dv_dext_l, size:14, height:3, area:gcode, modes:GCODE}),
|
||||
extSelect: newText(LANG.dv_exts_s, {title:LANG.dv_exts_l, size:14, height:3, area:gcode}),
|
||||
extDeselect: newText(LANG.dv_dext_s, {title:LANG.dv_dext_l, size:14, height:3, area:gcode}),
|
||||
extPad: newBlank({class:"grow", modes:FDM}),
|
||||
extActions: newRow([
|
||||
ui.extPrev = newButton(undefined, undefined, {icon:'<i class="fas fa-less-than"></i>'}),
|
||||
|
|
@ -1955,7 +1955,7 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
laserLayout: newGroup(LANG.lo_menu, $('lzr-layout'), { modes:LASER, driven, separator }),
|
||||
outputTileSpacing: newInput(LANG.ou_spac_s, {title:LANG.ou_spac_l, convert:toInt}),
|
||||
outputLaserMerged: newBoolean(LANG.ou_mrgd_s, onBooleanClick, {title:LANG.ou_mrgd_l}),
|
||||
outputLaserGroup: newBoolean(LANG.ou_grpd_s, onBooleanClick, {title:LANG.ou_grpd_l}),
|
||||
outputLaserGroup: newBoolean(LANG.ou_grpd_s, onBooleanClick, {title:LANG.ou_grpd_l, show:() => !ui.outputLaserStack.checked}),
|
||||
laserOutput: newGroup(LANG.ou_menu, $('lzr-output'), { modes:LASER, driven, separator }),
|
||||
outputLaserPower: newInput(LANG.ou_powr_s, {title:LANG.ou_powr_l, convert:toInt, bound:bound(1,100)}),
|
||||
outputLaserSpeed: newInput(LANG.ou_sped_s, {title:LANG.ou_sped_l, convert:toInt}),
|
||||
|
|
|
|||
|
|
@ -665,8 +665,8 @@ self.kiri.lang['en-us'] = {
|
|||
ou_layr_l: ["output layer order","from top right to","bottom left"],
|
||||
ou_layo_s: "layer color",
|
||||
ou_layo_l: ["output layer colors","for each z index","overridden by merged"],
|
||||
ou_lays_s: "layer stacking",
|
||||
ou_lays_l: ["mark layers for stacking","with a unique color"],
|
||||
ou_lays_s: "layer marking",
|
||||
ou_lays_l: ["mark layers for stacking. the layer above will be output in a different color which the laser can mark with a lower power. turns on layer grouping."],
|
||||
ou_drkn_s: "drag knife",
|
||||
ou_drkn_l: ["enable drag knife","output in gcode","cut radii are added","to corners with","cut down passes"],
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue