Wait for FinishedSlicing message to mark slicing as finished

Instead of waiting until progress is more than 99%, wait for the dedicated FinishedSlicing message.

Contributes to issue CURA-427.
This commit is contained in:
Ghostkeeper 2016-01-29 11:22:04 +01:00
parent c3eb810aa2
commit c53969f1bd
2 changed files with 29 additions and 20 deletions

View file

@ -9,6 +9,7 @@ from UM.Preferences import Preferences
from UM.Math.Vector import Vector from UM.Math.Vector import Vector
from UM.Signal import Signal from UM.Signal import Signal
from UM.Logger import Logger from UM.Logger import Logger
from UM.Qt.Bindings.BackendProxy import BackendState #To determine the state of the slicing job.
from UM.Resources import Resources from UM.Resources import Resources
from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator from UM.Settings.SettingOverrideDecorator import SettingOverrideDecorator
from UM.Message import Message from UM.Message import Message
@ -66,6 +67,7 @@ class CuraEngineBackend(Backend):
self._message_handlers[Cura_pb2.GCodeLayer] = self._onGCodeLayerMessage self._message_handlers[Cura_pb2.GCodeLayer] = self._onGCodeLayerMessage
self._message_handlers[Cura_pb2.GCodePrefix] = self._onGCodePrefixMessage self._message_handlers[Cura_pb2.GCodePrefix] = self._onGCodePrefixMessage
self._message_handlers[Cura_pb2.ObjectPrintTime] = self._onObjectPrintTimeMessage self._message_handlers[Cura_pb2.ObjectPrintTime] = self._onObjectPrintTimeMessage
self._message_handlers[Cura_pb2.SlicingFinished] = self._onSlicingFinishedMessage
self._slicing = False self._slicing = False
self._restart = False self._restart = False
@ -126,6 +128,7 @@ class CuraEngineBackend(Backend):
return #No slicing if we have error values since those are by definition illegal values. return #No slicing if we have error values since those are by definition illegal values.
self.processingProgress.emit(0.0) self.processingProgress.emit(0.0)
self.backendStateChange.emit(BackendState.NOT_STARTED)
if self._message: if self._message:
self._message.setProgress(-1) self._message.setProgress(-1)
#else: #else:
@ -197,15 +200,10 @@ class CuraEngineBackend(Backend):
self._message.setProgress(round(message.amount * 100)) self._message.setProgress(round(message.amount * 100))
self.processingProgress.emit(message.amount) self.processingProgress.emit(message.amount)
self.backendStateChange.emit(BackendState.PROCESSING)
def _onGCodeLayerMessage(self, message): def _onSlicingFinishedMessage(self, message):
self._scene.gcode_list.append(message.data.decode("utf-8", "replace")) self.backendStateChange.emit(BackendState.DONE)
def _onGCodePrefixMessage(self, message):
self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
def _onObjectPrintTimeMessage(self, message):
self.printDurationMessage.emit(message.time, message.material_amount)
self.processingProgress.emit(1.0) self.processingProgress.emit(1.0)
self._slicing = False self._slicing = False
@ -215,16 +213,25 @@ class CuraEngineBackend(Backend):
self._message.hide() self._message.hide()
self._message = None self._message = None
if self._always_restart: #if self._always_restart:
try: #try:
self._process.terminate() #self._process.terminate()
self._createSocket() #self._createSocket()
except: # terminating a process that is already terminating causes an exception, silently ignore this. #except: # terminating a process that is already terminating causes an exception, silently ignore this.
pass #pass
def _onGCodeLayerMessage(self, message):
self._scene.gcode_list.append(message.data.decode("utf-8", "replace"))
def _onGCodePrefixMessage(self, message):
self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
def _onObjectPrintTimeMessage(self, message):
self.printDurationMessage.emit(message.time, message.material_amount)
def _createSocket(self): def _createSocket(self):
super()._createSocket() super()._createSocket()
self._socket.registerMessageType(1, Cura_pb2.Slice) self._socket.registerMessageType(1, Cura_pb2.Slice)
self._socket.registerMessageType(2, Cura_pb2.SlicedObjectList) self._socket.registerMessageType(2, Cura_pb2.SlicedObjectList)
self._socket.registerMessageType(3, Cura_pb2.Progress) self._socket.registerMessageType(3, Cura_pb2.Progress)
@ -232,6 +239,7 @@ class CuraEngineBackend(Backend):
self._socket.registerMessageType(5, Cura_pb2.ObjectPrintTime) self._socket.registerMessageType(5, Cura_pb2.ObjectPrintTime)
self._socket.registerMessageType(6, Cura_pb2.SettingList) self._socket.registerMessageType(6, Cura_pb2.SettingList)
self._socket.registerMessageType(7, Cura_pb2.GCodePrefix) self._socket.registerMessageType(7, Cura_pb2.GCodePrefix)
self._socket.registerMessageType(8, Cura_pb2.SlicingFinished)
## Manually triggers a reslice ## Manually triggers a reslice
def forceSlice(self): def forceSlice(self):

View file

@ -13,18 +13,19 @@ Rectangle {
UM.I18nCatalog { id: catalog; name:"cura"} UM.I18nCatalog { id: catalog; name:"cura"}
property real progress: UM.Backend.progress; property real progress: UM.Backend.progress;
property int backendState: UM.Backend.state;
property bool activity: Printer.getPlatformActivity; property bool activity: Printer.getPlatformActivity;
//Behavior on progress { NumberAnimation { duration: 250; } } //Behavior on progress { NumberAnimation { duration: 250; } }
property int totalHeight: childrenRect.height + UM.Theme.sizes.default_margin.height property int totalHeight: childrenRect.height + UM.Theme.sizes.default_margin.height
property string fileBaseName property string fileBaseName
property string statusText: { property string statusText: {
if(progress == 0) { if(base.backendState == 0) {
if(!activity) { if(!activity) {
return catalog.i18nc("@label:PrintjobStatus","Please load a 3d model"); return catalog.i18nc("@label:PrintjobStatus","Please load a 3d model");
} else { } else {
return catalog.i18nc("@label:PrintjobStatus","Preparing to slice..."); return catalog.i18nc("@label:PrintjobStatus","Preparing to slice...");
} }
} else if(base.progress < 0.99) { } else if(base.backendState == 1) {
return catalog.i18nc("@label:PrintjobStatus","Slicing..."); return catalog.i18nc("@label:PrintjobStatus","Slicing...");
} else { } else {
return catalog.i18nc("@label:PrintjobStatus","Ready to ") + UM.OutputDeviceManager.activeDeviceShortDescription; return catalog.i18nc("@label:PrintjobStatus","Ready to ") + UM.OutputDeviceManager.activeDeviceShortDescription;
@ -59,7 +60,7 @@ Rectangle {
height: parent.height height: parent.height
color: UM.Theme.colors.progressbar_control color: UM.Theme.colors.progressbar_control
radius: UM.Theme.sizes.progressbar_radius.width radius: UM.Theme.sizes.progressbar_radius.width
visible: base.progress > 0.99 ? false : true visible: base.backendState == 1 ? true : false
} }
} }
@ -76,7 +77,7 @@ Rectangle {
property int resizedWidth property int resizedWidth
x: base.width - saveToButton.resizedWidth - UM.Theme.sizes.default_margin.width - UM.Theme.sizes.save_button_save_to_button.height + UM.Theme.sizes.save_button_save_to_button.width x: base.width - saveToButton.resizedWidth - UM.Theme.sizes.default_margin.width - UM.Theme.sizes.save_button_save_to_button.height + UM.Theme.sizes.save_button_save_to_button.width
tooltip: UM.OutputDeviceManager.activeDeviceDescription; tooltip: UM.OutputDeviceManager.activeDeviceDescription;
enabled: base.progress > 0.99 && base.activity == true enabled: base.backendState == 2 && base.activity == true
height: UM.Theme.sizes.save_button_save_to_button.height height: UM.Theme.sizes.save_button_save_to_button.height
width: 150 width: 150
anchors.top:parent.top anchors.top:parent.top
@ -125,7 +126,7 @@ Rectangle {
anchors.rightMargin: UM.Theme.sizes.default_margin.width anchors.rightMargin: UM.Theme.sizes.default_margin.width
width: UM.Theme.sizes.save_button_save_to_button.height width: UM.Theme.sizes.save_button_save_to_button.height
height: UM.Theme.sizes.save_button_save_to_button.height height: UM.Theme.sizes.save_button_save_to_button.height
enabled: base.progress > 0.99 && base.activity == true enabled: base.backendState == 2 && base.activity == true
//iconSource: UM.Theme.icons[UM.OutputDeviceManager.activeDeviceIconName]; //iconSource: UM.Theme.icons[UM.OutputDeviceManager.activeDeviceIconName];
style: ButtonStyle { style: ButtonStyle {