From 44c1c850e9b5104ea826c1b6806d5dedf3e7ac74 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 1 Dec 2020 19:54:54 -0500 Subject: [PATCH] checkpoint trace work --- src/kiri/main.js | 2 +- src/kiri/stack.js | 4 +++- src/kiri/widget.js | 16 +++++++++++---- src/mode/cam/animate.js | 9 +++++++++ src/mode/cam/client.js | 45 +++++++++++++++++++++++++++++------------ src/mode/cam/driver.js | 4 ++-- src/mode/cam/prepare.js | 6 ++++-- src/mode/cam/slice.js | 6 +++++- src/mode/cam/tool.js | 4 ++++ web/kiri/index.css | 9 +++++++++ web/kiri/index.html | 1 + 11 files changed, 82 insertions(+), 24 deletions(-) diff --git a/src/kiri/main.js b/src/kiri/main.js index 64e7b798..11c732ca 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -2187,7 +2187,7 @@ UI.back.style.display = ''; UI.render.style.display = ''; UI.render.classList.add('lt-enabled'); - KIRI.work.clear(); + // KIRI.work.clear(); STACKS.clear(); hideSlider(); updateSpeeds(); diff --git a/src/kiri/stack.js b/src/kiri/stack.js index e86f77a6..3ba089e7 100644 --- a/src/kiri/stack.js +++ b/src/kiri/stack.js @@ -74,7 +74,7 @@ } const { polys, lines, faces, cface, paths, cpath, color, off } = layer; - const meshes = this.meshes; + const meshes = []; const defstate = !off; const mats = []; mats.state = defstate; @@ -185,6 +185,8 @@ mats.appendAll(mat); } + this.new_meshes = meshes; + this.meshes.appendAll(meshes); mats.forEach(mat => mat.visible = defstate); return mats; } diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 2acb32a4..90127011 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -390,7 +390,8 @@ */ PRO.setTopZ = function(z) { let mesh = this.mesh, - pos = this.track.pos; + pos = this.track.pos, + ltz = this.last_top_z || {}; if (z) { pos.z = mesh.getBoundingBox().max.z - z; mesh.position.z = -pos.z - 0.01; @@ -398,7 +399,12 @@ pos.z = 0; mesh.position.z = 0; } - this.modified = true; + let ntz = { + pz: pos.z, + mpz: mesh.position.z + }; + this.modified |= (ltz.pz !== ntz.pz || ltz.mpz !== ntz.mpz); + this.last_top_z = ntz; } PRO.move = function(x, y, z, abs) { @@ -448,6 +454,7 @@ scale.x *= (x || 1.0); scale.y *= (y || 1.0); scale.z *= (z || 1.0); + this.modified = true; }; PRO.rotate = function(x, y, z) { @@ -478,6 +485,7 @@ rot.y += (y || 0); rot.z += (z || 0); } + this.modified = true; }; PRO.unrotate = function() { @@ -486,6 +494,7 @@ }); this.roto = []; this.center(); + this.modified = true; }; PRO.mirror = function() { @@ -511,6 +520,7 @@ geo.computeFaceNormals(); geo.computeVertexNormals(); o.mirror = !o.mirror; + this.modified = true; }; PRO.getGeoVertices = function() { @@ -593,7 +603,6 @@ ondone(false, reply.error); } if (reply.done) { - widget.modified = false; ondone(true); } }); @@ -609,7 +618,6 @@ onupdate(1.0, "transfer"); widget.stats.slice_time = UTIL.time() - startTime; - widget.modified = false; ondone(); }; diff --git a/src/mode/cam/animate.js b/src/mode/cam/animate.js index f7a4a000..18a4b294 100644 --- a/src/mode/cam/animate.js +++ b/src/mode/cam/animate.js @@ -305,6 +305,15 @@ self.kiri.loader.push(function() { animating = true; stepsRemain--; if (next.tool >= 0 && (!tool || tool.getNumber() !== next.tool)) { + // on real tool change, go to safe Z first + if (tool) { + let pos = last.point = { + x: last.point.x, + y: last.point.y, + z: stock.z + }; + send.data({ mesh_move: { toolID, pos }}); + } updateTool(next.tool, send); } const id = toolID; diff --git a/src/mode/cam/client.js b/src/mode/cam/client.js index 1f7221e0..050f3dbc 100644 --- a/src/mode/cam/client.js +++ b/src/mode/cam/client.js @@ -10,6 +10,7 @@ PRO = CAM.process, newPolygon = BASE.newPolygon, newPoint = BASE.newPoint, + toolInfo, isAnimate, isArrange, isCamMode, @@ -33,6 +34,8 @@ UC = api.uc; API = api; + toolInfo = $('tool-info'); + api.event.on("mode.set", (mode) => { isCamMode = mode === 'CAM'; $('set-tools').style.display = isCamMode ? '' : 'none'; @@ -239,18 +242,21 @@ alert = api.show.alert("[esc] key cancels trace editing"); KIRI.api.widgets.opacity(0.5); KIRI.api.widgets.for(widget => { + if (widget.trace_stack) { + widget.adds.appendAll(widget.trace_stack.meshes); + widget.trace_stack.show(); + return; + } let stack = new KIRI.Stack(widget.mesh); widget.trace_stack = stack; widget.traces.forEach(poly => { let layers = new KIRI.Layers(); layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly); stack.addLayers(layers); - stack.meshes.forEach(mesh => { + stack.new_meshes.forEach(mesh => { mesh.trace = {widget, poly}; }); - // reset so each mesh array is new for the layer - widget.adds.appendAll(stack.meshes); - stack.meshes = []; + widget.adds.appendAll(stack.new_meshes); }); // for (let [key, val] of Object.entries(widget.sindex)) { // console.log('sindex', {key, val}); @@ -276,8 +282,8 @@ api.feature.hoverAdds = false; KIRI.api.widgets.for(widget => { if (widget.trace_stack) { + widget.trace_stack.hide(); widget.adds.removeAll(widget.trace_stack.meshes); - widget.trace_stack.destroy(); } }); }); @@ -300,6 +306,18 @@ return; } lastTrace = data.int.object; + if (lastTrace.selected) { + let traceInfo = lastTrace.trace.poly.traceInfo; + let tool = new CAM.Tool(current, traceInfo.tool); + toolInfo.innerText = [ + ` tool: ${tool.getName()}`, + ` feed: ${traceInfo.speed}`, + `plunge: ${traceInfo.plunge}` + ].join('\n'); + toolInfo.style.display = 'flex'; + } else { + toolInfo.style.display = ''; + } let material = lastTrace.material[0]; let color = material.color; let {r, g, b} = color; @@ -310,7 +328,6 @@ }; func.traceHoverUp = function(int) { if (!int) return; - console.log({traceHoverUp: int}); func.traceToggle(int.object); }; func.traceToggle = function(obj) { @@ -461,13 +478,15 @@ } function clearTraces(widget) { - Object.values(widget.traces || {}).forEach(rec => { - console.log('clear',rec); - // widget.adds.remove(rec.box); - // widget.mesh.remove(rec.box); - }); - widget.traces = {}; - widget.trace_stack = null; + let stack = widget.trace_stack; + if (stack) { + stack.meshes.forEach(mesh => { + if (mesh.selected) { + func.traceToggle(mesh); + } + }); + } + widget.trace = null; delete API.widgets.annotate(widget.id).trace; } diff --git a/src/mode/cam/driver.js b/src/mode/cam/driver.js index fc7a0a69..816f8352 100644 --- a/src/mode/cam/driver.js +++ b/src/mode/cam/driver.js @@ -42,8 +42,8 @@ KIRI.worker.traces = function(data, send) { const { settings } = data; const widgets = Object.values(cache); - widgets.forEach(widget => CAM.traces(settings, widget)); - send.done(KIRI.codec.encode(widgets.map(widget => {return { + const fresh = widgets.filter(widget => CAM.traces(settings, widget)); + send.done(KIRI.codec.encode(fresh.map(widget => {return { id: widget.id, traces: widget.traces, // sindex: widget.sindex diff --git a/src/mode/cam/prepare.js b/src/mode/cam/prepare.js index 7458f003..ad3b11d3 100644 --- a/src/mode/cam/prepare.js +++ b/src/mode/cam/prepare.js @@ -75,6 +75,8 @@ easeDown = process.camEaseDown, depthFirst = process.camDepthFirst, tolerance = process.camTolerance, + contour = process.camContourXOn || process.camContourYOn, + contourCurves = process.camContourCurves, drillDown = process.camDrillDown, drillLift = process.camDrillLift, drillDwell = process.camDrillDwell, @@ -550,7 +552,7 @@ printPoint = depthOutlinePath(printPoint, 0, flatLevels, toolDiam, polyEmit, true); } // two modes for deferred outlining: x then y or combined - if (process.camContourCurves) { + if (contour && contourCurves) { lastMode = PRO.CONTOUR_X; setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge); spindle = Math.min(spindleMax, process.camContourSpindle); @@ -567,7 +569,7 @@ newLayer(); return lastPoint; }); - } else { + } else if (contour) { setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge); spindle = Math.min(spindleMax, process.camContourSpindle); // deferred contour x outlining diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index 423780b3..88aeabe9 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -503,7 +503,6 @@ .addPolys(slice.topPolys()) sliceAll.push(slice); maxToolDiam = Math.max(maxToolDiam, traceToolDiam); -console.log({slice}); }); } @@ -537,6 +536,10 @@ console.log({slice}); }; CAM.traces = function computeTraces(settings, widget) { + if (widget.traces) { + // do no work if cached + return false; + } let slicer = new KIRI.slicer2(widget.getPoints(), { zlist: true, zline: true @@ -615,6 +618,7 @@ console.log({slice}); slicer.slice(indices, opts); widget.traces = traces; // widget.sindex = sindex; + return true; }; // drilling op diff --git a/src/mode/cam/tool.js b/src/mode/cam/tool.js index f243cb34..e9ff642a 100644 --- a/src/mode/cam/tool.js +++ b/src/mode/cam/tool.js @@ -28,6 +28,10 @@ return this.tool.id; } + getName() { + return this.tool.name; + } + getType() { return this.tool.type; } diff --git a/web/kiri/index.css b/web/kiri/index.css index 054e590d..fc66d2fd 100644 --- a/web/kiri/index.css +++ b/web/kiri/index.css @@ -1196,6 +1196,15 @@ th, tr, td, label { right: 5px; color: #000; } +#tool-info { + position: fixed; + white-space: pre; + font-family: monospace; + font-size: 12px; + bottom: 5px; + left: 5px; + color: #000; +} #winfo { position: fixed; font-size: 10px; diff --git a/web/kiri/index.html b/web/kiri/index.html index ed7086ab..92ff04b1 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -390,6 +390,7 @@

this site uses cookies to preserve application preferences

+