track widget indexing to timeline selection

This commit is contained in:
Stewart Allen 2022-10-31 12:14:28 -04:00
commit b5f756acf6
7 changed files with 51 additions and 15 deletions

View file

@ -9,7 +9,7 @@
gapp.register("geo.paths", [], (root, exports) => {
const { base } = root;
const { util, config, newPoint } = base;
const { util, config } = base;
const { sqr, numOrDefault } = util;
const DEG2RAD = Math.PI / 180;

View file

@ -80,7 +80,11 @@ class Point {
}
clone() {
return newPoint(this.x, this.y, this.z, this._key);
let p = newPoint(this.x, this.y, this.z, this._key);
if (this.a) {
p.a = this.a;
}
return p;
}
slopeTo(p) {

View file

@ -492,7 +492,7 @@ kiri.load(() => {
const sd = Math.sqrt(mx*mx + my*my + mz*mz);
const moves = [];
for (let i=0, x=lp.x, y=lp.y, z=lp.z; i<st; i++) {
moves.push({x,y,z,md:sd});
moves.push({x,y,z,a:lp.a,md:sd});
x += mx;
y += my;
z += mz;

View file

@ -65,10 +65,15 @@ CAM.init = function(kiri, api) {
}
function setAnimationStyle(settings) {
isIndexed = settings.process.camStockIndexed;
if (!isIndexed || !isCamMode) {
for (let widget of API.widgets.all()) {
widget.setAxisIndex(0);
}
}
if (!isCamMode) {
return;
}
isIndexed = settings.process.camStockIndexed;
animVer = isIndexed ? 1 : 0;
updateStock();
SPACE.platform.setVisible(!isIndexed);
@ -400,19 +405,24 @@ CAM.init = function(kiri, api) {
listel.innerHTML = html.join('');
let bounds = [];
let unpop = null;
let index = 0;
let indexing = true;
// drag and drop re-ordering
for (let [id, rec] of Object.entries(bind)) {
let type = rec.type;
let clock = type === '|';
if (!clock)
$(`${id}-x`).onmousedown = (ev) => {
ev.stopPropagation();
ev.preventDefault();
func.surfaceDone();
func.traceDone();
func.tabDone();
func.opDel(rec);
};
if (!clock) {
$(`${id}-x`).onmousedown = (ev) => {
ev.stopPropagation();
ev.preventDefault();
func.surfaceDone();
func.traceDone();
func.tabDone();
func.opDel(rec);
};
} else {
indexing = false;
}
let el = $(id);
if (rec.disabled) {
el.classList.add("disabled");
@ -422,6 +432,9 @@ CAM.init = function(kiri, api) {
let inside = true;
let popped = false;
let poprec = popOp[rec.type];
if (type === 'index' && indexing) {
index = rec.absolute ? rec.degrees : index + rec.degrees;
}
el.rec = rec;
el.unpop = () => {
let pos = [...el.childNodes].indexOf(poprec.div);
@ -565,6 +578,10 @@ CAM.init = function(kiri, api) {
el.onmouseleave = onLeave;
}
}
// update widget rotations from timeline marker
for (let widget of API.widgets.all()) {
widget.setAxisIndex(-index);
}
});
func.opGCode = (label, field = 'gcode') => {

View file

@ -41,6 +41,10 @@ class CamOp {
class OpIndex extends CamOp {
constructor(state, op) {
super(state, op);
}
slice() {
let { op, state } = this;
state.setAxisIndex(op.degrees);
}

View file

@ -147,9 +147,13 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
}
sliceAll.appendAll(slices);
if (axisIndex !== undefined) {
console.log({post_axis_index: slices});
// update slice cam lines to add axis indexing
for (let slice of slices) {
slice.axisIndex = axisIndex;
for (let poly of slice.camLines) {
for (let point of poly.points) {
point.a = axisIndex;
}
}
}
}
}
@ -189,6 +193,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
let opSum = 0;
let opTot = opList.length ? opList.map(op => op.weight()).reduce((a,v) => a + v) : 0;
// determing # of steps and step weighting for progress bar
for (let op of proc.ops.filter(op => !op.disabled)) {
let opfn = OPS[op.type];
if (opfn) {
@ -201,6 +206,8 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
// give ops access to entire sequence
state.ops = opList;
// call slice() function on all ops in order
setAxisIndex(undefined);
for (let op of opList) {
let weight = op.weight();
op.slice((progress, message) => {

View file

@ -552,6 +552,10 @@ class Widget {
this.setModified();
}
setAxisIndex(deg) {
this.mesh.rotation.x = deg * (Math.PI / 180);
}
rotate(x, y, z, temp) {
this.group.forEach(w => {
w._rotate(x, y, z, temp);