add preliminary svg import
This commit is contained in:
parent
01aa71574f
commit
c51444d631
3 changed files with 55 additions and 10 deletions
|
|
@ -57,6 +57,36 @@ var gs_kiri_print = exports;
|
||||||
PRO.addPrintPoints = addPrintPoints;
|
PRO.addPrintPoints = addPrintPoints;
|
||||||
PRO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit;
|
PRO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit;
|
||||||
|
|
||||||
|
PRO.parseSVG = function(code, offset) {
|
||||||
|
let scope = this,
|
||||||
|
output = scope.output = [],
|
||||||
|
bounds = scope.bounds = {
|
||||||
|
max: { x:-Infinity, y:-Infinity, z:-Infinity},
|
||||||
|
min: { x:Infinity, y:Infinity, z:Infinity}
|
||||||
|
};
|
||||||
|
let svg = new DOMParser().parseFromString(code, 'text/xml');
|
||||||
|
let lines = [...svg.getElementsByTagName('polyline')];
|
||||||
|
lines.forEach(line => {
|
||||||
|
let seq = [];
|
||||||
|
let points = [...line.points];
|
||||||
|
points.forEach(point => {
|
||||||
|
if (offset) {
|
||||||
|
point.x += offset.x;
|
||||||
|
point.y += offset.y;
|
||||||
|
}
|
||||||
|
if (point.x) bounds.min.x = Math.min(bounds.min.x, point.x);
|
||||||
|
if (point.x) bounds.max.x = Math.max(bounds.max.x, point.x);
|
||||||
|
if (point.y) bounds.min.y = Math.min(bounds.min.y, point.y);
|
||||||
|
if (point.y) bounds.max.y = Math.max(bounds.max.y, point.y);
|
||||||
|
if (point.z) bounds.min.z = Math.min(bounds.min.z, point.z);
|
||||||
|
if (point.z) bounds.max.z = Math.max(bounds.max.z, point.z);
|
||||||
|
addOutput(seq, point, seq.length > 0);
|
||||||
|
});
|
||||||
|
output.push(seq);
|
||||||
|
});
|
||||||
|
scope.lines = lines.length;
|
||||||
|
};
|
||||||
|
|
||||||
PRO.parseGCode = function(gcode, offset) {
|
PRO.parseGCode = function(gcode, offset) {
|
||||||
var lines = gcode
|
var lines = gcode
|
||||||
.toUpperCase()
|
.toUpperCase()
|
||||||
|
|
|
||||||
33
js/kiri.js
33
js/kiri.js
|
|
@ -899,22 +899,36 @@ self.kiri.license = exports.LICENSE;
|
||||||
SPACE.update();
|
SPACE.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadGCode(gcode) {
|
function loadCode(code, type) {
|
||||||
setViewMode(VIEWS.PREVIEW);
|
setViewMode(VIEWS.PREVIEW);
|
||||||
clearPrint();
|
clearPrint();
|
||||||
setOpacity(0);
|
setOpacity(0);
|
||||||
currentPrint = kiri.newPrint(settings, []);
|
currentPrint = kiri.newPrint(settings, []);
|
||||||
currentPrint.parseGCode(gcode, settings.process.outputOriginCenter ? null : {
|
let offset = settings.process.outputOriginCenter ? null : {
|
||||||
x: -settings.device.bedWidth / 2,
|
x: -settings.device.bedWidth / 2,
|
||||||
y: -settings.device.bedDepth / 2,
|
y: -settings.device.bedDepth / 2,
|
||||||
});
|
};
|
||||||
|
switch (type) {
|
||||||
|
case 'svg':
|
||||||
|
currentPrint.parseSVG(code, offset);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
currentPrint.parseGCode(code, offset);
|
||||||
|
break;
|
||||||
|
}
|
||||||
currentPrint.render();
|
currentPrint.render();
|
||||||
SPACE.platform.add(currentPrint.group);
|
SPACE.platform.add(currentPrint.group);
|
||||||
SPACE.update();
|
SPACE.update();
|
||||||
UI.layerPrint.checked = true;
|
UI.layerPrint.checked = true;
|
||||||
updateSliderMax(true);
|
updateSliderMax(true);
|
||||||
showSlices();
|
showSlices();
|
||||||
exportGCode(gcode);
|
switch (type) {
|
||||||
|
case 'svg':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
exportGCode(code);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function preparePrint(callback) {
|
function preparePrint(callback) {
|
||||||
|
|
@ -1879,19 +1893,20 @@ self.kiri.license = exports.LICENSE;
|
||||||
|
|
||||||
function loadFiles(files) {
|
function loadFiles(files) {
|
||||||
for (var i=0; i<files.length; i++) {
|
for (var i=0; i<files.length; i++) {
|
||||||
var lower = files[i].name.toLowerCase(),
|
var reader = new FileReader(),
|
||||||
reader = new FileReader(),
|
lower = files[i].name.toLowerCase(),
|
||||||
isstl = lower.indexOf(".stl") > 0,
|
isstl = lower.indexOf(".stl") > 0,
|
||||||
|
issvg = lower.indexOf(".svg") > 0,
|
||||||
isgcode = lower.indexOf(".gcode") > 0 || lower.indexOf(".nc") > 0;
|
isgcode = lower.indexOf(".gcode") > 0 || lower.indexOf(".nc") > 0;
|
||||||
reader.file = files[i];
|
reader.file = files[i];
|
||||||
reader.onloadend = function (e) {
|
reader.onloadend = function (e) {
|
||||||
if (isstl)
|
if (isstl) platformAdd(
|
||||||
platformAdd(
|
|
||||||
newWidget()
|
newWidget()
|
||||||
.loadVertices(new MOTO.STL().parse(e.target.result))
|
.loadVertices(new MOTO.STL().parse(e.target.result))
|
||||||
.saveToCatalog(e.target.file.name)
|
.saveToCatalog(e.target.file.name)
|
||||||
);
|
);
|
||||||
if (isgcode) loadGCode(e.target.result);
|
if (isgcode) loadCode(e.target.result, 'gcode');
|
||||||
|
if (issvg) loadCode(e.target.result, 'svg');
|
||||||
};
|
};
|
||||||
reader.readAsBinaryString(reader.file);
|
reader.readAsBinaryString(reader.file);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
var exports = {
|
var exports = {
|
||||||
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
|
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
|
||||||
LICENSE:"See the license.md file included with the source distribution",
|
LICENSE:"See the license.md file included with the source distribution",
|
||||||
VERSION:"1.4.5"
|
VERSION:"1.4.6"
|
||||||
};
|
};
|
||||||
if (!module) var module = {};
|
if (!module) var module = {};
|
||||||
module.exports = exports;
|
module.exports = exports;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue