CURA-4461 Read buildplate id from the printer and set the automatic

option
This commit is contained in:
Diego Prado Gesto 2018-01-11 13:03:35 +01:00
parent a2089c6afd
commit de98a62dc8
3 changed files with 50 additions and 29 deletions

View file

@ -36,6 +36,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
self._target_hotend_temperatures = [0] * self._num_extruders
self._material_ids = [""] * self._num_extruders
self._hotend_ids = [""] * self._num_extruders
self._buildplate_id = ""
self._progress = 0
self._head_x = 0
self._head_y = 0
@ -99,6 +100,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
# Signal to be emitted when either of the hotend ids is changed
hotendIdChanged = pyqtSignal(int, str, arguments = ["index", "id"])
# Signal to be emitted when the buildplate is changed
buildplateChanged = pyqtSignal()
# Signal that is emitted every time connection state is changed.
# it also sends it's own device_id (for convenience sake)
connectionStateChanged = pyqtSignal(str)
@ -495,6 +499,22 @@ class PrinterOutputDevice(QObject, OutputDevice):
self._hotend_ids[index] = None
self.hotendIdChanged.emit(index, None)
@pyqtProperty(str, notify = buildplateChanged)
def buildplateId(self):
return self._buildplate_id
## Protected setter for the current buildplate id.
# /param buildplate_id id of the buildplate
def _setBuildplateId(self, buildplate_id):
if buildplate_id and buildplate_id != self._buildplate_id:
Logger.log("d", "Setting buildplate id to %s." % (buildplate_id))
self._buildplate_id = buildplate_id
self.buildplateChanged.emit(buildplate_id)
elif not buildplate_id:
Logger.log("d", "Removing buildplate id.")
self._buildplate_id = None
self.buildplateChanged.emit(None)
## Let the user decide if the hotends and/or material should be synced with the printer
# NB: the UX needs to be implemented by the plugin
def materialHotendChangedMessage(self, callback):

View file

@ -583,6 +583,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
hotend_id = ""
self._setHotendId(index, hotend_id)
# TODO Set the buildplate id depending on the info from the printer. To be discussed...
bed_temperatures = self._json_printer_state["bed"]["temperature"]
self._setBedTemperature(bed_temperatures["current"])
self._updateTargetBedTemperature(bed_temperatures["target"])

View file

@ -12,7 +12,6 @@ Menu
id: menu
title: "Build plate"
property int extruderIndex: 0
property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0
property bool isClusterPrinter:
{
@ -29,34 +28,34 @@ Menu
return true;
}
// MenuItem
// {
// id: automaticBuildplate
// text:
// {
// if(printerConnected && Cura.MachineManager.buildplateIds.length > buildplateIndex && !isClusterPrinter)
// {
// var buildplateName = Cura.MachineManager.buildplateIds[buildplateIndex]
// return catalog.i18nc("@title:menuitem %1 is the buildplate currently loaded in the printer", "Automatic: %1").arg(buildplateName)
// }
// return ""
// }
// visible: printerConnected && Cura.MachineManager.buildplateIds.length > buildplateIndex && !isClusterPrinter
// onTriggered:
// {
// var buildplateId = Cura.MachineManager.buildplateIds[buildplateIndex]
// var itemIndex = buildplateInstantiator.model.find("name", buildplateId);
// if(itemIndex > -1)
// {
// Cura.MachineManager.setActiveVariantBuildplate(buildplateInstantiator.model.getItem(itemIndex).id);
// }
// }
// }
//
// MenuSeparator
// {
// visible: automaticBuildplate.visible
// }
MenuItem
{
id: automaticBuildplate
text:
{
if(printerConnected && Cura.MachineManager.printerOutputDevices[0].buildplateId != "" && !isClusterPrinter)
{
var buildplateName = Cura.MachineManager.printerOutputDevices[0].buildplateId
return catalog.i18nc("@title:menuitem %1 is the buildplate currently loaded in the printer", "Automatic: %1").arg(buildplateName)
}
return ""
}
visible: printerConnected && Cura.MachineManager.printerOutputDevices[0].buildplateId != "" && !isClusterPrinter
onTriggered:
{
var buildplateId = Cura.MachineManager.printerOutputDevices[0].buildplateId
var itemIndex = buildplateInstantiator.model.find("name", buildplateId)
if(itemIndex > -1)
{
Cura.MachineManager.setActiveVariantBuildplate(buildplateInstantiator.model.getItem(itemIndex).id)
}
}
}
MenuSeparator
{
visible: automaticBuildplate.visible
}
Instantiator
{