Both material weights & lengths are now exposed

CURA-1038
This commit is contained in:
Jaime van Kessel 2016-07-15 15:49:25 +02:00
parent d48b4bf790
commit 7a43164654
3 changed files with 28 additions and 11 deletions

View file

@ -7,6 +7,8 @@ from UM.Application import Application
from UM.Qt.Duration import Duration from UM.Qt.Duration import Duration
from UM.Preferences import Preferences from UM.Preferences import Preferences
import cura.Settings.ExtruderManager
import math import math
import os.path import os.path
import unicodedata import unicodedata
@ -44,7 +46,8 @@ class PrintInformation(QObject):
self._current_print_time = Duration(None, self) self._current_print_time = Duration(None, self)
self._material_amounts = [] self._material_lengths = []
self._material_weights = []
self._backend = Application.getInstance().getBackend() self._backend = Application.getInstance().getBackend()
if self._backend: if self._backend:
@ -62,11 +65,17 @@ class PrintInformation(QObject):
def currentPrintTime(self): def currentPrintTime(self):
return self._current_print_time return self._current_print_time
materialAmountsChanged = pyqtSignal() materialLengthsChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify = materialAmountsChanged) @pyqtProperty("QVariantList", notify = materialLengthsChanged)
def materialAmounts(self): def materialLengths(self):
return self._material_amounts return self._material_lengths
materialWeightsChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify = materialWeightsChanged)
def materialWeights(self):
return self._material_weights
def _onPrintDurationMessage(self, total_time, material_amounts): def _onPrintDurationMessage(self, total_time, material_amounts):
self._current_print_time.setDuration(total_time) 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 # Material amount is sent as an amount of mm^3, so calculate length from that
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
self._material_amounts = [] self._material_lengths = []
for amount in material_amounts: self._material_weights = []
self._material_amounts.append(round((amount / (math.pi * r ** 2)) / 1000, 2)) extruder_stacks = list(cura.Settings.ExtruderManager.getInstance().getMachineExtruders(Application.getInstance().getGlobalContainerStack().getId()))
self.materialAmountsChanged.emit() 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) @pyqtSlot(str)
def setJobName(self, name): def setJobName(self, name):

View file

@ -59,7 +59,7 @@ class SliceInfo(Extension):
material_radius = 0.5 * global_container_stack.getProperty("material_diameter", "value") material_radius = 0.5 * global_container_stack.getProperty("material_diameter", "value")
# TODO: Send material per extruder instead of mashing it on a pile # 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) # Get model information (bounding boxes, hashes and transformation matrix)
models_info = [] models_info = []

View file

@ -24,7 +24,7 @@ Rectangle {
UM.I18nCatalog { id: catalog; name:"cura"} UM.I18nCatalog { id: catalog; name:"cura"}
property variant printDuration: PrintInformation.currentPrintTime property variant printDuration: PrintInformation.currentPrintTime
property variant printMaterialAmounts: PrintInformation.materialAmounts property variant printMaterialAmounts: PrintInformation.materialLengths
height: childrenRect.height height: childrenRect.height
color: "transparent" color: "transparent"