From 0dc452e445b345d2a42d133467d0833a90af6b6b Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Thu, 11 Feb 2021 12:58:25 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20skipping?= =?UTF-8?q?=20gcode=20in=20the=20gcode=20viewer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bundledplugins/gcodeviewer.rst | 1 + src/octoprint/plugins/gcodeviewer/__init__.py | 5 +++-- .../gcodeviewer/static/js/gcodeviewer.js | 19 +++++++++++++++++-- .../templates/gcodeviewer_settings.jinja2 | 11 +++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/bundledplugins/gcodeviewer.rst b/docs/bundledplugins/gcodeviewer.rst index 704d04213..8af5f971c 100644 --- a/docs/bundledplugins/gcodeviewer.rst +++ b/docs/bundledplugins/gcodeviewer.rst @@ -27,6 +27,7 @@ The plugin supports the following configuration keys: * ``mobileSizeThreshold``: Whether to also enable tracking on unreleased OctoPrint versions (anything not stable releases or release candidates). Defaults to ``false``. * ``sizeThreshold``: Unique instance identifier, auto generated on first activation + * ``skipUntilthis``: If this string is provided the GCode Viewer will search for this string, and if found, skip all gcode up until this string. This can be used to skip prime nozzle gcode in the preview .. _sec-bundledplugins-gcodeviewer-sourcecode: diff --git a/src/octoprint/plugins/gcodeviewer/__init__.py b/src/octoprint/plugins/gcodeviewer/__init__.py index a7331b0ca..7622ee710 100644 --- a/src/octoprint/plugins/gcodeviewer/__init__.py +++ b/src/octoprint/plugins/gcodeviewer/__init__.py @@ -48,8 +48,9 @@ class GcodeviewerPlugin( def get_settings_defaults(self): return { "mobileSizeThreshold": 2 * 1024 * 1024, # 2MB - "sizeThreshold": 20 * 1024 * 1024, - } # 20MB + "sizeThreshold": 20 * 1024 * 1024, # 20MB + "skipUntilthis": None, + } def get_settings_version(self): return 1 diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 6fb9ba4e3..261851798 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -475,6 +475,21 @@ $(function () { }; self.showGCodeViewer = function (response, rstatus) { + // Slice of the gcode + if (self.settings.settings.plugins.gcodeviewer.skipUntilthis() != "") { + var findThis = + self.settings.settings.plugins.gcodeviewer.skipUntilthis() + ""; + var indexPos = response.indexOf("\n" + findThis); + // Try windows newlines if not found + if (indexPos == -1) { + indexPos = response.indexOf("\r" + findThis); + } + if (indexPos != -1) { + // Slice and make sure we comment out any string left back after slicing - so if a user configures something like "G1" we dont end up with a snippet of gcode commands + // Yes it would be prettier to parse it line by line and remove the entire line, that is very slow and uses mem - this way we find the string, and remove it + response = ";" + response.slice(indexPos + findThis.length + 1); + } + } var par = { target: { result: response @@ -879,8 +894,8 @@ $(function () { self.resetOptions(); var current = loadFromLocalStorage(optionsLocalStorageKey); - if (current["centerViewport"] !== undefined) - self.renderer_centerViewport(current["centerViewport"]); + if (current["centerViewPort"] !== undefined) + self.renderer_centerViewport(current["centerViewPort"]); if (current["zoomOnModel"] !== undefined) self.renderer_zoomOnModel(current["zoomOnModel"]); if (current["showMoves"] !== undefined) diff --git a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 index f61067956..b6e485083 100644 --- a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 +++ b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 @@ -19,4 +19,15 @@ +
+ +
+ +
+
+ + {% trans %}If provided, the GCode Viewer will search for a line beginning with this string. If found, all GCode up to that point will be skipped. This can be used to skip "purge/nozzle wipe" GCode in the viewer. Note the search is case sensitive. Example: ; layer 1{% endtrans %} + +
+
From ac2e25f6d62a68872cd5139807312d49e6c19b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 23 Feb 2021 16:23:55 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20skipUntilthis=20=3D>?= =?UTF-8?q?=20skipUntilThis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also made some comparisons a bit more resilient. --- docs/bundledplugins/gcodeviewer.rst | 2 +- src/octoprint/plugins/gcodeviewer/__init__.py | 2 +- .../plugins/gcodeviewer/static/js/gcodeviewer.js | 9 ++++----- .../gcodeviewer/templates/gcodeviewer_settings.jinja2 | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/bundledplugins/gcodeviewer.rst b/docs/bundledplugins/gcodeviewer.rst index 8af5f971c..b112a22c7 100644 --- a/docs/bundledplugins/gcodeviewer.rst +++ b/docs/bundledplugins/gcodeviewer.rst @@ -27,7 +27,7 @@ The plugin supports the following configuration keys: * ``mobileSizeThreshold``: Whether to also enable tracking on unreleased OctoPrint versions (anything not stable releases or release candidates). Defaults to ``false``. * ``sizeThreshold``: Unique instance identifier, auto generated on first activation - * ``skipUntilthis``: If this string is provided the GCode Viewer will search for this string, and if found, skip all gcode up until this string. This can be used to skip prime nozzle gcode in the preview + * ``skipUntilThis``: If this string is provided the GCode Viewer will search for this string, and if found, skip all gcode up until this string. This can be used to skip prime nozzle gcode in the preview .. _sec-bundledplugins-gcodeviewer-sourcecode: diff --git a/src/octoprint/plugins/gcodeviewer/__init__.py b/src/octoprint/plugins/gcodeviewer/__init__.py index 7622ee710..7bc359016 100644 --- a/src/octoprint/plugins/gcodeviewer/__init__.py +++ b/src/octoprint/plugins/gcodeviewer/__init__.py @@ -49,7 +49,7 @@ class GcodeviewerPlugin( return { "mobileSizeThreshold": 2 * 1024 * 1024, # 2MB "sizeThreshold": 20 * 1024 * 1024, # 20MB - "skipUntilthis": None, + "skipUntilThis": None, } def get_settings_version(self): diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 261851798..5f194574a 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -476,15 +476,14 @@ $(function () { self.showGCodeViewer = function (response, rstatus) { // Slice of the gcode - if (self.settings.settings.plugins.gcodeviewer.skipUntilthis() != "") { - var findThis = - self.settings.settings.plugins.gcodeviewer.skipUntilthis() + ""; + var findThis = self.settings.settings.plugins.gcodeviewer.skipUntilThis(); + if (findThis && findThis !== "") { var indexPos = response.indexOf("\n" + findThis); // Try windows newlines if not found - if (indexPos == -1) { + if (indexPos === -1) { indexPos = response.indexOf("\r" + findThis); } - if (indexPos != -1) { + if (indexPos !== -1) { // Slice and make sure we comment out any string left back after slicing - so if a user configures something like "G1" we dont end up with a snippet of gcode commands // Yes it would be prettier to parse it line by line and remove the entire line, that is very slow and uses mem - this way we find the string, and remove it response = ";" + response.slice(indexPos + findThis.length + 1); diff --git a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 index b6e485083..1520023a1 100644 --- a/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 +++ b/src/octoprint/plugins/gcodeviewer/templates/gcodeviewer_settings.jinja2 @@ -20,9 +20,9 @@
- +
- +