Merge branch '15.06'

This commit is contained in:
Arjen Hiemstra 2015-07-08 13:03:05 +02:00
commit 032e27c68c
30 changed files with 9355 additions and 109 deletions

View file

@ -209,6 +209,7 @@ class CuraEngineBackend(Backend):
def _onObjectPrintTimeMessage(self, message):
self.printDurationMessage.emit(message.time, message.material_amount)
self.processingProgress.emit(1.0)
def _createSocket(self):
super()._createSocket()

View file

@ -54,13 +54,13 @@ class ProcessSlicedObjectListJob(Job):
self._progress.setProgress(2)
mesh = MeshData()
layerData = LayerData.LayerData()
for object in self._message.objects:
try:
node = objectIdMap[object.id]
except KeyError:
continue
layerData = LayerData.LayerData()
for layer in object.layers:
layerData.addLayer(layer.id)
layerData.setLayerHeight(layer.id, layer.height)

View file

@ -4,60 +4,64 @@
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
Rectangle
{
width: 300; height: 100
ColumnLayout
import UM 1.0 as UM
UM.Dialog {
width: 500 * Screen.devicePixelRatio;
height: 100 * Screen.devicePixelRatio;
title: "Print with USB"
Column
{
RowLayout
anchors.fill: parent;
Row
{
Text
spacing: UM.Theme.sizes.default_margin.width;
Text
{
//: USB Printing dialog label, %1 is head temperature
text: qsTr("Extruder Temperature %1").arg(manager.extruderTemperature)
}
Text
Text
{
//: USB Printing dialog label, %1 is bed temperature
text: qsTr("Bed Temperature %1").arg(manager.bedTemperature)
}
Text
Text
{
text: "" + manager.error
}
}
RowLayout
{
Button
{
//: USB Printing dialog start print button
text: qsTr("Print");
onClicked: { manager.startPrint() }
enabled: manager.progress == 0 ? true : false
}
Button
{
//: USB Printing dialog cancel print button
text: qsTr("Cancel");
onClicked: { manager.cancelPrint() }
enabled: manager.progress == 0 ? false: true
}
}
ProgressBar
ProgressBar
{
id: prog;
value: manager.progress
anchors.left: parent.left;
anchors.right: parent.right;
minimumValue: 0;
maximumValue: 100;
Layout.maximumWidth:parent.width
Layout.preferredWidth:230
Layout.preferredHeight:25
Layout.minimumWidth:230
Layout.minimumHeight:25
width: 230
height: 25
value: manager.progress
}
}
rightButtons: [
Button {
//: USB Printing dialog start print button
text: qsTr("Print");
onClicked: { manager.startPrint() }
enabled: manager.progress == 0 ? true : false
},
Button
{
//: USB Printing dialog cancel print button
text: qsTr("Cancel");
onClicked: { manager.cancelPrint() }
enabled: manager.progress == 0 ? false: true
}
]
}

View file

@ -1,17 +1,35 @@
// Copyright (c) 2015 Ultimaker B.V.
// Cura is released under the terms of the AGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
Rectangle
{
width: 300; height: 100
ColumnLayout
{
import QtQuick 2.2
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Text
import UM 1.0 as UM
UM.Dialog
{
id: base;
width: 500 * Screen.devicePixelRatio;
height: 100 * Screen.devicePixelRatio;
visible: true;
modality: Qt.ApplicationModal;
title: "Firmware Update";
Column
{
anchors.fill: parent;
Text
{
anchors {
left: parent.left;
right: parent.right;
}
text: {
if (manager.progress == 0)
{
@ -29,20 +47,33 @@ Rectangle
return qsTr("Updating firmware.")
}
}
wrapMode: Text.Wrap;
}
ProgressBar
{
id: prog;
value: manager.progress
minimumValue: 0;
maximumValue: 100;
Layout.maximumWidth:parent.width
Layout.preferredWidth:230
Layout.preferredHeight:25
Layout.minimumWidth:230
Layout.minimumHeight:25
width: 230
height: 25
anchors {
left: parent.left;
right: parent.right;
}
}
SystemPalette {
id: palette;
}
}
rightButtons: [
Button {
text: "Close";
enabled: manager.progress >= 100;
onClicked: base.visible = false;
}
]
}

View file

@ -58,7 +58,7 @@ class PrinterConnection(SignalEmitter):
self._gcode_position = 0
# List of gcode lines to be printed
self._gcode = None
self._gcode = []
# Number of extruders
self._extruder_count = 1
@ -102,9 +102,13 @@ class PrinterConnection(SignalEmitter):
# \param gcode_list List with gcode (strings).
def printGCode(self, gcode_list):
if self.isPrinting() or not self._is_connected:
Logger.log("d", "Printer is busy or not connected, aborting print")
return
self._gcode = gcode_list
self._gcode.clear()
for layer in gcode_list:
self._gcode.extend(layer.split("\n"))
#Reset line number. If this is not done, first line is sometimes ignored
self._gcode.insert(0, "M110")
self._gcode_position = 0
@ -130,23 +134,23 @@ class PrinterConnection(SignalEmitter):
if self._is_connecting or self._is_connected:
self.close()
hex_file = intelHex.readHex(self._firmware_file_name)
if len(hex_file) == 0:
Logger.log("e", "Unable to read provided hex file. Could not update firmware")
return
programmer = stk500v2.Stk500v2()
programmer.progressCallback = self.setProgress
programmer.connect(self._serial_port)
time.sleep(1) # Give programmer some time to connect. Might need more in some cases, but this worked in all tested cases.
if not programmer.isConnected():
Logger.log("e", "Unable to connect with serial. Could not update firmware")
return
self._updating_firmware = True
try:
programmer.programChip(hex_file)
self._updating_firmware = False
@ -155,15 +159,19 @@ class PrinterConnection(SignalEmitter):
self._updating_firmware = False
return
programmer.close()
self.setProgress(100, 100)
## Upload new firmware to machine
# \param filename full path of firmware file to be uploaded
def updateFirmware(self, file_name):
Logger.log("i", "Updating firmware of %s using %s", self._serial_port, file_name)
self._firmware_file_name = file_name
self._update_firmware_thread.start()
## Private connect function run by thread. Can be started by calling connect.
def _connect(self):
def _connect(self):
Logger.log("d", "Attempting to connect to %s", self._serial_port)
self._is_connecting = True
programmer = stk500v2.Stk500v2()
try:
@ -174,8 +182,9 @@ class PrinterConnection(SignalEmitter):
except Exception as e:
Logger.log("i", "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
if not self._serial or not programmer.serial:
if not self._serial:
self._is_connecting = False
Logger.log("i", "Could not establish connection on %s, unknown reasons.", self._serial_port)
return
# If the programmer connected, we know its an atmega based version. Not all that usefull, but it does give some debugging information.
@ -229,13 +238,14 @@ class PrinterConnection(SignalEmitter):
self.connectionStateChanged.emit(self._serial_port)
if self._is_connected:
self._listen_thread.start() #Start listening
'''Application.getInstance().addOutputDevice(self._serial_port, {
"id": self._serial_port,
"function": self.printGCode,
"description": "Print with USB {0}".format(self._serial_port),
"icon": "print_usb",
"priority": 1
})'''
#Application.getInstance().addOutputDevice(self._serial_port, {
#"id": self._serial_port,
#"function": self.printGCode,
#"shortDescription": "Print with USB",
#"description": "Print with USB {0}".format(self._serial_port),
#"icon": "save",
#"priority": 1
#})
else:
Logger.log("w", "Printer connection state was not changed")
@ -268,6 +278,7 @@ class PrinterConnection(SignalEmitter):
def _sendCommand(self, cmd):
if self._serial is None:
return
if "M109" in cmd or "M190" in cmd:
self._heatup_wait_start_time = time.time()
if "M104" in cmd or "M109" in cmd:
@ -367,6 +378,7 @@ class PrinterConnection(SignalEmitter):
if b"Extruder switched off" in line or b"Temperature heated bed switched off" in line or b"Something is wrong, please turn off the printer." in line:
if not self.hasError():
self._setErrorState(line[6:])
elif b" T:" in line or line.startswith(b"T:"): #Temperature message
try:
self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1)))
@ -420,7 +432,7 @@ class PrinterConnection(SignalEmitter):
if self._gcode_position == 100:
self._print_start_time_100 = time.time()
line = self._gcode[self._gcode_position]
if ";" in line:
line = line[:line.find(";")]
line = line.strip()
@ -446,7 +458,7 @@ class PrinterConnection(SignalEmitter):
## Set the progress of the print.
# It will be normalized (based on max_progress) to range 0 - 100
def setProgress(self, progress, max_progress = 100):
self._progress = progress / max_progress * 100 #Convert to scale of 0-100
self._progress = (progress / max_progress) * 100 #Convert to scale of 0-100
self.progressChanged.emit(self._progress, self._serial_port)
## Cancel the current print. Printer connection wil continue to listen.

View file

@ -7,16 +7,21 @@ from UM.Application import Application
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Scene.SceneNode import SceneNode
from UM.Resources import Resources
from UM.Logger import Logger
from UM.PluginRegistry import PluginRegistry
import threading
import platform
import glob
import time
import os
import os.path
import sys
from UM.Extension import Extension
from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtProperty, pyqtSignal
from PyQt5.QtQml import QQmlComponent, QQmlContext
from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtProperty, pyqtSignal, Qt
from UM.i18n import i18nCatalog
i18n_catalog = i18nCatalog("cura")
@ -42,7 +47,7 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
self.setMenuName("Firmware")
self.addMenuItem(i18n_catalog.i18n("Update Firmware"), self.updateAllFirmware)
pyqtError = pyqtSignal(str, arguments = ["amount"])
pyqtError = pyqtSignal(str, arguments = ["error"])
processingProgress = pyqtSignal(float, arguments = ["amount"])
pyqtExtruderTemperature = pyqtSignal(float, arguments = ["amount"])
pyqtBedTemperature = pyqtSignal(float, arguments = ["amount"])
@ -51,18 +56,27 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
# This will create the view if its not already created.
def spawnFirmwareInterface(self, serial_port):
if self._firmware_view is None:
self._firmware_view = QQuickView()
self._firmware_view.engine().rootContext().setContextProperty("manager",self)
self._firmware_view.setSource(QUrl("plugins/USBPrinting/FirmwareUpdateWindow.qml"))
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "FirmwareUpdateWindow.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._firmware_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._firmware_context.setContextProperty("manager", self)
self._firmware_view = component.create(self._firmware_context)
self._firmware_view.show()
## Show control interface.
# This will create the view if its not already created.
def spawnControlInterface(self,serial_port):
if self._control_view is None:
self._control_view = QQuickView()
self._control_view.engine().rootContext().setContextProperty("manager",self)
self._control_view.setSource(QUrl("plugins/USBPrinting/ControlWindow.qml"))
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._control_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._control_context.setContextProperty("manager", self)
self._control_view = component.create(self._control_context)
self._control_view.show()
@pyqtProperty(float,notify = processingProgress)
@ -112,7 +126,10 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
def updateAllFirmware(self):
self.spawnFirmwareInterface("")
for printer_connection in self._printer_connections:
printer_connection.updateFirmware(Resources.getPath(Resources.FirmwareLocation, self._getDefaultFirmwareName()))
try:
printer_connection.updateFirmware(Resources.getPath(Resources.FirmwareLocation, self._getDefaultFirmwareName()))
except FileNotFoundError:
continue
def updateFirmwareBySerial(self, serial_port):
printer_connection = self.getConnectionByPort(serial_port)
@ -158,8 +175,8 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
## Callback for error
def onError(self, error):
self._error_message = error
self.pyqtError.emit(error)
self._error_message = error if type(error) is str else error.decode("utf-8")
self.pyqtError.emit(self._error_message)
## Callback for progress change
def onProgress(self, progress, serial_port):
@ -224,8 +241,9 @@ class USBPrinterManager(QObject, SignalEmitter, Extension):
Application.getInstance().addOutputDevice(serial_port, {
"id": serial_port,
"function": self.spawnControlInterface,
"description": "Write to USB {0}".format(serial_port),
"icon": "print_usb",
"description": "Print with USB {0}".format(serial_port),
"shortDescription": "Print with USB",
"icon": "save",
"priority": 1
})
else: