add gbr to loader classes
This commit is contained in:
parent
9adfe33cfb
commit
fdfea41a48
8 changed files with 179 additions and 129 deletions
|
|
@ -5,6 +5,7 @@
|
|||
// dep: kiri-mode.cam.driver
|
||||
// use: kiri-mode.cam.animate
|
||||
// use: kiri-mode.cam.animate2
|
||||
// use: load.gbr
|
||||
gapp.register("kiri-mode.cam.client", [], (root, exports) => {
|
||||
|
||||
const { base, kiri } = root;
|
||||
|
|
@ -116,102 +117,7 @@ CAM.init = function(kiri, api) {
|
|||
}
|
||||
|
||||
api.event.on("cam.parse.gerber", gerber => {
|
||||
let fact = 1000000;
|
||||
let tools = {};
|
||||
let tool;
|
||||
let poly;
|
||||
let polys = [];
|
||||
let circs = [];
|
||||
let rects = [];
|
||||
let last = {};
|
||||
let bounds = base.newBounds();
|
||||
let p = TracespaceParser.createParser();
|
||||
p.feed(gerber);
|
||||
let r = p.results();
|
||||
let c = r.children
|
||||
.filter(c => {
|
||||
switch (c.type) {
|
||||
case 'toolDefinition':
|
||||
tools[c.code] = c.shape;
|
||||
break;
|
||||
case 'toolChange':
|
||||
tool = { code: c.code, shape: tools[c.code] };
|
||||
break;
|
||||
case 'graphic':
|
||||
c.tool = tool;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.map(r => {
|
||||
return {
|
||||
type: r.graphic,
|
||||
tool: r.tool,
|
||||
x: parseInt(r.coordinates.x),
|
||||
y: parseInt(r.coordinates.y)
|
||||
};
|
||||
})
|
||||
.map(r => {
|
||||
const { x, y, tool, type } = r;
|
||||
const pos = { x:x/fact, y:y/fact, z: 0};
|
||||
bounds.update(pos);
|
||||
switch (type) {
|
||||
case 'move':
|
||||
if (true && poly && last.x === x && last.y === y && last.tool === tool) {
|
||||
// console.log('continuation');
|
||||
} else {
|
||||
poly = base.newPolygon().setOpen().add(pos.x, pos.y, 0);
|
||||
poly.tool = tool;
|
||||
polys.push(poly);
|
||||
}
|
||||
break;
|
||||
case 'segment':
|
||||
poly.add(pos.x, pos.y, 0);
|
||||
break;
|
||||
case 'shape':
|
||||
poly = undefined;
|
||||
let { shape } = tool;
|
||||
switch (shape.type) {
|
||||
case 'obround':
|
||||
if (shape.xSize === shape.ySize) {
|
||||
circs.push(base.newPolygon().centerCircle(pos, shape.xSize / 2, 20));
|
||||
} else {
|
||||
console.log('TODO', shape);
|
||||
}
|
||||
break;
|
||||
case 'circle':
|
||||
circs.push(base.newPolygon().centerCircle(pos, shape.diameter / 2, 20));
|
||||
break;
|
||||
case 'rectangle':
|
||||
rects.push(base.newPolygon().centerRectangle(pos, shape.xSize, shape.ySize));
|
||||
break;
|
||||
default:
|
||||
console.log('TODO', shape);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
last = { x, y, tool };
|
||||
return r;
|
||||
});
|
||||
const { minx, maxx, miny, maxy } = bounds;
|
||||
for (let poly of [...polys, ...circs, ...rects]) {
|
||||
poly.move({
|
||||
x: -((maxx-minx)/2 + minx),
|
||||
y: -((maxy-miny)/2 + miny),
|
||||
z: 0
|
||||
});
|
||||
}
|
||||
const open = [];
|
||||
const closed = [];
|
||||
for (let poly of polys) {
|
||||
if (poly.appearsClosed()) {
|
||||
closed.push(...poly.simplify());
|
||||
} else {
|
||||
open.push(poly);
|
||||
}
|
||||
}
|
||||
console.log({ open, closed, circs, rects });
|
||||
const { open, closed, circs, rects } = load.GBR.parse(gerber);
|
||||
const widget = api.widgets.all()[0];
|
||||
const stack = new kiri.Stack(widget.mesh);
|
||||
const layers = new kiri.Layers();
|
||||
|
|
@ -228,7 +134,6 @@ CAM.init = function(kiri, api) {
|
|||
layers.setLayer("rects", {line: 0x0000ff}, false).addPoly(poly);
|
||||
}
|
||||
stack.addLayers(layers);
|
||||
console.log(r, tools);
|
||||
});
|
||||
|
||||
api.event.on("widget.add", widget => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue