From 9522821232b82f95bd875d87e0ac1743f6b0beb2 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 13 Nov 2020 22:09:08 -0500 Subject: [PATCH] change default stock visualization in slice and preview modes --- src/kiri/main.js | 13 +++++++++---- src/mode/cam/client.js | 34 +++++++++++++++++++++++++++++++--- src/mode/cam/slice.js | 21 ++++++++++++--------- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/kiri/main.js b/src/kiri/main.js index 7258626a..7960b407 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -1285,6 +1285,12 @@ SPACE.update(); } + function updateStockVisibility() { + if (camStock) { + camStock.material.visible = settings.mode === 'CAM' && viewMode === VIEWS.ARRANGE; + } + } + function platformUpdateStock(refresh) { let sd = settings.process; let offset = UI.camStockOffset.checked; @@ -1341,7 +1347,7 @@ camStock.position.x = csox; camStock.position.y = csoy; camStock.position.z = csz / 2; - camStock.material.visible = settings.mode === 'CAM'; + updateStockVisibility(); camTopZ = csz; } else if (camStock) { // UI.stock.style.display = 'none'; @@ -1957,6 +1963,7 @@ viewMode = mode; platform.deselect(); updateSelectedInfo(); + updateStockVisibility(); switch (mode) { case VIEWS.ARRANGE: UI.back.style.display = ''; @@ -2032,9 +2039,7 @@ API.event.emit('device.set', currentDeviceName()); } // really belongs in CAM driver (lots of work / abstraction needed) - if (camStock) { - camStock.material.visible = settings.mode === 'CAM'; - } + updateStockVisibility(); // updates right-hand menu by enabling/disabling fields setViewMode(VIEWS.ARRANGE); UC.setMode(MODE); diff --git a/src/mode/cam/client.js b/src/mode/cam/client.js index 0b8e274a..1654340f 100644 --- a/src/mode/cam/client.js +++ b/src/mode/cam/client.js @@ -5,17 +5,20 @@ (function() { let KIRI = self.kiri, + BASE = self.base, CAM = KIRI.driver.CAM, - PRO = CAM.process; + PRO = CAM.process, + newPolygon = BASE.newPolygon, + newPoint = BASE.newPoint; CAM.init = function(kiri, api) { api.event.on("mode.set", (mode) => { - let isCAM = mode === 'CAM'; + const isCAM = mode === 'CAM'; $('set-tools').style.display = isCAM ? '' : 'none'; kiri.space.platform.setColor(isCAM ? 0xeeeeee : 0xcccccc); }); api.event.on("settings.saved", (settings) => { - let proc = settings.process; + const proc = settings.process; api.ui.camTabs.marker.style.display = proc.camTabsOn ? 'flex' : 'none'; api.ui.camRough.marker.style.display = proc.camRoughOn ? 'flex' : 'none'; api.ui.camDrill.marker.style.display = @@ -24,6 +27,31 @@ api.ui.camContour.marker.style.display = proc.camContourXOn || proc.camContourYOn ? 'flex' : 'none'; }); + + function updateStock() { + const STACKS = api.const.STACKS; + const SPACE = api.const.SPACE; + const stock = api.conf.get().stock; + const {x, y, z} = stock; + if (x && y && z) { + const render = new KIRI.Render().setLayer('stock', { face: 0xaaaaaa, line: 0xaaaaaa }, true); + const stack = STACKS.create('stock', SPACE.platform.world); + stack.add(render.addPolys([ + newPolygon().centerRectangle({x:0, y:0, z:0}, x, y), + newPolygon().centerRectangle({x:0, y:0, z}, x, y) + ], { thin: true } )); + const hx = x/2, hy = y/2; + stack.add(render.addLines([ + newPoint( hx, -hy, 0), newPoint( hx, -hy, stock.z), + newPoint( hx, hy, 0), newPoint( hx, hy, stock.z), + newPoint(-hx, -hy, 0), newPoint(-hx, -hy, stock.z), + newPoint(-hx, hy, 0), newPoint(-hx, hy, stock.z), + ], { thin: true })); + } + } + + api.event.on("slice.end", updateStock); + api.event.on("preview.end", updateStock); }; })(); diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index 97dc3325..06f34c35 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -59,18 +59,21 @@ camRoughDown = proc.camRoughDown, minStepDown = Math.min(1, roughDown, outlineDown), maxToolDiam = 0, - thruHoles; + thruHoles, + stock = settings.stock || {}; - if (settings.stock.x + 0.00001 < bounds.max.x - bounds.min.x) { - return ondone('stock X too small for part. disable stock or use offset stock'); - } + if (stock.x && stock.y && stock.z) { + if (stock.x + 0.00001 < bounds.max.x - bounds.min.x) { + return ondone('stock X too small for part. disable stock or use offset stock'); + } - if (settings.stock.y + 0.00001 < bounds.max.y - bounds.min.y) { - return ondone('stock Y too small for part. disable stock or use offset stock'); - } + if (stock.y + 0.00001 < bounds.max.y - bounds.min.y) { + return ondone('stock Y too small for part. disable stock or use offset stock'); + } - if (settings.stock.z + 0.00001 < bounds.max.z - bounds.min.z) { - return ondone('stock Z too small for part. disable stock or use offset stock'); + if (stock.z + 0.00001 < bounds.max.z - bounds.min.z) { + return ondone('stock Z too small for part. disable stock or use offset stock'); + } } if (sliceDepth <= 0.05) {