Closed mcous closed 10 years ago
Hmm.. I'm getting a "Unable to generate board file: Error: Error at line 119 - end of file encountered before required M02 command" on this file. Seems to have M02 at the end...
Edit by @mcous: Remove paste and add link to file
I just ran this file in the command line and on svgerber and didn't have any issues. Seeing as the file is 6443 lines long and you're seeing the error at line 119, there could be a problem with whatever is grabbing the string to enter into gerber-to-svg.
Off the top of my head, is the file coming from a request that could be getting chunked up? Or maybe from a FileReader that isn't done reading yet?
Hmm.. you might be onto something.. I'm using promises to read the file (after beeing downloaded and unzipped). Might be an issue with this.. will do some more tests.
var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs-extra"));
let content = yield fs.readFileAsync(filename, "utf-8");
I'll.. let you know when resolved.
Certainly seems like it could cause problems. You could try doing it with the normal fs.readFile
callback to check that it works, and then building up to the promise wrapping and fs-extra.
If you're in need of asynchronicity, you could also play around with the release-candidate branch. I haven't finished tying up all the loose ends after a big refactor (still working on step repeats, pretty printing, and getting the API completely sorted), but it does let you use it with fs.createReadStream. Details here: https://github.com/mcous/gerber-to-svg/blob/release-candidate/API.md
Nice,
Is pcb-stackup compatible with the release candidate?
_sort-layers seems to blow here:
for (i = 0, len = layers.length; i < len; i++) {
ly = layers[i];
svg = ly.svg;
children = svg.svg._; <------- HERE
type = ly.type;
props = layerProps(svg);
gType = genericType(type);
2015-12-10T09:19:49.888Z - info: (myproject/controllers/create.js:297) TypeError: Cannot read property '_' of undefined
at sortLayers (/Users/hek/git/openhardware/myproject/node_modules/pcb-stackup/lib/_sort-layers.js:47:25)
When running this snippet on release-candidate
var idLayer = require('pcb-stackup/lib/layer-types').identify;
var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs-extra"));
var fsOrig = Promise.promisifyAll(require("fs"));
var gerberToSvg = Promise.promisify(require('gerber-to-svg'));
let generateBoardsG = function*(id) {
let imagesDir = __dirname + "/../public/uploads/"+id+"/image/";
let boardDir = __dirname + "/../public/uploads/"+id+"/design/";
yield fs.mkdirpAsync(imagesDir);
let warnings = [];
return yield fs.readdirAsync(boardDir).filter(function(filename) {
return idLayer(filename) !== "drw";
}).map(function(filename) {
return fs.readFileAsync(boardDir+filename, {encoding: "utf8"}).then(function(content) {
let layerType = idLayer(filename)
console.log(filename);
return gerberToSvg(content, {id: "oh", object: true, drill: (layerType === 'drl'), warnArr: warnings}).then(function (layer) {
return {type: layerType, svg: layer};
});
}).catch(function(err) {
console.log(filename);
console.log(err.stack);
});
}).then(function(layers) {
let insert = function (orig, find, insert) {
var pos = orig.indexOf(find);
return [orig.slice(0, pos), insert, orig.slice(pos)].join('');
};
let style =
'<style type="text/css">\
.oh_board-fr4 { color: #696969; }\
.oh_board-cu { color: #d3d3d3; }\
.oh_board-cf { color: #daa520; }\
.oh_board-sm { color: #006400; opacity: 0.75; }\
.oh_board-ss { color: #ffffff; }\
.oh_board-sp { color: #c0c0c0; }\
.oh_board-out { color: #000000; }\
</style>';
let stackup = pcbStackup(layers, 'oh');
let top = insert(gerberToSvg(stackup.top), "<defs>", style);
let bottom = insert(gerberToSvg(stackup.bottom), "<defs>", style);
yield fs.writeFileAsync(Path.join(imagesDir, "generatedTop.svg"), top);
yield fs.writeFileAsync(Path.join(imagesDir, "generatedBottom.svg"), bottom);
let path = "/uploads/"+id+"/";
return [{type:"image", path:path+"generatedTop.svg"}, {type:"image", path:path+"generatedBottom.svg"}];
}).catch(function (err) {
console.log(err.stack);
console.log(err);
})
};
Hmm.. looks like gerberToSvg doesn't respect the {object:true} options any longer.
Ah oops, please forgive my 2AM brain for leaving that (admittedly important) part out! Object mode has been dropped, and pcb-stackup will need to be completely re-written. So if you're using pcb-stackup, the RC of gerber-to-svg isn't an option right now. I won't release gerber-to-svg v1.0.0 until I have pcb-stackup ready for the new version, though.
Ok,
Too bad.. The parsing went much better with the release-candidate.. Hmm.. Will the merging of layers be more complicated now in the stacker?
Actually, it will be way simpler! Simple string concatenation instead of a bunch of array parsing and nested objects. I also get to throw out most of board shape module because release-candidate
reorganizes paths for smaller file sizes. I'm hoping to get some time to work on it in the coming weeks (in a sprint at the real job right now).
Oh and there won't be any need to throw it back into gerber-to-svg
at the end.
Ok, sounds promising. I'll test anything you throw at me :)
:+1: sweet I'll be sure to let you know when I've got stuff up
Get the parser to return a file end flag or something