checkpoint internal work. # app server file wrapping, gerber import work
This commit is contained in:
parent
2519bec95d
commit
d1938316e5
8 changed files with 163 additions and 7 deletions
38
app.js
38
app.js
|
|
@ -23,6 +23,7 @@ const mods = {};
|
|||
const load = [];
|
||||
const synth = {};
|
||||
const api = {};
|
||||
const wrap = {};
|
||||
|
||||
let forceUseCache = false;
|
||||
let serviceWorker = true;
|
||||
|
|
@ -57,6 +58,14 @@ netdb.create = async function(map = {}) {
|
|||
return client;
|
||||
};
|
||||
|
||||
function wrapdata(path, buf) {
|
||||
return [
|
||||
`gapp.register("${path}", [], (root, exports) => {`,
|
||||
buf.toString(),
|
||||
"});"
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function addonce(array, v) {
|
||||
if (array.indexOf(v) < 0) {
|
||||
array.push(v);
|
||||
|
|
@ -209,6 +218,9 @@ function init(mod) {
|
|||
if (fc === '@') {
|
||||
continue;
|
||||
}
|
||||
if (fc === '#') {
|
||||
continue;
|
||||
}
|
||||
if (fc === '&') {
|
||||
path = path.substring(1);
|
||||
addonce(roots, path);
|
||||
|
|
@ -230,7 +242,16 @@ function init(mod) {
|
|||
}
|
||||
// val.splice(1, 0, ...roots);
|
||||
if (xxxx) console.log({key, cache, refs, paths, roots, val});
|
||||
script[key] = val.map(p => p.charAt(0) !== '@' ? `src/${p}.js` : p);
|
||||
script[key] = val.map(p => {
|
||||
let fc = p.charAt(0);
|
||||
if (fc === '@') return p;
|
||||
if (fc === '#') {
|
||||
let nupath = `src/${p.substring(1)}.js`;
|
||||
wrap[nupath] = true;
|
||||
return nupath;
|
||||
}
|
||||
return `src/${p}.js`;
|
||||
});
|
||||
// console.log({script: key, files: script[key]});
|
||||
}
|
||||
|
||||
|
|
@ -271,6 +292,17 @@ function init(mod) {
|
|||
});
|
||||
}
|
||||
mod.add(rewriteHtmlVersion);
|
||||
mod.add((req, res, next) => {
|
||||
const path = req.gs.path.substring(1);
|
||||
if (wrap[path]) {
|
||||
const data = getCachedFile(path, data => {
|
||||
console.log({ do_not_min: data });
|
||||
return data;
|
||||
});
|
||||
return res.end(data);
|
||||
}
|
||||
next();
|
||||
});
|
||||
mod.static("/src/", "src");
|
||||
mod.static("/obj/", "web/obj");
|
||||
mod.static("/font/", "web/font");
|
||||
|
|
@ -724,6 +756,10 @@ function getCachedFile(file, fn) {
|
|||
fs.writeFileSync(cachePath, cacheData);
|
||||
}
|
||||
|
||||
if (wrap[file]) {
|
||||
cacheData = wrapdata(file, cacheData);
|
||||
}
|
||||
|
||||
cached = {
|
||||
data: cacheData,
|
||||
mtime: cmod || now,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
"@fortawesome/fontawesome-free": "^6.1.1",
|
||||
"@gridspace/app-server": "^0.0.13",
|
||||
"@gridspace/net-level-client": "^0.2.3",
|
||||
"@tracespace/parser": "^5.0.0-next.0",
|
||||
"@tweenjs/tween.js": "^16.6.0",
|
||||
"base64-js": "^1.5.1",
|
||||
"buffer-crc32": "^0.2.13",
|
||||
|
|
|
|||
|
|
@ -115,6 +115,99 @@ CAM.init = function(kiri, api) {
|
|||
updateStock();
|
||||
}
|
||||
|
||||
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 '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;
|
||||
}
|
||||
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
|
||||
});
|
||||
}
|
||||
console.log(polys, circs, rects);
|
||||
const widget = api.widgets.all()[0];
|
||||
const stack = new kiri.Stack(widget.mesh);
|
||||
const layers = new kiri.Layers();
|
||||
for (let poly of polys) {
|
||||
layers.setLayer("paths", {line: 0xff0000}, false).addPoly(poly);
|
||||
}
|
||||
for (let poly of circs) {
|
||||
layers.setLayer("circs", {line: 0x008800}, false).addPoly(poly);
|
||||
}
|
||||
for (let poly of rects) {
|
||||
layers.setLayer("rects", {line: 0x0000ff}, false).addPoly(poly);
|
||||
}
|
||||
stack.addLayers(layers);
|
||||
});
|
||||
|
||||
api.event.on("widget.add", widget => {
|
||||
if (isCamMode && !Array.isArray(widget)) {
|
||||
updateAxisMode(true);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// dep: kiri.selection
|
||||
// use: kiri.tools
|
||||
// use: kiri.pack
|
||||
// use: ext.gerber
|
||||
gapp.register("kiri.init", [], (root, exports) => {
|
||||
|
||||
const { base, kiri } = root;
|
||||
|
|
@ -369,6 +370,7 @@ gapp.register("kiri.init", [], (root, exports) => {
|
|||
if (evt.metaKey) {
|
||||
evt.preventDefault();
|
||||
api.space.save();
|
||||
api.settings.sync.put();
|
||||
}
|
||||
break;
|
||||
case 76: // 'l' for restore workspace
|
||||
|
|
|
|||
|
|
@ -139,8 +139,16 @@ gapp.register("kiri.main", [], (root, exports) => {
|
|||
is_fdm() { return MODE === MODES.FDM },
|
||||
is_cam() { return MODE === MODES.CAM },
|
||||
is_sla() { return MODE === MODES.SLA },
|
||||
is_laser() { return MODE === MODES.LASER },
|
||||
is_drag() { return MODE === MODES.DRAG },
|
||||
is_wedm() { return MODE === MODES.WEDM },
|
||||
is_wjet() { return MODE === MODES.WJET },
|
||||
is_laser() { return MODE === MODES.LASER },
|
||||
is_2d() { return
|
||||
api.mode.is_drag() ||
|
||||
api.mode.is_wedm() ||
|
||||
api.mode.is_wjet() ||
|
||||
api.mode.is_laser()
|
||||
}
|
||||
},
|
||||
probe: {
|
||||
live: "https://live.grid.space",
|
||||
|
|
@ -549,7 +557,6 @@ gapp.register("kiri.main", [], (root, exports) => {
|
|||
|
||||
function saveWorkspace(quiet) {
|
||||
api.conf.save();
|
||||
api.settings.sync.put();
|
||||
const newWidgets = [];
|
||||
const oldWidgets = js2o(SDB.getItem('ws-widgets'), []);
|
||||
api.widgets.each(function(widget) {
|
||||
|
|
|
|||
|
|
@ -763,7 +763,8 @@ function platformLoadFiles(files, group) {
|
|||
isgcode = lower.indexOf(".gcode") > 0 || lower.indexOf(".nc") > 0,
|
||||
isset = lower.indexOf(".b64") > 0 || lower.indexOf(".km") > 0,
|
||||
iskmz = lower.indexOf(".kmz") > 0,
|
||||
isini = lower.indexOf(".ini") > 0;
|
||||
isini = lower.indexOf(".ini") > 0,
|
||||
isgrb = lower.indexOf(".grb");
|
||||
reader.file = files[i];
|
||||
reader.onloadend = function(e) {
|
||||
function load_dec() {
|
||||
|
|
@ -817,6 +818,12 @@ function platformLoadFiles(files, group) {
|
|||
} else {
|
||||
odon();
|
||||
}
|
||||
} else if (isgrb && api.conf.get().controller.devel) {
|
||||
if (api.mode.is_cam()) {
|
||||
api.event.emit('cam.parse.gerber', e.target.result);
|
||||
} else {
|
||||
api.alerts.show('Gerber import not availabe in this device mode');
|
||||
}
|
||||
} else if (is3mf) {
|
||||
let odon = function(models) {
|
||||
let msg = api.show.alert('Adding Objects');
|
||||
|
|
@ -870,7 +877,7 @@ function platformLoadFiles(files, group) {
|
|||
else if (ispng) api.image.dialog(e.target.result, e.target.file.name);
|
||||
else if (isjpg) api.image.convert(e.target.result, e.target.file.name);
|
||||
else if (isini) api.settings.import_prusa(e.target.result);
|
||||
else api.show.alert(`Unsupported file: ${files[i].name}`);
|
||||
else api.show.alert(`Unsupported file: ${reader.file.name}`);
|
||||
};
|
||||
if (isstl || ispng || isjpg || iskmz) {
|
||||
reader.readAsArrayBuffer(reader.file);
|
||||
|
|
|
|||
|
|
@ -79,6 +79,16 @@ gapp.register = function() {
|
|||
mods.push(mod);
|
||||
};
|
||||
|
||||
function safeFN(fn, name) {
|
||||
return function() {
|
||||
try {
|
||||
return fn(...arguments);
|
||||
} catch (error) {
|
||||
console.log({ register_fail: name, error });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// perform dependency checks and run module load functions
|
||||
gapp.main = function() {
|
||||
const args = exargs([...arguments]);
|
||||
|
|
@ -115,7 +125,7 @@ gapp.main = function() {
|
|||
}
|
||||
}
|
||||
let tmp = path[map] || {};
|
||||
fn(root, exports => {
|
||||
safeFN(fn, name)(root, exports => {
|
||||
if (exports) {
|
||||
return path[map] = Object.assign(tmp, exports);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -642,7 +642,7 @@ self.kiri.lang['en-us'] = {
|
|||
|
||||
// LASER SLICING
|
||||
ls_offs_s: "offset / kerf",
|
||||
ls_offs_l: ["adjust for beam width","also known as kerf","in millimeters"],
|
||||
ls_offs_l: ["distance between the center of the cutting","path and the edge of remaining material","in millimeters"],
|
||||
ls_lahi_s: "slice height",
|
||||
ls_lahi_l: ["layer height","in millimeters","0 = auto/detect"],
|
||||
ls_lahm_s: "slice minimum",
|
||||
|
|
|
|||
Loading…
Reference in a new issue