|
1 | 1 | import os.path |
2 | | -from io import StringIO |
3 | | -from time import time, sleep |
4 | 2 | import datetime |
5 | 3 | import base64 |
6 | 4 | import urllib |
7 | 5 | import json |
| 6 | +from io import StringIO |
| 7 | +from time import time, sleep |
| 8 | +from typing import cast |
8 | 9 |
|
9 | 10 | from PyQt5 import QtNetwork |
10 | 11 | from PyQt5.QtCore import QFile, QUrl, QObject, QCoreApplication, QByteArray, QTimer, pyqtProperty, pyqtSignal, pyqtSlot |
|
14 | 15 | from UM.Application import Application |
15 | 16 | from UM.Logger import Logger |
16 | 17 | from UM.Message import Message |
| 18 | +from UM.Mesh.MeshWriter import MeshWriter |
| 19 | +from UM.PluginRegistry import PluginRegistry |
17 | 20 | from UM.OutputDevice.OutputDevice import OutputDevice |
18 | 21 | from UM.OutputDevice import OutputDeviceError |
19 | 22 |
|
@@ -152,36 +155,13 @@ def onFilenameAccepted(self): |
152 | 155 |
|
153 | 156 | Logger.log("d", self._name_id + " | Loading gcode...") |
154 | 157 |
|
155 | | - # find the G-code for the active build plate to print |
156 | | - version = Application.getInstance().getVersion() |
157 | | - Logger.log("d", "Found Cura %s" % version) |
158 | | - if version.startswith('3.0') or version.startswith('3.1'): |
159 | | - # Cura 3.0 and 3.1 |
160 | | - gcode = getattr(Application.getInstance().getController().getScene(), "gcode_list") |
161 | | - else: |
162 | | - if version.startswith('3.2'): |
163 | | - # Cura 3.2 |
164 | | - active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate |
165 | | - else: |
166 | | - # Cura 3.3 and later |
167 | | - active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate |
168 | | - |
169 | | - gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict") |
170 | | - gcode = gcode_dict[active_build_plate_id] |
171 | | - |
172 | | - lines = len(gcode) |
173 | | - Logger.log("d", "Found %s lines of gcode." % lines) |
174 | | - |
175 | | - # send all the gcode to self._stream |
176 | | - nextYield = time() + 0.05 |
177 | | - i = 0 |
178 | | - for line in gcode: |
179 | | - i += 1 |
180 | | - self._stream.write(line) |
181 | | - if time() > nextYield: |
182 | | - self._onProgress(i / lines) |
183 | | - QCoreApplication.processEvents() |
184 | | - nextYield = time() + 0.05 |
| 158 | + # get the g-code through the GCodeWrite plugin |
| 159 | + # this serializes the actual scene and should produce the same output as "Save to File" |
| 160 | + gcode_writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter")) |
| 161 | + success = gcode_writer.write(self._stream, None) |
| 162 | + if not success: |
| 163 | + Logger.log("e", "GCodeWrite failed.") |
| 164 | + return |
185 | 165 |
|
186 | 166 | # start |
187 | 167 | Logger.log("d", self._name_id + " | Connecting...") |
|
0 commit comments