From a83bcedb2261d9b4a16e2dbd58b6faa9bb611f11 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 9 Jul 2015 16:27:22 +0200 Subject: [PATCH 1/8] Catch errors when trying to close the connection thread Contributes to #82 --- plugins/USBPrinting/PrinterConnection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/USBPrinting/PrinterConnection.py b/plugins/USBPrinting/PrinterConnection.py index a4867e656a..7ef6c759ac 100644 --- a/plugins/USBPrinting/PrinterConnection.py +++ b/plugins/USBPrinting/PrinterConnection.py @@ -255,7 +255,10 @@ class PrinterConnection(SignalEmitter): ## Close the printer connection def close(self): if self._connect_thread.isAlive(): - self._connect_thread.join() + try: + self._connect_thread.join() + except: + pass if self._serial is not None: self.setIsConnected(False) try: From 20874d88ad1d3f8e6ffbb97a64009f84ed0f8f68 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 9 Jul 2015 16:30:12 +0200 Subject: [PATCH 2/8] Properly close all open USB connections on shut down Contributes to #82 --- plugins/USBPrinting/USBPrinterManager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/USBPrinting/USBPrinterManager.py b/plugins/USBPrinting/USBPrinterManager.py index cb06113f60..5b889d30ce 100644 --- a/plugins/USBPrinting/USBPrinterManager.py +++ b/plugins/USBPrinting/USBPrinterManager.py @@ -46,6 +46,8 @@ class USBPrinterManager(QObject, SignalEmitter, Extension): ## Add menu item to top menu of the application. self.setMenuName("Firmware") self.addMenuItem(i18n_catalog.i18n("Update Firmware"), self.updateAllFirmware) + + Application.getInstance().applicationShuttingDown.connect(self._onApplicationShuttingDown) pyqtError = pyqtSignal(str, arguments = ["error"]) processingProgress = pyqtSignal(float, arguments = ["amount"]) @@ -292,3 +294,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension): else: base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*") return base_list + + def _onApplicationShuttingDown(self): + for connection in self._printer_connections: + connection.close() From b458a4c6e35aa6ecdd626f044b6fdbc0efdc44d4 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 9 Jul 2015 16:31:06 +0200 Subject: [PATCH 3/8] Correct a copy-paste error in getConnectionList Contributes to #82 --- plugins/USBPrinting/USBPrinterManager.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterManager.py b/plugins/USBPrinting/USBPrinterManager.py index 5b889d30ce..0609869059 100644 --- a/plugins/USBPrinting/USBPrinterManager.py +++ b/plugins/USBPrinting/USBPrinterManager.py @@ -282,17 +282,17 @@ class USBPrinterManager(QObject, SignalEmitter, Extension): i = 0 while True: values = winreg.EnumValue(key, i) - if not base_list or "USBSER" in values[0]: + if not only_list_usb or "USBSER" in values[0]: base_list += [values[1]] i += 1 except Exception as e: pass - - if base_list: - base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*") - base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list else: - base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*") + if only_list_usb: + base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*") + base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list + else: + base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*") return base_list def _onApplicationShuttingDown(self): From ba80cdba67a9ae4d67bd5924a36dc5299dc0b333 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 9 Jul 2015 16:31:44 +0200 Subject: [PATCH 4/8] Write to the correct variable so bed temperature is properly updated Contributes to #82 --- plugins/USBPrinting/USBPrinterManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/USBPrinting/USBPrinterManager.py b/plugins/USBPrinting/USBPrinterManager.py index 0609869059..066ae585da 100644 --- a/plugins/USBPrinting/USBPrinterManager.py +++ b/plugins/USBPrinting/USBPrinterManager.py @@ -172,7 +172,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension): ## Callback for bed temperature change def onBedTemperature(self, serial_port,temperature): - self._bed_temperature = temperature + self._bed_temp = temperature self.pyqtBedTemperature.emit(temperature) ## Callback for error From f4153fa63ec30bcc9442729abbf47032e7770975 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jul 2015 10:51:54 +0200 Subject: [PATCH 5/8] Only process the layer data if the layer view is active. Contributes to #109 --- .../CuraEngineBackend/CuraEngineBackend.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index ab7b4cebf3..d5e948d0cd 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -37,6 +37,12 @@ class CuraEngineBackend(Backend): self._scene = Application.getInstance().getController().getScene() self._scene.sceneChanged.connect(self._onSceneChanged) + # Workaround to disable layer view processing if layer view is not active. + self._layer_view_active = False + Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged) + self._onActiveViewChanged() + self._stored_layer_data = None + self._settings = None Application.getInstance().activeMachineChanged.connect(self._onActiveMachineChanged) self._onActiveMachineChanged() @@ -150,7 +156,7 @@ class CuraEngineBackend(Backend): obj = msg.objects.add() obj.id = id(object) - verts = numpy.array(mesh_data.getVertices(), copy=True) + verts = numpy.array(mesh_data.getVertices()) verts[:,[1,2]] = verts[:,[2,1]] verts[:,1] *= -1 obj.vertices = verts.tostring() @@ -188,8 +194,11 @@ class CuraEngineBackend(Backend): def _onSlicedObjectListMessage(self, message): if self._save_polygons: - job = ProcessSlicedObjectListJob.ProcessSlicedObjectListJob(message) - job.start() + if self._layer_view_active: + job = ProcessSlicedObjectListJob.ProcessSlicedObjectListJob(message) + job.start() + else : + self._stored_layer_data = message def _onProgressMessage(self, message): if message.amount >= 0.99: @@ -248,3 +257,14 @@ class CuraEngineBackend(Backend): def _onToolOperationStopped(self, tool): self._enabled = True self._onChanged() + + def _onActiveViewChanged(self): + if Application.getInstance().getController().getActiveView(): + view = Application.getInstance().getController().getActiveView() + if view.getPluginId() == "LayerView": + self._layer_view_active = True + if self._stored_layer_data: + job = ProcessSlicedObjectListJob.ProcessSlicedObjectListJob(self._stored_layer_data) + job.start() + else: + self._layer_view_active = False From 8fa0468787b2a375668c67c789be49bec696e48e Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jul 2015 11:14:59 +0200 Subject: [PATCH 6/8] Also add the parent class' command line arguments Contributes to #96 --- cura/CuraApplication.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 5e2ba4a08a..f5a89df498 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -110,6 +110,7 @@ class CuraApplication(QtApplication): self._plugin_registry.loadPlugin("CuraEngineBackend") def addCommandLineOptions(self, parser): + super().addCommandLineOptions(parser) parser.add_argument("file", nargs="*", help="Files to load after starting the application.") def run(self): From 3e27c8b791f9da9fc877e773d3d69477d175cfa0 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jul 2015 15:58:34 +0200 Subject: [PATCH 7/8] Do not store files that fail to load in recent files Contributes to Ultimaker/Cura#103 --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f5a89df498..3e7ae252c8 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -523,7 +523,7 @@ class CuraApplication(QtApplication): op.push() def _onJobFinished(self, job): - if type(job) is not ReadMeshJob: + if type(job) is not ReadMeshJob or not job.getResult(): return f = QUrl.fromLocalFile(job.getFileName()) From 6859481fd48deb87a3fcb3d3bc77d8a9031f1aa0 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jul 2015 16:02:01 +0200 Subject: [PATCH 8/8] Send M104 to set the temperature to 0 This makes it possible to continue communication after cancelling a print. Contributes to #82 --- plugins/USBPrinting/PrinterConnection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/USBPrinting/PrinterConnection.py b/plugins/USBPrinting/PrinterConnection.py index 7ef6c759ac..9d3c3334ef 100644 --- a/plugins/USBPrinting/PrinterConnection.py +++ b/plugins/USBPrinting/PrinterConnection.py @@ -468,7 +468,7 @@ class PrinterConnection(SignalEmitter): # Turn of temperatures self._sendCommand("M140 S0") - self._sendCommand("M109 S0") + self._sendCommand("M104 S0") self._is_printing = False ## Check if the process did not encounter an error yet.