Cura/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml
Ghostkeeper c7e6553dbf
Disallow printers larger than 2km
To do this, I'm giving more power to the NumericTextFieldWithUnit QML element, to allow an arbitrary minimum and maximum. Enforcing this minimum and maximum is fairly simple with a JavaScript hook. This hook is necessary because the DoubleValidator allows intermediary values which defeats the purpose, essentially allowing any number as long as it has the correct number of digits.
Printers larger than 2km would start to give overflow errors in its X and Y coordinates. Z is okay up to about 9 billion kilometres in theory, since we don't need to do any squaring math on those coordinates afaik. In practice I'm doing this because at very high values the Arranger also gives errors because Numpy can't handle those extremely big arrays (since the arranger creates a 2mm grid).

Fixes Sentry issue CURA-CB.
2020-03-20 11:16:16 +01:00

93 lines
2.9 KiB
QML

// Copyright (c) 2019 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.3 as UM
import Cura 1.1 as Cura
//
// This is the widget for editing min and max X and Y for the print head.
// The print head is internally stored as a JSON array or array, representing a polygon of the print head.
// The polygon array is stored in the format illustrated below:
// [ [ -x_min, y_max ],
// [ -x_min, -y_min ],
// [ x_max, y_max ],
// [ x_max, -y_min ],
// ]
//
// In order to modify each field, the widget is configurable via "axisName" and "axisMinOrMax", where
// - axisName is "x" or "y"
// - axisMinOrMax is "min" or "max"
//
NumericTextFieldWithUnit
{
id: printerHeadMinMaxField
UM.I18nCatalog { id: catalog; name: "cura" }
containerStackId: Cura.MachineManager.activeMachine.id
settingKey: "machine_head_with_fans_polygon"
settingStoreIndex: 1
property string axisName: "x"
property string axisMinOrMax: "min"
property var axisValue:
{
var polygon = JSON.parse(propertyProvider.properties.value)
var item = (axisName == "x") ? 0 : 1
var result = polygon[0][item]
var func = (axisMinOrMax == "min") ? Math.min : Math.max
for (var i = 1; i < polygon.length; i++)
{
result = func(result, polygon[i][item])
}
return result
}
valueText: axisValue
Connections
{
target: textField
onActiveFocusChanged:
{
// When this text field loses focus and the entered text is not valid, make sure to recreate the binding to
// show the correct value.
if (!textField.activeFocus && !textField.acceptableInput)
{
valueText = Qt.binding(function() { return printerHeadMinMaxField.axisValue })
}
}
}
editingFinishedFunction: function()
{
var polygon = JSON.parse(propertyProvider.properties.value)
var newValue = parseFloat(valueText.replace(',', '.'))
if (axisName == "x") // x min/x max
{
var start_i1 = (axisMinOrMax == "min") ? 0 : 2
polygon[start_i1][0] = newValue
polygon[start_i1 + 1][0] = newValue
}
else // y min/y max
{
var start_i1 = (axisMinOrMax == "min") ? 1 : 0
polygon[start_i1][1] = newValue
polygon[start_i1 + 2][1] = newValue
}
var polygon_string = JSON.stringify(polygon)
if (polygon_string != propertyProvider.properties.value)
{
propertyProvider.setPropertyValue("value", polygon_string)
forceUpdateOnChangeFunction()
}
// Recreate the binding to show the correct value.
valueText = Qt.binding(function() { return axisValue })
}
}