Merge branch 'rel-4.1'
This commit is contained in:
commit
8be4f5adfa
4 changed files with 98 additions and 41 deletions
|
|
@ -258,7 +258,7 @@ CAM.init = function(kiri, api) {
|
||||||
"selection.rotate"
|
"selection.rotate"
|
||||||
], updateStock);
|
], updateStock);
|
||||||
|
|
||||||
// invalidate trace ops on scale or rotate
|
// invalidate trace and drill ops on scale or rotate
|
||||||
api.event.on([
|
api.event.on([
|
||||||
"selection.scale",
|
"selection.scale",
|
||||||
"selection.rotate"
|
"selection.rotate"
|
||||||
|
|
@ -268,6 +268,9 @@ CAM.init = function(kiri, api) {
|
||||||
if (op.type === 'trace' && !flipping) {
|
if (op.type === 'trace' && !flipping) {
|
||||||
op.areas = {};
|
op.areas = {};
|
||||||
}
|
}
|
||||||
|
else if( op.type === 'drill' && !flipping){
|
||||||
|
op.drills = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -401,7 +404,7 @@ CAM.init = function(kiri, api) {
|
||||||
|
|
||||||
func.opAddDrill = () => {
|
func.opAddDrill = () => {
|
||||||
let rec = popOp.drill.new();
|
let rec = popOp.drill.new();
|
||||||
rec.drills = { /* widget.id: [ drills... ] */ };
|
rec.drills = { };
|
||||||
func.opAdd(rec);
|
func.opAdd(rec);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1245,11 +1248,10 @@ CAM.init = function(kiri, api) {
|
||||||
alert = api.show.alert("Some holes are shadowed by part and are not shown.");
|
alert = api.show.alert("Some holes are shadowed by part and are not shown.");
|
||||||
}
|
}
|
||||||
centers = centers ?? []
|
centers = centers ?? []
|
||||||
//flattened list of all hole centers and if they are selected
|
// list of all hole centers and if they are selected
|
||||||
kiri.api.widgets.for(widget => {
|
kiri.api.widgets.for(widget => {
|
||||||
const {holes} = centers.find(center=>center.id = widget.id)
|
const {holes} = centers.find(center=>center.id = widget.id)
|
||||||
|
// console.log(holes)
|
||||||
console.log(holes)
|
|
||||||
if (!holes.length) unselectHoles(holes);
|
if (!holes.length) unselectHoles(holes);
|
||||||
holes.forEach(hole => {
|
holes.forEach(hole => {
|
||||||
createHoleMesh(widget, hole)
|
createHoleMesh(widget, hole)
|
||||||
|
|
@ -1403,12 +1405,12 @@ CAM.init = function(kiri, api) {
|
||||||
func.traceDone();
|
func.traceDone();
|
||||||
}
|
}
|
||||||
unselectTraces(widget);
|
unselectTraces(widget);
|
||||||
if (flipping) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (holeSelOn) {
|
if (holeSelOn) {
|
||||||
func.selectHolesDone();
|
func.selectHolesDone();
|
||||||
}
|
}
|
||||||
|
if (flipping) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
func.clearHolesRec(widget)
|
func.clearHolesRec(widget)
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
clearTabs(widget);
|
clearTabs(widget);
|
||||||
|
|
@ -1778,8 +1780,8 @@ CAM.init = function(kiri, api) {
|
||||||
lift: 'camDrillLift',
|
lift: 'camDrillLift',
|
||||||
mark: 'camDrillMark',
|
mark: 'camDrillMark',
|
||||||
thru: 'camDrillThru',
|
thru: 'camDrillThru',
|
||||||
})
|
|
||||||
|
|
||||||
|
})
|
||||||
drillOp.inputs = {
|
drillOp.inputs = {
|
||||||
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
|
tool: UC.newSelect(LANG.cc_tool, {}, "tools"),
|
||||||
sep: UC.newBlank({class:"pop-sep"}),
|
sep: UC.newBlank({class:"pop-sep"}),
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ kiri.load(api => {
|
||||||
// const fresh = widgets.filter(widget => CAM.traces(settings, widget, single));
|
// const fresh = widgets.filter(widget => CAM.traces(settings, widget, single));
|
||||||
send.done(kiri.codec.encode(fresh.map(widget => { return {
|
send.done(kiri.codec.encode(fresh.map(widget => { return {
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
holes: widget.holes,
|
holes: widget.drills,
|
||||||
shadowed:widget.shadowedDrills
|
shadowed:widget.shadowedDrills
|
||||||
} } )));
|
} } )));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -628,12 +628,20 @@ class OpOutline extends CamOp {
|
||||||
} else {
|
} else {
|
||||||
if (op.wide) {
|
if (op.wide) {
|
||||||
let stepover = toolDiam * op.step;
|
let stepover = toolDiam * op.step;
|
||||||
for (let c = (op.steps || 1); c > 0; c--)
|
let wideCuts = [] //accumulator for wide cuts
|
||||||
offset.slice().forEach(op => {
|
for (let c = (op.steps || 1); c > 0; c--){
|
||||||
// clone removes inners but the real solution is
|
offset.slice().forEach(op => {
|
||||||
// to limit expanded shells to through holes
|
// clone removes inners but the real solution is
|
||||||
POLY.expand([op.clone(true)], stepover, slice.z, offset, 1);
|
// to limit expanded shells to through holes
|
||||||
});
|
let wideCut = POLY.expand([op.clone(true)], stepover*c, slice.z, [], 1);
|
||||||
|
wideCut.forEach(cut =>{ //set order of cuts when wide
|
||||||
|
cut.order = c
|
||||||
|
if(cut.inner) cut.inner.forEach(inn =>{ inn.order = c })
|
||||||
|
});
|
||||||
|
wideCuts.push(...wideCut)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
offset.appendAll(wideCuts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -697,7 +705,10 @@ class OpOutline extends CamOp {
|
||||||
|
|
||||||
for (let slice of sliceOut) {
|
for (let slice of sliceOut) {
|
||||||
let polys = [], t = [], c = [];
|
let polys = [], t = [], c = [];
|
||||||
POLY.flatten(slice.camLines).forEach(function (poly) {
|
let lines =POLY.flatten(slice.camLines)
|
||||||
|
// console.log(lines);
|
||||||
|
lines.forEach((poly)=> {
|
||||||
|
poly.order = poly.order ?? 0;
|
||||||
let child = poly.parent;
|
let child = poly.parent;
|
||||||
if (depthFirst) { poly = poly.clone(); poly.parent = child ? 1 : 0 }
|
if (depthFirst) { poly = poly.clone(); poly.parent = child ? 1 : 0 }
|
||||||
if (child) c.push(poly); else t.push(poly);
|
if (child) c.push(poly); else t.push(poly);
|
||||||
|
|
@ -713,11 +724,21 @@ class OpOutline extends CamOp {
|
||||||
if (depthFirst) {
|
if (depthFirst) {
|
||||||
depthData.push(polys);
|
depthData.push(polys);
|
||||||
} else {
|
} else {
|
||||||
printPoint = poly2polyEmit(polys, printPoint, function(poly, index, count) {
|
let orderSplit = {}
|
||||||
poly.forEachPoint(function(point, pidx, points, offset) {
|
polys.forEach(poly => {
|
||||||
camOut(point.clone(), offset !== 0);
|
if(poly.order in orderSplit) orderSplit[poly.order].push(poly);
|
||||||
}, poly.isClosed(), index);
|
else orderSplit[poly.order] = [poly];
|
||||||
}, { swapdir: false });
|
})
|
||||||
|
Object.entries(orderSplit) //split the polys by order
|
||||||
|
.sort((a,b) => -(a[0] - b[0] )) //sort by order (highest first)
|
||||||
|
.forEach(([order, orderPolys]) => { // emit based on closest for each order
|
||||||
|
// console.log({order, orderPolys});
|
||||||
|
printPoint = poly2polyEmit(orderPolys, printPoint, function(poly, index, count) {
|
||||||
|
poly.forEachPoint(function(point, pidx, points, offset) {
|
||||||
|
camOut(point.clone(), offset !== 0);
|
||||||
|
}, poly.isClosed(), index);
|
||||||
|
}, { swapdir: false });
|
||||||
|
})
|
||||||
newLayer();
|
newLayer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -474,12 +474,14 @@ CAM.holes = async function(settings, widget, diam) {
|
||||||
.map(kv => parseFloat(kv).round(5))
|
.map(kv => parseFloat(kv).round(5))
|
||||||
.filter(z => z !== null)
|
.filter(z => z !== null)
|
||||||
)]
|
)]
|
||||||
|
let individual = (diam <= 0);
|
||||||
|
|
||||||
|
diam = individual ? 1 : diam; // sets default diameter when select individual used
|
||||||
|
|
||||||
let centerDiff = diam * 0.1,
|
let centerDiff = diam * 0.1,
|
||||||
area = (diam/2) * (diam/2) * Math.PI,
|
area = (diam/2) * (diam/2) * Math.PI,
|
||||||
areaDelta = area * 0.05,
|
circles = [],
|
||||||
drills = [],
|
slices = [];
|
||||||
slices = [],
|
|
||||||
individual = (diam <= 0);
|
|
||||||
|
|
||||||
function onEach(slice) {
|
function onEach(slice) {
|
||||||
slices.push(slice);
|
slices.push(slice);
|
||||||
|
|
@ -499,38 +501,70 @@ CAM.holes = async function(settings, widget, diam) {
|
||||||
for (let poly of inner) {
|
for (let poly of inner) {
|
||||||
let center = poly.calcCircleCenter();
|
let center = poly.calcCircleCenter();
|
||||||
center.area = poly.area();
|
center.area = poly.area();
|
||||||
|
center.overlapping = [center]
|
||||||
|
center.depth = 0;
|
||||||
// console.log("center",center)
|
// console.log("center",center)
|
||||||
center.selected = (!individual && poly.circularity() >= 0.985 && Math.abs(center.area - area) <= areaDelta );
|
if ( poly.circularity() < 0.985 ){
|
||||||
|
// if not circular, don't add to holes
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (center.isInPolygon(slice.shadow)) {
|
if (center.isInPolygon(slice.shadow)) {
|
||||||
// if shadowed, don't add, and inform client
|
// if shadowed, don't add, and inform client
|
||||||
shadowedDrills = true;
|
shadowedDrills = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let overlap = false;
|
let overlap = false;
|
||||||
for (let [i,drill] of drills.entries()) {
|
for (let [i,circle] of circles.entries()) {
|
||||||
let dist = drill.distTo2D(center)
|
let dist = circle.distTo2D(center)
|
||||||
//if on the same xy point, and both have the same selection value
|
|
||||||
if (dist <= centerDiff && drill.selected == center.selected) {
|
// //if on the same xy point,
|
||||||
// console.log("overlap",center,drill);
|
if (dist <= centerDiff ) {
|
||||||
if(center.z > drill.z) { //if current is higher than old
|
|
||||||
drills[i] = center; //replace with top point
|
// console.log("overlap",center,circle);
|
||||||
drills[i].depth = center.z-drill.z
|
circle.overlapping.push(center);
|
||||||
}else if(center.z <= drill.z-drill.depth){// if current is lower or same as old
|
|
||||||
drills[i].depth = drill.z-center.z
|
|
||||||
}
|
|
||||||
// if overlapping, don't add and continue
|
// if overlapping, don't add and continue
|
||||||
overlap = true;
|
overlap = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
center.depth = 0;
|
if (!overlap) circles.push(center);
|
||||||
if(!overlap) drills.push(center);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let drills = []
|
||||||
|
|
||||||
|
for (let c of circles) {
|
||||||
|
let overlapping = c.overlapping
|
||||||
|
.sort((a,b) => b.z - a.z)
|
||||||
|
|
||||||
|
let last = overlapping.shift();
|
||||||
|
while (overlapping.length) {
|
||||||
|
let circ = overlapping.shift();
|
||||||
|
let aveArea = (circ.area + last.area) / 2;
|
||||||
|
let areaDelta = Math.abs(circ.area -last.area)
|
||||||
|
if (areaDelta < aveArea * 0.05){ // if area delta less than 5% of average area
|
||||||
|
//keep top circle selected
|
||||||
|
last.depth = last.z - circ.z;
|
||||||
|
}else{ // if not the same area
|
||||||
|
//push and move on
|
||||||
|
drills.push(last);
|
||||||
|
last = circ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (last.depth != 0) drills.push(last) //add last circle
|
||||||
|
}
|
||||||
|
|
||||||
|
drills.forEach( h=>{
|
||||||
|
delete h.overlapping //for encoding
|
||||||
|
h.selected = (!individual && Math.abs(h.area - area) <= area * 0.05 ); //for same size selection
|
||||||
|
})
|
||||||
|
|
||||||
|
// console.log("unfiltered circles",circles)
|
||||||
|
// console.log("drills",drills)
|
||||||
drills = drills.filter(drill => drill.depth > 0)
|
drills = drills.filter(drill => drill.depth > 0)
|
||||||
widget.shadowedDrills = shadowedDrills
|
widget.shadowedDrills = shadowedDrills
|
||||||
widget.holes = drills;
|
widget.drills = drills;
|
||||||
return drills;
|
return drills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue