diff --git a/cura/PrintInformation.py b/cura/PrintInformation.py index 52c53a34a7..6ba1274a49 100644 --- a/cura/PrintInformation.py +++ b/cura/PrintInformation.py @@ -7,6 +7,8 @@ from UM.Application import Application from UM.Qt.Duration import Duration from UM.Preferences import Preferences +import cura.Settings.ExtruderManager + import math import os.path import unicodedata @@ -44,7 +46,8 @@ class PrintInformation(QObject): self._current_print_time = Duration(None, self) - self._material_amounts = [] + self._material_lengths = [] + self._material_weights = [] self._backend = Application.getInstance().getBackend() if self._backend: @@ -62,11 +65,17 @@ class PrintInformation(QObject): def currentPrintTime(self): return self._current_print_time - materialAmountsChanged = pyqtSignal() + materialLengthsChanged = pyqtSignal() - @pyqtProperty("QVariantList", notify = materialAmountsChanged) - def materialAmounts(self): - return self._material_amounts + @pyqtProperty("QVariantList", notify = materialLengthsChanged) + def materialLengths(self): + return self._material_lengths + + materialWeightsChanged = pyqtSignal() + + @pyqtProperty("QVariantList", notify = materialWeightsChanged) + def materialWeights(self): + return self._material_weights def _onPrintDurationMessage(self, total_time, material_amounts): self._current_print_time.setDuration(total_time) @@ -74,10 +83,18 @@ class PrintInformation(QObject): # Material amount is sent as an amount of mm^3, so calculate length from that r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 - self._material_amounts = [] - for amount in material_amounts: - self._material_amounts.append(round((amount / (math.pi * r ** 2)) / 1000, 2)) - self.materialAmountsChanged.emit() + self._material_lengths = [] + self._material_weights = [] + extruder_stacks = list(cura.Settings.ExtruderManager.getInstance().getMachineExtruders(Application.getInstance().getGlobalContainerStack().getId())) + for index, amount in enumerate(material_amounts): + ## Find the right extruder stack. As the list isn't sorted because it's a annoying generator, we do some + # list comprehension filtering to solve this for us. + extruder_stack = [extruder for extruder in extruder_stacks if extruder.getMetaDataEntry("position") == str(index)][0] + density = extruder_stack.getMetaDataEntry("properties", {}).get("density", 0) + self._material_weights.append(float(amount) * float(density)) + self._material_lengths.append(round((amount / (math.pi * r ** 2)) / 1000, 2)) + self.materialLengthsChanged.emit() + self.materialWeightsChanged.emit() @pyqtSlot(str) def setJobName(self, name): diff --git a/plugins/SliceInfoPlugin/SliceInfo.py b/plugins/SliceInfoPlugin/SliceInfo.py index 39a55702ab..913ad467c5 100644 --- a/plugins/SliceInfoPlugin/SliceInfo.py +++ b/plugins/SliceInfoPlugin/SliceInfo.py @@ -59,7 +59,7 @@ class SliceInfo(Extension): material_radius = 0.5 * global_container_stack.getProperty("material_diameter", "value") # TODO: Send material per extruder instead of mashing it on a pile - material_used = math.pi * material_radius * material_radius * sum(print_information.materialAmounts) #Volume of all materials used + material_used = math.pi * material_radius * material_radius * sum(print_information.materialLengths) #Volume of all materials used # Get model information (bounding boxes, hashes and transformation matrix) models_info = [] diff --git a/resources/qml/JobSpecs.qml b/resources/qml/JobSpecs.qml index db58b5ee4e..40eb9cd250 100644 --- a/resources/qml/JobSpecs.qml +++ b/resources/qml/JobSpecs.qml @@ -24,7 +24,7 @@ Rectangle { UM.I18nCatalog { id: catalog; name:"cura"} property variant printDuration: PrintInformation.currentPrintTime - property variant printMaterialAmounts: PrintInformation.materialAmounts + property variant printMaterialAmounts: PrintInformation.materialLengths height: childrenRect.height color: "transparent"