Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
macdylan committed Nov 28, 2022
1 parent bb01cff commit 7022590
Show file tree
Hide file tree
Showing 9 changed files with 666 additions and 583 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ dmypy.json
release.sh

*.zip
Makefile
52 changes: 23 additions & 29 deletions SM2GCodeWriter.py → GCodeWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
try:
from PyQt6.QtCore import QBuffer
from PyQt6.QtGui import QImage
# QImageFormat = QImage.Format.Format_Indexed8
QBufferOpenMode = QBuffer.OpenModeFlag.ReadWrite
except ImportError:
from PyQt5.QtCore import QBuffer
from PyQt5.QtGui import QImage
# QImageFormat = QImage.Format_Indexed8
QBufferOpenMode = QBuffer.ReadWrite

from UM.i18n import i18nCatalog

catalog = i18nCatalog("cura")


Expand All @@ -33,14 +32,22 @@ class SM2GCodeWriter(MeshWriter):
PROCESSED_IDENTITY = ";Processed by Snapmaker2Plugin (https://github.com/macdylan/Snapmaker2Plugin)"

@call_on_qt_thread
def write(self, stream, nodes, mode=MeshWriter.OutputMode.TextMode) -> bool:
def write(self,
stream,
nodes,
mode=MeshWriter.OutputMode.TextMode) -> bool:
if mode != MeshWriter.OutputMode.TextMode:
Logger.log("e", "SM2GCodeWriter does not support non-text mode.")
self.setInformation(catalog.i18nc("@error:not supported", "SM2GCodeWriter does not support non-text mode."))
Logger.error("SM2GCodeWriter does not support non-text mode.")
self.setInformation(
catalog.i18nc(
"@error:not supported",
"SM2GCodeWriter does not support non-text mode."))
return False

gcode = StringIO()
writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter"))
writer = cast(
MeshWriter,
PluginRegistry.getInstance().getPluginObject("GCodeWriter"))
success = writer.write(gcode, None)

if not success:
Expand All @@ -51,11 +58,11 @@ def write(self, stream, nodes, mode=MeshWriter.OutputMode.TextMode) -> bool:
try:
result = self.mod(gcode)
stream.write(result.getvalue())
Logger.log("i", "SM2GCodeWriter done")
Logger.info("SM2GCodeWriter done")
return True
except ModError as e:
self.setInformation(str(e))
Logger.log("e", e)
Logger.error(e)
return False

def mod(self, data: StringIO) -> StringIO:
Expand Down Expand Up @@ -86,13 +93,16 @@ def mod(self, data: StringIO) -> StringIO:
p.write("\n")

app = CuraApplication.getInstance()
print_time = int(app.getPrintInformation().currentPrintTime) * 1.07 # Times empirical parameter: 1.07
print_time = int(app.getPrintInformation().currentPrintTime
) * 1.07 # Times empirical parameter: 1.07
print_speed = float(self._getValue("speed_infill"))
print_temp = float(self._getValue("material_print_temperature"))
bed_temp = float(self._getValue("material_bed_temperature")) or 0.0

if not print_speed or not print_temp:
raise ModError("Unable to slice with the current settings: speed_infill or material_print_temperature")
raise ModError(
"Unable to slice with the current settings: speed_infill or material_print_temperature"
)

p.write(";file_total_lines: %d\n" % len(gcodes))
p.write(";estimated_time(s): %.0f\n" % print_time)
Expand All @@ -111,15 +121,15 @@ def mod(self, data: StringIO) -> StringIO:
return p

def _createSnapshot(self) -> QImage:
Logger.log("d", "Creating thumbnail image...")
Logger.debug("Creating thumbnail image...")
try:
return Snapshot.snapshot(width=150, height=150) # .convertToFormat(QImageFormat)
return Snapshot.snapshot(width=240, height=160)
except Exception:
Logger.logException("w", "Failed to create snapshot image")
return None

def _encodeSnapshot(self, snapshot: QImage) -> str:
Logger.log("d", "Encoding thumbnail image...")
Logger.debug("Encoding thumbnail image...")
try:
thumbnail_buffer = QBuffer()
thumbnail_buffer.open(QBufferOpenMode)
Expand All @@ -133,19 +143,7 @@ def _encodeSnapshot(self, snapshot: QImage) -> str:
Logger.logException("w", "Failed to encode snapshot image")

def _getValue(self, key) -> str:
# app = CuraApplication.getInstance()
stack = ExtruderManager.getInstance().getActiveExtruderStack()
# stack2 = app.getGlobalContainerStack()
# stack3 = app.getMachineManager()

# stack = None
# if stack1.hasProperty(key, "value"):
# stack = stack1
# elif stack2.hasProperty(key, "value"):
# stack = stack2
# elif stack3.hasProperty(key, "value"):
# stack = stack3

if not stack:
return ""

Expand All @@ -155,15 +153,11 @@ def _getValue(self, key) -> str:
if str(GetType) == "float":
GelValStr = "{:.4f}".format(GetVal).rstrip("0").rstrip(".")
else:
# enum = Option list
if str(GetType) == "enum":
# definition_option = key + " option " + str(GetVal)
get_option = str(GetVal)
GetOption = stack.getProperty(key, "options")
GetOptionDetail = GetOption[get_option]
# GelValStr=i18n_catalog.i18nc(definition_option, GetOptionDetail)
GelValStr = GetOptionDetail
# Logger.log("d", "GetType_doTree = %s ; %s ; %s ; %s",definition_option, GelValStr, GetOption, GetOptionDetail)
else:
GelValStr = str(GetVal)

Expand Down
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

Loading

0 comments on commit 7022590

Please sign in to comment.