Show material cost in Job Specs area...

...if weight/price information is available
This commit is contained in:
fieldOfView 2016-12-13 16:22:29 +01:00
parent 27cf300ba6
commit a83c397d69
2 changed files with 67 additions and 12 deletions

View file

@ -12,6 +12,7 @@ import cura.Settings.ExtruderManager
import math
import os.path
import unicodedata
import json
## A class for processing and calculating minimum, current and maximum print time as well as managing the job name
#
@ -48,6 +49,7 @@ class PrintInformation(QObject):
self._material_lengths = []
self._material_weights = []
self._material_costs = []
self._backend = Application.getInstance().getBackend()
if self._backend:
@ -77,6 +79,12 @@ class PrintInformation(QObject):
def materialWeights(self):
return self._material_weights
materialCostsChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify = materialCostsChanged)
def materialCosts(self):
return self._material_costs
def _onPrintDurationMessage(self, total_time, material_amounts):
self._current_print_time.setDuration(total_time)
self.currentPrintTimeChanged.emit()
@ -85,20 +93,40 @@ class PrintInformation(QObject):
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
self._material_lengths = []
self._material_weights = []
self._material_costs = []
material_preference_values = json.loads(Preferences.getInstance().getValue("cura/material_settings"))
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.
material = None
if extruder_stacks: # Multi extrusion machine
extruder_stack = [extruder for extruder in extruder_stacks if extruder.getMetaDataEntry("position") == str(index)][0]
density = extruder_stack.getMetaDataEntry("properties", {}).get("density", 0)
material = extruder_stack.findContainer({"type": "material"})
else: # Machine with no extruder stacks
density = Application.getInstance().getGlobalContainerStack().getMetaDataEntry("properties", {}).get("density", 0)
material = Application.getInstance().getGlobalContainerStack().findContainer({"type": "material"})
self._material_weights.append(float(amount) * float(density) / 1000)
weight = float(amount) * float(density) / 1000
cost = 0
if material:
material_guid = material.getMetaDataEntry("GUID")
if material_guid in material_preference_values:
weight_per_spool = float(material_preference_values[material_guid]["spool_weight"])
cost_per_spool = float(material_preference_values[material_guid]["spool_cost"])
cost = cost_per_spool * weight / weight_per_spool
self._material_weights.append(weight)
self._material_lengths.append(round((amount / (math.pi * r ** 2)) / 1000, 2))
self._material_costs.append(cost)
self.materialLengthsChanged.emit()
self.materialWeightsChanged.emit()
self.materialCostsChanged.emit()
@pyqtSlot(str)
def setJobName(self, name):

View file

@ -26,6 +26,7 @@ Rectangle {
property variant printDuration: PrintInformation.currentPrintTime
property variant printMaterialLengths: PrintInformation.materialLengths
property variant printMaterialWeights: PrintInformation.materialWeights
property variant printMaterialCosts: PrintInformation.materialCosts
height: childrenRect.height
color: "transparent"
@ -133,7 +134,8 @@ Rectangle {
}
}
Label{
Label
{
id: boundingSpec
anchors.top: jobNameRow.bottom
anchors.right: parent.right
@ -144,17 +146,20 @@ Rectangle {
text: Printer.getSceneBoundingBoxString
}
Rectangle {
Rectangle
{
id: specsRow
anchors.top: boundingSpec.bottom
anchors.right: parent.right
height: UM.Theme.getSize("jobspecs_line").height
Item{
Item
{
width: parent.width
height: parent.height
UM.RecolorImage {
UM.RecolorImage
{
id: timeIcon
anchors.right: timeSpec.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
@ -166,7 +171,8 @@ Rectangle {
color: UM.Theme.getColor("text_subtext")
source: UM.Theme.getIcon("print_time")
}
Label{
Label
{
id: timeSpec
anchors.right: lengthIcon.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
@ -175,7 +181,8 @@ Rectangle {
color: UM.Theme.getColor("text_subtext")
text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
}
UM.RecolorImage {
UM.RecolorImage
{
id: lengthIcon
anchors.right: lengthSpec.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
@ -187,7 +194,8 @@ Rectangle {
color: UM.Theme.getColor("text_subtext")
source: UM.Theme.getIcon("category_material")
}
Label{
Label
{
id: lengthSpec
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
@ -197,21 +205,40 @@ Rectangle {
{
var lengths = [];
var weights = [];
var costs = [];
var someCostsKnown = false;
if(base.printMaterialLengths) {
for(var index = 0; index < base.printMaterialLengths.length; index++) {
if(base.printMaterialLengths[index] > 0) {
for(var index = 0; index < base.printMaterialLengths.length; index++)
{
if(base.printMaterialLengths[index] > 0)
{
lengths.push(base.printMaterialLengths[index].toFixed(2));
weights.push(String(Math.floor(base.printMaterialWeights[index])));
costs.push(base.printMaterialCosts[index].toFixed(2));
if(base.printMaterialCosts[index] > 0)
{
someCostsKnown = true;
}
}
}
if(lengths.length == 0) {
}
if(lengths.length == 0)
{
lengths = ["0.00"];
weights = ["0"];
costs = ["0.00"];
}
if(someCostsKnown)
{
return catalog.i18nc("@label", "%1 m / ~ %2 g / ~ %4 %3").arg(lengths.join(" + "))
.arg(weights.join(" + ")).arg(costs.join(" + ")).arg(UM.Preferences.getValue("cura/currency"));
}
else
{
return catalog.i18nc("@label", "%1 m / ~ %2 g").arg(lengths.join(" + ")).arg(weights.join(" + "));
}
}
}
}
}
}