From 2b74a7f603940612fcf2baf45a50e54fb666bd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 19 Jan 2021 11:42:48 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=96=20staging/bugfix=20is=20now=20?= =?UTF-8?q?1.5.4.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index d6191b42b..c88373677 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,10 +24,10 @@ maintenance 1.5.0 42769dad7dda3bc0c6c94e0e8ce832af9b14a565 pep440-dev fix/.* 1.5.0 42769dad7dda3bc0c6c94e0e8ce832af9b14a565 pep440-dev improve/.* 1.5.0 42769dad7dda3bc0c6c94e0e8ce832af9b14a565 pep440-dev -# staging/bugfix is the branch for preparation of the 1.5.3 hotfix release +# staging/bugfix is the branch for preparation of the 1.5.4 bugfix release # so are any bug/... branches -staging/bugfix 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev -bug/.* 1.5.3 e46e8fa17a1553cd0c228a4fa4cfd93e2a9bce7b pep440-dev +staging/bugfix 1.5.4 5860942967618e424901412e6c41abc103cf64c2 pep440-dev +bug/.* 1.5.4 5860942967618e424901412e6c41abc103cf64c2 pep440-dev # staging/maintenance is currently the branch for preparation of 1.5.0rc4 # so is regressionfix/... From 2494736d5f4ce4b1e273ecd8ca573936b6dab4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 29 Apr 2021 12:48:18 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=96=20staging/bugfix=20is=20now=20?= =?UTF-8?q?1.6.1.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index bef2e0e8e..977aeb0d9 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,10 +24,10 @@ maintenance 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev fix/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev improve/.* 1.6.0 b7a45b79bf86339f0b28177ac1eaebb56d00ea37 pep440-dev -# staging/bugfix is the branch for preparation of the 1.5.4 bugfix release +# staging/bugfix is the branch for preparation of the 1.6.1 bugfix release # so are any bug/... branches -staging/bugfix 1.5.4 5860942967618e424901412e6c41abc103cf64c2 pep440-dev -bug/.* 1.5.4 5860942967618e424901412e6c41abc103cf64c2 pep440-dev +staging/bugfix 1.6.1 29484fb2926960279e62881d6ee073c374a2a5fe pep440-dev +bug/.* 1.6.1 29484fb2926960279e62881d6ee073c374a2a5fe pep440-dev # staging/maintenance is currently the branch for preparation of 1.6.0rc4 # so is regressionfix/... From 19c39588e6472d13a2d6b308d06fe717c3978a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 29 Apr 2021 15:04:54 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9B=20GCV:=20Fix=20dragging=20w/?= =?UTF-8?q?=20center=20origin=20&=20bed=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Minor refactoring to get rid of three problems. Not only is #4115 as introduced by 886c3d9449c3ddd4e5a9dd73a1397a564996db4c fixed but changes to the bed dimensions after printer profile change now trigger a proper viewport reset (zoom & translation) and there's now also a button to reset the viewport to a sensible default should you get completely lost in the viewer canvas. Closes #4115 --- .../gcodeviewer/static/js/gcodeviewer.js | 7 ++ .../gcodeviewer/static/js/viewer/renderer.js | 116 ++++++++++-------- .../gcodeviewer/static/js/viewer/ui.js | 4 + .../templates/gcodeviewer_tab.jinja2 | 1 + 4 files changed, 77 insertions(+), 51 deletions(-) diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 2f1a48ec7..306897424 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -214,6 +214,9 @@ $(function () { self.settings.printerProfiles .currentProfileData() .volume.formFactor.subscribe(self._printerProfileUpdated); + self.settings.printerProfiles + .currentProfileData() + .volume.origin.subscribe(self._printerProfileUpdated); } if (self.settings.printerProfiles.currentProfileData().axes) { self.settings.printerProfiles @@ -393,6 +396,10 @@ $(function () { self.clear(); }; + self.resetViewport = function () { + GCODE.ui.resetViewport(); + }; + self.resetOptions = function () { self.renderer_centerModel(false); self.renderer_centerViewport(false); diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/renderer.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/renderer.js index 1b1072f89..079125010 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/renderer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/renderer.js @@ -74,12 +74,18 @@ GCODE.renderer = (function () { onDragStop: undefined }; + // offset due to dragging var offsetModelX = 0, offsetModelY = 0; + + // TODO: remove in 1.7.0 var offsetBedX = 0, offsetBedY = 0; + + // scale due to zooming var scaleX = 1, scaleY = 1; + var speeds = []; var speedsByLayer = {}; var currentInvertX = false, @@ -357,8 +363,6 @@ GCODE.renderer = (function () { ctx.lineCap = "round"; trackTransforms(ctx); - ctx.scale(1, -1); // Invert y-axis - // dragging => translating canvas.addEventListener( "mousedown", @@ -395,6 +399,9 @@ GCODE.renderer = (function () { if (renderOptions["onDrag"] && renderOptions["onDrag"](pt) === false) return; + ctx.translate(pt.x - dragStart.x, pt.y - dragStart.y); + reRender(); + renderOptions["centerViewport"] = false; renderOptions["zoomInOnModel"] = false; renderOptions["zoomInOnBed"] = false; @@ -405,9 +412,6 @@ GCODE.renderer = (function () { scaleX = 1; scaleY = 1; - ctx.translate(pt.x - dragStart.x, pt.y - dragStart.y); - reRender(); - if (renderOptions["onInternalOptionChange"] !== undefined) { renderOptions["onInternalOptionChange"]({ centerViewport: false, @@ -451,6 +455,9 @@ GCODE.renderer = (function () { // return to old position ctx.translate(-pt.x, -pt.y); + // render + reRender(); + // disable conflicting options renderOptions["zoomInOnModel"] = false; renderOptions["zoomInOnBed"] = false; @@ -461,9 +468,6 @@ GCODE.renderer = (function () { scaleX = 1; scaleY = 1; - // render - reRender(); - if (renderOptions["onInternalOptionChange"] !== undefined) { renderOptions["onInternalOptionChange"]({ zoomInOnModel: false, @@ -1036,15 +1040,6 @@ GCODE.renderer = (function () { (renderOptions["bed"]["y"] / 2 - (layerBounds.minY + layerBounds.maxY) / 2); } - } else if ( - renderOptions["bed"]["circular"] || - renderOptions["bed"]["centeredOrigin"] - ) { - canvasCenter = ctx.transformedPoint(canvas.width / 2, canvas.height / 2); - offsetModelX = canvasCenter.x; - offsetModelY = canvasCenter.y; - offsetBedX = 0; - offsetBedY = 0; } else { offsetModelX = 0; offsetModelY = 0; @@ -1127,48 +1122,56 @@ GCODE.renderer = (function () { currentInvertY = invertY; }; + var resetViewport = function () { + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.scale(1, -1); // invert y axis + + var bedWidth = renderOptions["bed"]["x"]; + var bedHeight = renderOptions["bed"]["y"]; + if (renderOptions["bed"]["circular"]) { + bedWidth = bedHeight = renderOptions["bed"]["r"] * 2; + } + + // Ratio of bed to canvas viewport + var viewportRatio = Math.min( + (canvas.width - 10) / bedWidth, + (canvas.height - 10) / bedHeight + ); + + // Apply initial translation to center the bed in the viewport + var translationX, translationY; + if (renderOptions["bed"]["circular"] || renderOptions["bed"]["centeredOrigin"]) { + translationX = canvas.width / 2; + translationY = canvas.height / 2; + } else { + translationX = (canvas.width - bedWidth * viewportRatio) / 2; + translationY = + bedHeight * viewportRatio + + (canvas.height - bedHeight * viewportRatio) / 2; + } + + ctx.translate(translationX, -translationY); + ctx.scale(viewportRatio, viewportRatio); + + // Scaling to apply to move lines and extrusion/retraction markers + lineWidthFactor = 1 / viewportRatio; + + offsetModelX = 0; + offsetModelY = 0; + offsetBedX = 0; + offsetBedY = 0; + }; + // ***** PUBLIC ******* return { init: function () { startCanvas(); + resetViewport(); initialized = true; - var bedWidth = renderOptions["bed"]["x"]; - var bedHeight = renderOptions["bed"]["y"]; - if (renderOptions["bed"]["circular"]) { - bedWidth = bedHeight = renderOptions["bed"]["r"] * 2; - } - - // Ratio of bed to canvas viewport - var viewportRatio = Math.min( - (canvas.width - 10) / bedWidth, - (canvas.height - 10) / bedHeight - ); - - // Apply initial translation to center the bed in the viewport - var translationX, translationY; - if (renderOptions["bed"]["circular"]) { - translationX = canvas.width / 2; - translationY = canvas.height / 2; - } else { - translationX = (canvas.width - bedWidth * viewportRatio) / 2; - translationY = - bedHeight * viewportRatio + - (canvas.height - bedHeight * viewportRatio) / 2; - } - ctx.translate(translationX, -translationY); - - ctx.scale(viewportRatio, viewportRatio); - - offsetModelX = 0; - offsetModelY = 0; - offsetBedX = 0; - offsetBedY = 0; - - // Scaling to apply to move lines and extrusion/retraction markers - lineWidthFactor = 1 / viewportRatio; }, setOption: function (options) { var mustRefresh = false; + var mustReset = false; var dirty = false; for (var opt in options) { if (!renderOptions.hasOwnProperty(opt) || !options.hasOwnProperty(opt)) @@ -1190,10 +1193,17 @@ GCODE.renderer = (function () { ) { mustRefresh = true; } + + if ($.inArray(opt, ["bed", "onViewportChange"]) > -1) { + mustReset = true; + } } if (!dirty) return; if (initialized) { + if (mustReset) { + resetViewport(); + } if (mustRefresh) { this.refresh(); } else { @@ -1267,6 +1277,10 @@ GCODE.renderer = (function () { if (layerNum === undefined) layerNum = layerNumStore; this.doRender(model, layerNum); }, + resetViewport: function () { + resetViewport(); + reRender(); + }, getZ: function (layerNum) { if (!model || !model[layerNum]) { return "-1"; diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js index 50e1410b5..6d1e36bc9 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js @@ -177,6 +177,10 @@ GCODE.ui = (function () { } }, + resetViewport: function () { + GCODE.renderer.resetViewport(); + }, + updateLayerInfo: function (layerNum) { switchLayer(layerNum, true); }, diff --git a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_tab.jinja2 b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_tab.jinja2 index 9c8ce4eb3..eaf1b60bd 100644 --- a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_tab.jinja2 +++ b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_tab.jinja2 @@ -74,6 +74,7 @@

+

From 58fd13b2387db6296458e98810ee70a17adc9408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 3 May 2021 11:52:07 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20Fix=20refresh=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's in SECONDS, not milliseconds 🤦‍♀️ Part 1 of fixing #4119 --- src/octoprint/printer/standard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 27286c0c0..af8f5664a 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1087,7 +1087,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): tags=kwargs.get("tags", set()) | {"trigger:printer.refresh_sd_files"} ) if blocking: - self._sdFilelistAvailable.wait(kwargs.get("timeout", 10000)) + self._sdFilelistAvailable.wait(kwargs.get("timeout", 10)) # ~~ state monitoring From 0cb987a8bdcf02ea17b6dd62be71dd9fe6084ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 3 May 2021 12:07:51 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A5=85=20Prevent=20SD=20refresh=20whi?= =?UTF-8?q?le=20printing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part 2 of fixing #4119 --- docs/api/files.rst | 6 +++++- src/octoprint/printer/standard.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/api/files.rst b/docs/api/files.rst index 0757bde41..09e037ebd 100644 --- a/docs/api/files.rst +++ b/docs/api/files.rst @@ -15,7 +15,9 @@ Retrieve all files Retrieve information regarding all files currently available and regarding the disk space still available locally in the system. The results are cached for performance reasons. If you - want to override the cache, supply the query parameter ``force`` and set it to ``true``. + want to override the cache, supply the query parameter ``force`` and set it to ``true``. Note that + while printing a refresh/override of the cache for files stored on the printer's SD card + is disabled due to bandwidth restrictions on the serial interface. By default only returns the files and folders in the root directory. If the query parameter ``recursive`` is provided and set to ``true``, returns all files and folders. @@ -249,6 +251,8 @@ Retrieve files from specific location Retrieve information regarding the files currently available on the selected `location` and -- if targeting the ``local`` location -- regarding the disk space still available locally in the system. The results are cached for performance reasons. If you want to override the cache, supply the query parameter ``force`` and set it to ``true``. + Note that while printing a refresh/override of the cache for files stored on the printer's SD card + is disabled due to bandwidth restrictions on the serial interface. By default only returns the files and folders in the root directory. If the query parameter ``recursive`` is provided and set to ``true``, returns all files and folders. diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index af8f5664a..49d64e3db 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1086,7 +1086,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._comm.refreshSdFiles( tags=kwargs.get("tags", set()) | {"trigger:printer.refresh_sd_files"} ) - if blocking: + if blocking and not self.is_printing(): self._sdFilelistAvailable.wait(kwargs.get("timeout", 10)) # ~~ state monitoring