From 7f6a39d7d01a285e4b1631e51687f09f8d08bb37 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Fri, 20 Mar 2020 09:26:31 +0100 Subject: [PATCH 1/4] Fix loading comments in gcode snippets from 3mf projects Fixes #7304 --- plugins/3MFReader/ThreeMFWorkspaceReader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index be90f02d37..82b73c66d9 100755 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -285,13 +285,13 @@ class ThreeMFWorkspaceReader(WorkspaceReader): serialized = archive.open(instance_container_file_name).read().decode("utf-8") # Qualities and variants don't have upgrades, so don't upgrade them - parser = ConfigParser(interpolation = None) + parser = ConfigParser(interpolation = None, comment_prefixes = ()) parser.read_string(serialized) container_type = parser["metadata"]["type"] if container_type not in ("quality", "variant"): serialized = InstanceContainer._updateSerialized(serialized, instance_container_file_name) - parser = ConfigParser(interpolation = None) + parser = ConfigParser(interpolation = None, comment_prefixes = ()) parser.read_string(serialized) container_info = ContainerInfo(instance_container_file_name, serialized, parser) instance_container_info_dict[container_id] = container_info From 65336d84e5f515b5556a1b81184b097e9c7cbd63 Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Fri, 20 Mar 2020 10:56:10 +0100 Subject: [PATCH 2/4] Add pytest to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index ceed4be52f..b13e160868 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ pycollada==0.6 pycparser==2.19 pyparsing==2.4.2 pyserial==3.4 +pytest python-dateutil==2.8.0 python-utils==2.3.0 requests==2.22.0 From decf96e99e8139de896b323a0146e514a44ff707 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 20 Mar 2020 11:04:24 +0100 Subject: [PATCH 3/4] Set verticalAlignment of numericTextField Contributes to #7300 --- resources/qml/MachineSettings/NumericTextFieldWithUnit.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index 9898fb2c6b..1e6dc984b2 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -78,7 +78,7 @@ UM.TooltipArea id: textFieldWithUnit anchors.left: fieldLabel.right anchors.leftMargin: UM.Theme.getSize("default_margin").width - + verticalAlignment: Text.AlignVCenter width: numericTextFieldWithUnit.controlWidth height: numericTextFieldWithUnit.controlHeight From c7e6553dbfb5cdcfbe0ba0e7b263d64062fe0952 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 Mar 2020 11:16:08 +0100 Subject: [PATCH 4/4] 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. --- cura/Arranging/Arrange.py | 4 +-- .../MachineSettingsExtruderTab.qml | 4 +-- .../MachineSettingsPrinterTab.qml | 14 ++++------ resources/definitions/fdmprinter.def.json | 4 +++ .../NumericTextFieldWithUnit.qml | 28 +++++++++++++------ .../PrintHeadMinMaxTextField.qml | 7 ----- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/cura/Arranging/Arrange.py b/cura/Arranging/Arrange.py index a99e747c48..375d2462ff 100644 --- a/cura/Arranging/Arrange.py +++ b/cura/Arranging/Arrange.py @@ -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 @@ -30,7 +30,7 @@ LocationSuggestion = namedtuple("LocationSuggestion", ["x", "y", "penalty_points class Arrange: build_volume = None # type: Optional[BuildVolume] - def __init__(self, x, y, offset_x, offset_y, scale= 0.5): + def __init__(self, x, y, offset_x, offset_y, scale = 0.5): self._scale = scale # convert input coordinates to arrange coordinates world_x, world_y = int(x * self._scale), int(y * self._scale) self._shape = (world_y, world_x) diff --git a/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml b/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml index 2ceabf87d0..902388b669 100644 --- a/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsExtruderTab.qml @@ -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 } diff --git a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml index 3780d6447b..88f73a86f8 100644 --- a/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml +++ b/plugins/MachineSettingsAction/MachineSettingsPrinterTab.qml @@ -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 } diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index 80287a1b19..fc9c0ac613 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -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 diff --git a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml index 1e6dc984b2..46e9031d1d 100644 --- a/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml +++ b/resources/qml/MachineSettings/NumericTextFieldWithUnit.qml @@ -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 diff --git a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml index 1bbdb3c5c5..222f48b280 100644 --- a/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml +++ b/resources/qml/MachineSettings/PrintHeadMinMaxTextField.qml @@ -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