From d3583016cd9fa7f5d478471769cfdf71065a8db8 Mon Sep 17 00:00:00 2001 From: Jorge Robles Date: Wed, 20 Jun 2018 22:17:36 +0200 Subject: [PATCH] https://github.com/LaserWeb/LaserWeb4/issues/492 --- src/lib/action2gcode/generators/abstract-generator.js | 9 ++++++++- src/lib/cam-gcode-raster.js | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/action2gcode/generators/abstract-generator.js b/src/lib/action2gcode/generators/abstract-generator.js index ea25066a..013a85e8 100644 --- a/src/lib/action2gcode/generators/abstract-generator.js +++ b/src/lib/action2gcode/generators/abstract-generator.js @@ -6,8 +6,15 @@ class AbstractGenerator { this.settings = settings; } -} + postProcessRaster(gcode){ + if (this.settings.gcodeToolOn && this.settings.gcodeToolOff){ + return gcode.replace(new RegExp("G0(.*?)G1","gis"),'G0$1\n'+this.settings.gcodeToolOn+'\nG1').replace(new RegExp("G1(.*?)G0","gis"),'G1$1\n'+this.settings.gcodeToolOff+'\nG0') + } + return gcode; + } +} + // Exports export { AbstractGenerator } export default AbstractGenerator diff --git a/src/lib/cam-gcode-raster.js b/src/lib/cam-gcode-raster.js index 3b618bbd..8746dc57 100644 --- a/src/lib/cam-gcode-raster.js +++ b/src/lib/cam-gcode-raster.js @@ -4,7 +4,7 @@ import { DOCUMENT_INITIALSTATE } from '../reducers/document' import RasterToGcode from './lw.raster2gcode/raster-to-gcode'; import queue from 'queue' import { promisedImage } from '../components/image-filters.js'; - +import { getGenerator } from "./action2gcode/gcode-generator" const getImageBounds=(t,w,h)=>{ let tx = (x, y) => t[0] * x + t[2] * y; @@ -59,6 +59,8 @@ export function getLaserRasterGcodeFromOp(settings, opIndex, op, docsWithImages, QE.timeout = 3600 * 1000 QE.chunk = 100 / docsWithImages.length + var generator=getGenerator(settings.gcodeGenerator,settings) + // POSTPROCESS GCODE; const postProcessing = (gc) => { @@ -118,7 +120,7 @@ export function getLaserRasterGcodeFromOp(settings, opIndex, op, docsWithImages, //g += `${settings.gcodeToolOn} \r\n`; } - g += raster; //g += (raster.replace(/G1/gi,'\nM5;\nM3;\nG1').replace(/G0/gi,'M5;\nG0')); TOOL ON OFF? + g += generator.postProcessRaster(raster); //g += (raster.replace(/G1/gi,'\nM5;\nM3;\nG1').replace(/G0/gi,'M5;\nG0')); TOOL ON OFF? if (settings.gcodeToolOff && settings.gcodeToolOff.length) g += `${settings.gcodeToolOff} \r\n`;