From fe5ac4171de715b947cb6253c766fa5c05af49d1 Mon Sep 17 00:00:00 2001 From: Oleg-SH88 <102018920+Oleg-SH88@users.noreply.github.com> Date: Fri, 10 Feb 2023 13:48:43 +0300 Subject: [PATCH 1/4] SLICER-136 Add _checkingGcode function --- plugins/GCodeWriter/GCodeWriter.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index c56875c..65bfbf9 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -222,6 +222,9 @@ def _getSerializedBounding(self): 'MAXY': aabb.front.item(), 'MAXZ': aabb.top.item()} + def _checkingGcode(self,data: list): + return True + def _getSlicerVersion(self): version = self._application.getVersion() return ";VERSION:%(VERSION)s\n" % \ From 54259f2b0095d9ac3faad72b75d03c8ed34ce4d9 Mon Sep 17 00:00:00 2001 From: Oleg-SH88 <102018920+Oleg-SH88@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:55:59 +0300 Subject: [PATCH 2/4] SLICER-136 Added an integrity check of the finished gcode --- plugins/GCodeWriter/GCodeWriter.py | 64 ++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index 65bfbf9..e0a991a 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -14,9 +14,9 @@ from steslicer.Utils.Threading import call_on_qt_thread from steslicer.Snapshot import Snapshot - from PyQt5.QtCore import QBuffer from UM.i18n import i18nCatalog + catalog = i18nCatalog("steslicer") @@ -83,6 +83,11 @@ def write(self, stream, nodes, mode = MeshWriter.OutputMode.TextMode): gcode_list = gcode_dict.get(active_build_plate, None) if gcode_list is not None: has_settings = False + check_gcode = self._checkingGcode(gcode_list) + if not check_gcode: + self._application.п + self.setInformation(catalog.i18nc("@warning:status", "Incorrect GCODE. Repeat the slicing of the model")) + return False preview_image = self._getPreviewImage() if preview_image: stream.write(preview_image) @@ -222,8 +227,44 @@ def _getSerializedBounding(self): 'MAXY': aabb.front.item(), 'MAXZ': aabb.top.item()} - def _checkingGcode(self,data: list): - return True + def _checkingGcode(self, data: list): + start_gcode = False + end_gcode = False + sequence_layers = False + current_layer = 0 + previous_layer = -1 + verified_gcode = self._prepareData(data) + for index, layer in enumerate(verified_gcode): + split_layer = layer.rsplit('\n', len(layer)) + for line in split_layer: + line = line.strip() + if line == 'STARTT': + start_gcode = True + elif line == 'END': + end_gcode = True + elif line.startswith(";LAYER_COUNT:"): + #number_layer = getValue(line, ";LAYER_COUNT:") + current_layer = 0 + previous_layer = -1 + elif line.startswith(";LAYER:"): + current_layer = line[len(";LAYER:"):] + try: + current_layer = int(current_layer) + except ValueError: + continue + if current_layer >= 0 and current_layer == (previous_layer+1): + previous_layer = current_layer + sequence_layers = True + elif current_layer < 0: + sequence_layers = True + else: + sequence_layers = False + else: + pass + if start_gcode and end_gcode and sequence_layers: + return True + + return False def _getSlicerVersion(self): version = self._application.getVersion() @@ -233,7 +274,7 @@ def _getSlicerVersion(self): } @call_on_qt_thread # must be called from the main thread because of OpenGL def _createSnapshot(self): - + Logger.log("d", "Creating thumbnail image...") try: snapshot = Snapshot.snapshot(width = 300, height = 300) @@ -258,3 +299,18 @@ def _getPreviewImage(self): } else: return None + + # function for separating merged ("stuck together") layers + def _prepareData(self, data: list): + prepare_data = data + for index, layer in enumerate(data): + res = [i for i in range(len(layer)) if layer.startswith(";LAYER:", i)] + if len(res) > 1: + my_list = layer.rsplit(';LAYER:', len(res) - 1) + for i in range(len(res)): + if my_list[i].startswith(";LAYER:"): + prepare_data[index] = my_list[i] + continue + my_list[i] = ";LAYER:" + my_list[i] + prepare_data.insert(index + i, my_list[i]) + return prepare_data From 0f9d1eae2114bc581f0708638867c9a4c294cecb Mon Sep 17 00:00:00 2001 From: Oleg-SH88 <102018920+Oleg-SH88@users.noreply.github.com> Date: Thu, 2 Mar 2023 15:58:03 +0300 Subject: [PATCH 3/4] SLICER-136 Update --- tests/TestPrintInformation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestPrintInformation.py b/tests/TestPrintInformation.py index ddec6de..9c01411 100644 --- a/tests/TestPrintInformation.py +++ b/tests/TestPrintInformation.py @@ -51,7 +51,7 @@ def test_setProjectName(): # Test simple name project_name = ["HelloWorld",".3mf"] print_information.setProjectName(project_name[0] + project_name[1]) - + project_name[0] == print_information._job_name + + project_name[0] == print_information._job_name # Test the name with one dot project_name = ["Hello.World",".3mf"] From 2eea5347ee5b2c99a26a5e559d13bca1a54063c0 Mon Sep 17 00:00:00 2001 From: Oleg-SH88 <102018920+Oleg-SH88@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:39:13 +0300 Subject: [PATCH 4/4] SLICER-136 fix test info 'START' --- plugins/GCodeWriter/GCodeWriter.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index e0a991a..5ba8336 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -85,7 +85,6 @@ def write(self, stream, nodes, mode = MeshWriter.OutputMode.TextMode): has_settings = False check_gcode = self._checkingGcode(gcode_list) if not check_gcode: - self._application.п self.setInformation(catalog.i18nc("@warning:status", "Incorrect GCODE. Repeat the slicing of the model")) return False preview_image = self._getPreviewImage() @@ -238,7 +237,7 @@ def _checkingGcode(self, data: list): split_layer = layer.rsplit('\n', len(layer)) for line in split_layer: line = line.strip() - if line == 'STARTT': + if line == 'START': start_gcode = True elif line == 'END': end_gcode = True