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.
This commit is contained in:
Ghostkeeper 2020-03-20 11:16:08 +01:00
parent 3f69e11d90
commit c7e6553dbf
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A
6 changed files with 34 additions and 27 deletions

View file

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import List, Optional

View file

@ -107,7 +107,7 @@ Item
labelWidth: base.labelWidth
controlWidth: base.controlWidth
unitText: catalog.i18nc("@label", "mm")
allowNegativeValue: true
minimum: Number.NEGATIVE_INFINITY
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -122,7 +122,7 @@ Item
labelWidth: base.labelWidth
controlWidth: base.controlWidth
unitText: catalog.i18nc("@label", "mm")
allowNegativeValue: true
minimum: Number.NEGATIVE_INFINITY
forceUpdateOnChangeFunction: forceUpdateFunction
}

View file

@ -72,6 +72,7 @@ Item
labelWidth: base.labelWidth
controlWidth: base.controlWidth
unitText: catalog.i18nc("@label", "mm")
maximum: 2000000
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -86,6 +87,7 @@ Item
labelWidth: base.labelWidth
controlWidth: base.controlWidth
unitText: catalog.i18nc("@label", "mm")
maximum: 2000000
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -204,8 +206,8 @@ Item
axisName: "x"
axisMinOrMax: "min"
allowNegativeValue: true
allowPositiveValue: false
minimum: Number.NEGATIVE_INFINITY
maximum: 0
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -224,8 +226,8 @@ Item
axisName: "y"
axisMinOrMax: "min"
allowNegativeValue: true
allowPositiveValue: false
minimum: Number.NEGATIVE_INFINITY
maximum: 0
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -244,8 +246,6 @@ Item
axisName: "x"
axisMinOrMax: "max"
allowNegativeValue: false
allowPositiveValue: true
forceUpdateOnChangeFunction: forceUpdateFunction
}
@ -266,8 +266,6 @@ Item
axisName: "y"
axisMinOrMax: "max"
allowNegativeValue: false
allowPositiveValue: true
forceUpdateOnChangeFunction: forceUpdateFunction
}

View file

@ -142,6 +142,8 @@
"description": "The width (X-direction) of the printable area.",
"default_value": 100,
"type": "float",
"minimum_value": "0.001",
"maximum_value": "2000000",
"settable_per_mesh": false,
"settable_per_extruder": false,
"settable_per_meshgroup": false
@ -152,6 +154,8 @@
"description": "The depth (Y-direction) of the printable area.",
"default_value": 100,
"type": "float",
"minimum_value": "0.001",
"maximum_value": "2000000",
"settable_per_mesh": false,
"settable_per_extruder": false,
"settable_per_meshgroup": false

View file

@ -37,15 +37,13 @@ UM.TooltipArea
property alias textField: textFieldWithUnit
property alias valueText: textFieldWithUnit.text
property alias valueValidator: textFieldWithUnit.validator
property alias editingFinishedFunction: textFieldWithUnit.editingFinishedFunction
property string tooltipText: propertyProvider.properties.description
// whether negative value is allowed. This affects the validation of the input field.
property bool allowNegativeValue: false
// whether positive value is allowed. This affects the validation of the input field.
property bool allowPositiveValue: true
property real minimum: 0
property real maximum: Number.POSITIVE_INFINITY
property int decimals: 6
// callback functions
property var afterOnEditingFinishedFunction: dummy_func
@ -158,12 +156,26 @@ UM.TooltipArea
}
validator: DoubleValidator
{
bottom: allowNegativeValue ? Number.NEGATIVE_INFINITY : 0
top: allowPositiveValue ? Number.POSITIVE_INFINITY : 0
decimals: 6
bottom: numericTextFieldWithUnit.minimum
top: numericTextFieldWithUnit.maximum
decimals: numericTextFieldWithUnit.decimals
notation: DoubleValidator.StandardNotation
}
//Enforce actual minimum and maximum values.
//The DoubleValidator allows intermediate values, which essentially means that the maximum gets rounded up to the nearest power of 10.
//This is not accurate at all, so here if the value exceeds the maximum or the minimum we disallow it.
property string previousText
onTextChanged:
{
var value = Number(text);
if(value < numericTextFieldWithUnit.minimum || value > numericTextFieldWithUnit.maximum)
{
text = previousText;
}
previousText = text;
}
onEditingFinished: editingFinishedFunction()
property var editingFinishedFunction: defaultEditingFinishedFunction

View file

@ -46,13 +46,6 @@ NumericTextFieldWithUnit
return result
}
valueValidator: DoubleValidator {
bottom: allowNegativeValue ? Number.NEGATIVE_INFINITY : 0
top: allowPositiveValue ? Number.POSITIVE_INFINITY : 0
decimals: 6
notation: DoubleValidator.StandardNotation
}
valueText: axisValue
Connections