add progress bar for cam holes
This commit is contained in:
parent
089ce33ad3
commit
079bf03912
5 changed files with 77 additions and 36 deletions
|
|
@ -1219,7 +1219,6 @@ CAM.init = function(kiri, api) {
|
||||||
widget.adds.push(mesh); //for click detection
|
widget.adds.push(mesh); //for click detection
|
||||||
return mesh
|
return mesh
|
||||||
}
|
}
|
||||||
|
|
||||||
let meshesCached = widgets.every(widget=>poppedRec.drills[widget.id] != undefined)
|
let meshesCached = widgets.every(widget=>poppedRec.drills[widget.id] != undefined)
|
||||||
if( individual && meshesCached ){ // if any widget already has cached holes
|
if( individual && meshesCached ){ // if any widget already has cached holes
|
||||||
// console.log("already has cached holes",poppedRec.drills)
|
// console.log("already has cached holes",poppedRec.drills)
|
||||||
|
|
@ -1244,30 +1243,46 @@ CAM.init = function(kiri, api) {
|
||||||
})
|
})
|
||||||
|
|
||||||
}else{ // if no widget has cached holes
|
}else{ // if no widget has cached holes
|
||||||
await CAM.holes( individual,poppedRec, async centers => {
|
let alert = api.show.alert("");
|
||||||
let shadow = centers.some(c=>c.shadowed)
|
await CAM.holes(
|
||||||
api.hide.alert(alert)
|
individual,
|
||||||
if(shadow){
|
poppedRec,
|
||||||
alert = api.show.alert("Some holes are shadowed by part and are not shown.");
|
(progress,msg)=>{
|
||||||
}
|
console.log(progress,msg)
|
||||||
centers = centers ?? []
|
alert[0]=msg
|
||||||
// list of all hole centers and if they are selected
|
api.show.progress(progress,msg)
|
||||||
kiri.api.widgets.for(widget => {
|
api.alerts.update()
|
||||||
const {holes} = centers.find(center=>center.id = widget.id)
|
},
|
||||||
// console.log(holes)
|
async centers => {
|
||||||
if (!holes.length) unselectHoles(holes);
|
api.show.progress(0)
|
||||||
holes.forEach(hole => {
|
if(! Array.isArray(centers) ){
|
||||||
createHoleMesh(widget, hole)
|
console.log("worker returned a malformed drills response")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let shadow = centers.some(c=>c.shadowed)
|
||||||
|
api.hide.alert(alert)
|
||||||
|
if(shadow){
|
||||||
|
alert = api.show.alert("Some holes are shadowed by part and are not shown.");
|
||||||
|
}
|
||||||
|
centers = centers ?? []
|
||||||
|
// list of all hole centers and if they are selected
|
||||||
|
kiri.api.widgets.for(widget => {
|
||||||
|
const {holes} = centers.find(center=>center.id = widget.id)
|
||||||
|
// console.log(holes)
|
||||||
|
if (!holes.length) unselectHoles(holes);
|
||||||
|
holes.forEach(hole => {
|
||||||
|
createHoleMesh(widget, hole)
|
||||||
|
})
|
||||||
|
//add hole data to record
|
||||||
|
poppedRec.drills = poppedRec.drills ?? {}
|
||||||
|
poppedRec.drills[widget.id] = holes
|
||||||
|
//give widget access to an array of drill records that refrence it
|
||||||
|
//so that it can be cleared when widget is rotated or mirrored etc.
|
||||||
|
if(!widget.drills){widget.drills = []}
|
||||||
|
widget.drills.push(holes)
|
||||||
})
|
})
|
||||||
//add hole data to record
|
}
|
||||||
poppedRec.drills = poppedRec.drills ?? {}
|
);
|
||||||
poppedRec.drills[widget.id] = holes
|
|
||||||
//give widget access to an array of drill records that refrence it
|
|
||||||
//so that it can be cleared when widget is rotated or mirrored etc.
|
|
||||||
if(!widget.drills){widget.drills = []}
|
|
||||||
widget.drills.push(holes)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
//hide the alert once hole meshes are calculated on the worker, and then added to the scene
|
//hide the alert once hole meshes are calculated on the worker, and then added to the scene
|
||||||
// api.hide.alert(alert);
|
// api.hide.alert(alert);
|
||||||
|
|
|
||||||
|
|
@ -82,15 +82,21 @@ kiri.load(api => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//0 or less diameter means select all holes
|
|
||||||
CAM.holes = function(indiv,rec,onDone) {
|
CAM.holes = function(indiv,rec,onProgress,onDone) {
|
||||||
kiri.client.sync();
|
kiri.client.sync();
|
||||||
const settings = api.conf.get();
|
const settings = api.conf.get();
|
||||||
return new Promise((res,rej)=>{
|
return new Promise((res,rej)=>{
|
||||||
kiri.client.send("cam_holes", { settings, rec, indiv }, output => {
|
kiri.client.send("cam_holes", { settings, rec, indiv }, output => {
|
||||||
let out = kiri.codec.decode(output)
|
let out = kiri.codec.decode(output)
|
||||||
onDone(out)
|
if(out.progress != undefined){
|
||||||
res(out)
|
//if a progress message,
|
||||||
|
onProgress(out.progress,out.msg)
|
||||||
|
}else{
|
||||||
|
api.hide.alert(alert)
|
||||||
|
onDone(out)
|
||||||
|
res(out)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -161,8 +167,11 @@ kiri.load(api => {
|
||||||
const { settings, indiv, rec } = data;
|
const { settings, indiv, rec } = data;
|
||||||
const widgets = Object.values(kiri.worker.cache);
|
const widgets = Object.values(kiri.worker.cache);
|
||||||
const fresh = [];
|
const fresh = [];
|
||||||
for (let widget of widgets) {
|
|
||||||
if (await CAM.holes(settings, widget, indiv, rec)) {
|
for (let [i,widget] of widgets.entries() ) {
|
||||||
|
if (await CAM.holes(settings, widget, indiv, rec,
|
||||||
|
( prog, msg )=>{ send.data({progress: (i/widgets.length)+(prog/widgets.length),msg})}
|
||||||
|
)){
|
||||||
fresh.push(widget);
|
fresh.push(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -441,10 +441,12 @@ CAM.traces = async function(settings, widget, single) {
|
||||||
*
|
*
|
||||||
* @param {Object} settings - settings object
|
* @param {Object} settings - settings object
|
||||||
* @param {Object} widget - widget object
|
* @param {Object} widget - widget object
|
||||||
* @param {number} diam - diameter of the drill bit
|
* @param {boolean} individual - if true, drill holes individually
|
||||||
|
* @param {Object} rec - DrillOp record
|
||||||
|
* @param {Function} onProgress - callback function to report progress
|
||||||
* @returns {Array} list of hole centers as objects with `x`, `y`, `z`, `depth`, and `selected` properties.
|
* @returns {Array} list of hole centers as objects with `x`, `y`, `z`, `depth`, and `selected` properties.
|
||||||
*/
|
*/
|
||||||
CAM.holes = async function(settings, widget, individual, rec) {
|
CAM.holes = async function(settings, widget, individual, rec,onProgress) {
|
||||||
|
|
||||||
let {tool,mark,precision} = rec //TODO: display some visual difference if mark is selected
|
let {tool,mark,precision} = rec //TODO: display some visual difference if mark is selected
|
||||||
let toolDiam = new CAM.Tool(settings,tool).fluteDiameter()
|
let toolDiam = new CAM.Tool(settings,tool).fluteDiameter()
|
||||||
|
|
@ -491,11 +493,11 @@ CAM.holes = async function(settings, widget, individual, rec) {
|
||||||
function onEach(slice) {
|
function onEach(slice) {
|
||||||
slices.push(slice);
|
slices.push(slice);
|
||||||
}
|
}
|
||||||
let opts = { each: onEach };
|
let opts = { each: onEach, progress: (num,total)=> onProgress(num/total*0.5,"slice") };
|
||||||
await slicer.slice(indices, opts);
|
await slicer.slice(indices, opts);
|
||||||
let shadowedDrills = false;
|
let shadowedDrills = false;
|
||||||
// console.log("slices",slices)
|
// console.log("slices",slices)
|
||||||
for (let slice of slices) {
|
for (let [i,slice] of slices.entries()) {
|
||||||
for(let top of slice.tops){
|
for(let top of slice.tops){
|
||||||
// console.log("slicing",slice.z,top)
|
// console.log("slicing",slice.z,top)
|
||||||
slice.shadow = CAM.shadowAt(widget, slice.z, 0)
|
slice.shadow = CAM.shadowAt(widget, slice.z, 0)
|
||||||
|
|
@ -536,11 +538,12 @@ CAM.holes = async function(settings, widget, individual, rec) {
|
||||||
if (!overlap) circles.push(center);
|
if (!overlap) circles.push(center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onProgress(0.5+(i/slices.length*0.25),"recognize circles")
|
||||||
}
|
}
|
||||||
|
|
||||||
let drills = []
|
let drills = []
|
||||||
|
|
||||||
for (let c of circles) {
|
for (let [i,c] of circles.entries()) {
|
||||||
let overlapping = c.overlapping
|
let overlapping = c.overlapping
|
||||||
|
|
||||||
let last = overlapping.shift();
|
let last = overlapping.shift();
|
||||||
|
|
@ -558,6 +561,7 @@ CAM.holes = async function(settings, widget, individual, rec) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (last.depth != 0) drills.push(last) //add last circle
|
if (last.depth != 0) drills.push(last) //add last circle
|
||||||
|
onProgress(0.75+(i/circles.length*0.25),"assemble holes")
|
||||||
}
|
}
|
||||||
drills.forEach( h=>{
|
drills.forEach( h=>{
|
||||||
delete h.overlapping //for encoding
|
delete h.overlapping //for encoding
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,21 @@ class Slicer {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// slice through points at given Z and return polygons
|
/**
|
||||||
|
* Given an array of z-slice positions, generate a list of polygons
|
||||||
|
* representing the intersection of the mesh with the given z-slice
|
||||||
|
* positions.
|
||||||
|
*
|
||||||
|
* @param {number[]} zs - array of z-slice positions
|
||||||
|
* @param {Object} options - slicing parameters
|
||||||
|
* @param {number} [options.flatoff=0.01] - z offset when slicing on a flat surface
|
||||||
|
* @param {boolean} [options.progress=false] - callback with slice progress
|
||||||
|
* @param {function} [options.each] - callback with each slice result
|
||||||
|
* @returns {Promise<Object[]>} - list of slice objects with z and tops (polygons)
|
||||||
|
*/
|
||||||
async slice(zs, options) {
|
async slice(zs, options) {
|
||||||
const opt = this.setOptions(options);
|
const opt = this.setOptions(options);
|
||||||
|
// slice through points at given Z and return polygons
|
||||||
|
|
||||||
if (!Array.isArray(zs)) {
|
if (!Array.isArray(zs)) {
|
||||||
throw "slice zs parameter must be ab array";
|
throw "slice zs parameter must be ab array";
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ function show(message, time) {
|
||||||
api.event.emit('alert', rec);
|
api.event.emit('alert', rec);
|
||||||
} else {
|
} else {
|
||||||
alerts.push(rec);
|
alerts.push(rec);
|
||||||
|
setTimeout( update, time+0.02);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
return rec;
|
return rec;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue