mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Show material cost in Job Specs area...
...if weight/price information is available
This commit is contained in:
parent
27cf300ba6
commit
a83c397d69
2 changed files with 67 additions and 12 deletions
|
@ -12,6 +12,7 @@ import cura.Settings.ExtruderManager
|
||||||
import math
|
import math
|
||||||
import os.path
|
import os.path
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
import json
|
||||||
|
|
||||||
## A class for processing and calculating minimum, current and maximum print time as well as managing the job name
|
## 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_lengths = []
|
||||||
self._material_weights = []
|
self._material_weights = []
|
||||||
|
self._material_costs = []
|
||||||
|
|
||||||
self._backend = Application.getInstance().getBackend()
|
self._backend = Application.getInstance().getBackend()
|
||||||
if self._backend:
|
if self._backend:
|
||||||
|
@ -77,6 +79,12 @@ class PrintInformation(QObject):
|
||||||
def materialWeights(self):
|
def materialWeights(self):
|
||||||
return self._material_weights
|
return self._material_weights
|
||||||
|
|
||||||
|
materialCostsChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtProperty("QVariantList", notify = materialCostsChanged)
|
||||||
|
def materialCosts(self):
|
||||||
|
return self._material_costs
|
||||||
|
|
||||||
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)
|
||||||
self.currentPrintTimeChanged.emit()
|
self.currentPrintTimeChanged.emit()
|
||||||
|
@ -85,20 +93,40 @@ class PrintInformation(QObject):
|
||||||
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
|
r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2
|
||||||
self._material_lengths = []
|
self._material_lengths = []
|
||||||
self._material_weights = []
|
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()))
|
extruder_stacks = list(cura.Settings.ExtruderManager.getInstance().getMachineExtruders(Application.getInstance().getGlobalContainerStack().getId()))
|
||||||
for index, amount in enumerate(material_amounts):
|
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
|
## 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.
|
# list comprehension filtering to solve this for us.
|
||||||
|
material = None
|
||||||
if extruder_stacks: # Multi extrusion machine
|
if extruder_stacks: # Multi extrusion machine
|
||||||
extruder_stack = [extruder for extruder in extruder_stacks if extruder.getMetaDataEntry("position") == str(index)][0]
|
extruder_stack = [extruder for extruder in extruder_stacks if extruder.getMetaDataEntry("position") == str(index)][0]
|
||||||
density = extruder_stack.getMetaDataEntry("properties", {}).get("density", 0)
|
density = extruder_stack.getMetaDataEntry("properties", {}).get("density", 0)
|
||||||
|
material = extruder_stack.findContainer({"type": "material"})
|
||||||
else: # Machine with no extruder stacks
|
else: # Machine with no extruder stacks
|
||||||
density = Application.getInstance().getGlobalContainerStack().getMetaDataEntry("properties", {}).get("density", 0)
|
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_lengths.append(round((amount / (math.pi * r ** 2)) / 1000, 2))
|
||||||
|
self._material_costs.append(cost)
|
||||||
|
|
||||||
self.materialLengthsChanged.emit()
|
self.materialLengthsChanged.emit()
|
||||||
self.materialWeightsChanged.emit()
|
self.materialWeightsChanged.emit()
|
||||||
|
self.materialCostsChanged.emit()
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setJobName(self, name):
|
def setJobName(self, name):
|
||||||
|
|
|
@ -26,6 +26,7 @@ Rectangle {
|
||||||
property variant printDuration: PrintInformation.currentPrintTime
|
property variant printDuration: PrintInformation.currentPrintTime
|
||||||
property variant printMaterialLengths: PrintInformation.materialLengths
|
property variant printMaterialLengths: PrintInformation.materialLengths
|
||||||
property variant printMaterialWeights: PrintInformation.materialWeights
|
property variant printMaterialWeights: PrintInformation.materialWeights
|
||||||
|
property variant printMaterialCosts: PrintInformation.materialCosts
|
||||||
|
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
@ -133,7 +134,8 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label{
|
Label
|
||||||
|
{
|
||||||
id: boundingSpec
|
id: boundingSpec
|
||||||
anchors.top: jobNameRow.bottom
|
anchors.top: jobNameRow.bottom
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
@ -144,17 +146,20 @@ Rectangle {
|
||||||
text: Printer.getSceneBoundingBoxString
|
text: Printer.getSceneBoundingBoxString
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle
|
||||||
|
{
|
||||||
id: specsRow
|
id: specsRow
|
||||||
anchors.top: boundingSpec.bottom
|
anchors.top: boundingSpec.bottom
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: UM.Theme.getSize("jobspecs_line").height
|
height: UM.Theme.getSize("jobspecs_line").height
|
||||||
|
|
||||||
Item{
|
Item
|
||||||
|
{
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
|
|
||||||
UM.RecolorImage {
|
UM.RecolorImage
|
||||||
|
{
|
||||||
id: timeIcon
|
id: timeIcon
|
||||||
anchors.right: timeSpec.left
|
anchors.right: timeSpec.left
|
||||||
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
|
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
|
||||||
|
@ -166,7 +171,8 @@ Rectangle {
|
||||||
color: UM.Theme.getColor("text_subtext")
|
color: UM.Theme.getColor("text_subtext")
|
||||||
source: UM.Theme.getIcon("print_time")
|
source: UM.Theme.getIcon("print_time")
|
||||||
}
|
}
|
||||||
Label{
|
Label
|
||||||
|
{
|
||||||
id: timeSpec
|
id: timeSpec
|
||||||
anchors.right: lengthIcon.left
|
anchors.right: lengthIcon.left
|
||||||
anchors.rightMargin: UM.Theme.getSize("default_margin").width
|
anchors.rightMargin: UM.Theme.getSize("default_margin").width
|
||||||
|
@ -175,7 +181,8 @@ Rectangle {
|
||||||
color: UM.Theme.getColor("text_subtext")
|
color: UM.Theme.getColor("text_subtext")
|
||||||
text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
|
text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
|
||||||
}
|
}
|
||||||
UM.RecolorImage {
|
UM.RecolorImage
|
||||||
|
{
|
||||||
id: lengthIcon
|
id: lengthIcon
|
||||||
anchors.right: lengthSpec.left
|
anchors.right: lengthSpec.left
|
||||||
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
|
anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
|
||||||
|
@ -187,7 +194,8 @@ Rectangle {
|
||||||
color: UM.Theme.getColor("text_subtext")
|
color: UM.Theme.getColor("text_subtext")
|
||||||
source: UM.Theme.getIcon("category_material")
|
source: UM.Theme.getIcon("category_material")
|
||||||
}
|
}
|
||||||
Label{
|
Label
|
||||||
|
{
|
||||||
id: lengthSpec
|
id: lengthSpec
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
@ -197,19 +205,38 @@ Rectangle {
|
||||||
{
|
{
|
||||||
var lengths = [];
|
var lengths = [];
|
||||||
var weights = [];
|
var weights = [];
|
||||||
|
var costs = [];
|
||||||
|
var someCostsKnown = false;
|
||||||
if(base.printMaterialLengths) {
|
if(base.printMaterialLengths) {
|
||||||
for(var index = 0; index < base.printMaterialLengths.length; index++) {
|
for(var index = 0; index < base.printMaterialLengths.length; index++)
|
||||||
if(base.printMaterialLengths[index] > 0) {
|
{
|
||||||
|
if(base.printMaterialLengths[index] > 0)
|
||||||
|
{
|
||||||
lengths.push(base.printMaterialLengths[index].toFixed(2));
|
lengths.push(base.printMaterialLengths[index].toFixed(2));
|
||||||
weights.push(String(Math.floor(base.printMaterialWeights[index])));
|
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"];
|
lengths = ["0.00"];
|
||||||
weights = ["0"];
|
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(" + "));
|
||||||
}
|
}
|
||||||
return catalog.i18nc("@label", "%1 m / ~ %2 g").arg(lengths.join(" + ")).arg(weights.join(" + "));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue