mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Store cost & weight as preference values independent of material definition
Users need to be able to set these values independent of the xml definition, as it is not a material property but something that depends on the reseller etc. It must also be settable for read-only materials.
This commit is contained in:
parent
8ee6b89a56
commit
7516fb6056
3 changed files with 65 additions and 28 deletions
|
@ -217,6 +217,10 @@ class CuraApplication(QtApplication):
|
|||
Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True)
|
||||
Preferences.getInstance().addPreference("cura/dialog_on_project_save", True)
|
||||
Preferences.getInstance().addPreference("cura/asked_dialog_on_project_save", False)
|
||||
|
||||
Preferences.getInstance().addPreference("cura/currency", "€")
|
||||
Preferences.getInstance().addPreference("cura/material_settings", "{}")
|
||||
|
||||
for key in [
|
||||
"dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin
|
||||
"dialog_profile_path",
|
||||
|
|
|
@ -15,10 +15,11 @@ TabView
|
|||
property QtObject properties;
|
||||
|
||||
property bool editingEnabled: false;
|
||||
property string currency: UM.Preferences.getValue("general/currency") ? UM.Preferences.getValue("general/currency") : "€"
|
||||
property string currency: UM.Preferences.getValue("cura/currency") ? UM.Preferences.getValue("cura/currency") : "€"
|
||||
property real firstColumnWidth: width * 0.45
|
||||
property real secondColumnWidth: width * 0.45
|
||||
property string containerId: ""
|
||||
property var materialPreferenceValues: UM.Preferences.getValue("cura/material_settings") ? JSON.parse(UM.Preferences.getValue("cura/material_settings")) : {}
|
||||
|
||||
Tab
|
||||
{
|
||||
|
@ -112,12 +113,12 @@ TabView
|
|||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Density") }
|
||||
ReadOnlySpinBox
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: properties.density;
|
||||
width: base.secondColumnWidth
|
||||
value: properties.density
|
||||
decimals: 2
|
||||
suffix: "g/cm³"
|
||||
suffix: " g/cm³"
|
||||
stepSize: 0.01
|
||||
readOnly: !base.editingEnabled;
|
||||
readOnly: !base.editingEnabled
|
||||
|
||||
onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value)
|
||||
}
|
||||
|
@ -125,12 +126,12 @@ TabView
|
|||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Diameter") }
|
||||
ReadOnlySpinBox
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: properties.diameter;
|
||||
width: base.secondColumnWidth
|
||||
value: properties.diameter
|
||||
decimals: 2
|
||||
suffix: "mm"
|
||||
suffix: " mm"
|
||||
stepSize: 0.01
|
||||
readOnly: !base.editingEnabled;
|
||||
readOnly: !base.editingEnabled
|
||||
|
||||
onEditingFinished: base.setMetaDataEntry("properties/diameter", properties.diameter, value)
|
||||
}
|
||||
|
@ -138,38 +139,42 @@ TabView
|
|||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament Cost") }
|
||||
SpinBox
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: properties.spool_cost;
|
||||
prefix: base.currency
|
||||
enabled: false
|
||||
width: base.secondColumnWidth
|
||||
value: base.getMaterialPreferenceValue(properties.guid, "spool_cost")
|
||||
prefix: base.currency + " "
|
||||
decimals: 2
|
||||
maximumValue: 1000
|
||||
onEditingFinished: base.setMaterialPreferenceValue(properties.guid, "spool_cost", parseFloat(value))
|
||||
}
|
||||
|
||||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament weight") }
|
||||
SpinBox
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: properties.spool_weight;
|
||||
suffix: "g";
|
||||
stepSize: 10
|
||||
enabled: false
|
||||
width: base.secondColumnWidth
|
||||
value: base.getMaterialPreferenceValue(properties.guid, "spool_weight")
|
||||
suffix: " g"
|
||||
stepSize: 100
|
||||
decimals: 0
|
||||
maximumValue: 10000
|
||||
onEditingFinished: base.setMaterialPreferenceValue(properties.guid, "spool_weight", parseFloat(value))
|
||||
}
|
||||
|
||||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament length") }
|
||||
SpinBox
|
||||
Label
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: parseFloat(properties.spool_length);
|
||||
suffix: "m";
|
||||
enabled: false
|
||||
width: base.secondColumnWidth
|
||||
text: "%1 m".arg(properties.spool_length)
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
height: parent.rowHeight
|
||||
}
|
||||
|
||||
Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Cost per Meter (Approx.)") }
|
||||
SpinBox
|
||||
Label
|
||||
{
|
||||
width: base.secondColumnWidth;
|
||||
value: parseFloat(properties.cost_per_meter);
|
||||
suffix: catalog.i18nc("@label", "%1/m".arg(base.currency));
|
||||
enabled: false
|
||||
width: base.secondColumnWidth
|
||||
text: "%1 %2/m".arg(parseFloat(properties.cost_per_meter).toFixed(2)).arg(base.currency)
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
height: parent.rowHeight
|
||||
}
|
||||
|
||||
Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
|
||||
|
@ -268,6 +273,32 @@ TabView
|
|||
}
|
||||
}
|
||||
|
||||
function setMaterialPreferenceValue(material_guid, entry_name, new_value)
|
||||
{
|
||||
if(!(material_guid in materialPreferenceValues))
|
||||
{
|
||||
materialPreferenceValues[material_guid] = {};
|
||||
}
|
||||
if(entry_name in materialPreferenceValues[material_guid] && materialPreferenceValues[material_guid][entry_name] == new_value)
|
||||
{
|
||||
// value has not changed
|
||||
return
|
||||
}
|
||||
materialPreferenceValues[material_guid][entry_name] = new_value;
|
||||
|
||||
// store preference
|
||||
UM.Preferences.setValue("cura/material_settings", JSON.stringify(materialPreferenceValues));
|
||||
}
|
||||
|
||||
function getMaterialPreferenceValue(material_guid, entry_name)
|
||||
{
|
||||
if(material_guid in materialPreferenceValues && entry_name in materialPreferenceValues[material_guid])
|
||||
{
|
||||
return materialPreferenceValues[material_guid][entry_name];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function setName(old_value, new_value)
|
||||
{
|
||||
if(old_value != new_value)
|
||||
|
|
|
@ -219,6 +219,7 @@ UM.ManagementPage
|
|||
{
|
||||
id: materialProperties
|
||||
|
||||
property string guid: "00000000-0000-0000-0000-000000000000"
|
||||
property string name: "Unknown";
|
||||
property string profile_type: "Unknown";
|
||||
property string supplier: "Unknown";
|
||||
|
@ -344,6 +345,7 @@ UM.ManagementPage
|
|||
return
|
||||
}
|
||||
materialProperties.name = currentItem.name;
|
||||
materialProperties.guid = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "GUID");
|
||||
|
||||
if(currentItem.metadata != undefined && currentItem.metadata != null)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue