Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLICER-136 checking the gcode. don't merge #138

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions plugins/GCodeWriter/GCodeWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -83,6 +83,10 @@ 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.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)
Expand Down Expand Up @@ -222,6 +226,45 @@ def _getSerializedBounding(self):
'MAXY': aabb.front.item(),
'MAXZ': aabb.top.item()}

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 == 'START':
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()
return ";VERSION:%(VERSION)s\n" % \
Expand All @@ -230,7 +273,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)
Expand All @@ -255,3 +298,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
2 changes: 1 addition & 1 deletion tests/TestPrintInformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down