mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Expose approximateMaterialDiameter of the definition
This way we can request that from QML. Contributes to issue CURA-2822.
This commit is contained in:
parent
503aa00137
commit
fc96dfec4e
@ -107,6 +107,21 @@ class GlobalStack(CuraContainerStack):
|
||||
def setNextStack(self, next_stack: ContainerStack) -> None:
|
||||
raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!")
|
||||
|
||||
## Gets the approximate filament diameter that the machine requires.
|
||||
#
|
||||
# The approximate material diameter is the material diameter rounded to
|
||||
# the nearest millimetre.
|
||||
#
|
||||
# If the machine has no requirement for the diameter, -1 is returned.
|
||||
#
|
||||
# \return The approximate filament diameter for the printer, as a string.
|
||||
@pyqtProperty(str)
|
||||
def approximateMaterialDiameter(self) -> str:
|
||||
material_diameter = self.definition.getMetaDataEntry("material_diameter")
|
||||
if material_diameter is None:
|
||||
return "-1"
|
||||
return str(round(float(self.definition.getMetaDataEntry("material_diameter")))) #Round, then convert back to string.
|
||||
|
||||
# protected:
|
||||
|
||||
# Determine whether or not we should try to get the "resolve" property instead of the
|
||||
|
@ -86,6 +86,28 @@ def test_addExtruder(global_stack):
|
||||
# global_stack.addExtruder(unittest.mock.MagicMock())
|
||||
assert len(global_stack.extruders) == 2 #Didn't add the faulty extruder.
|
||||
|
||||
## Tests getting the approximate material diameter.
|
||||
@pytest.mark.parametrize("diameter, approximate_diameter", [
|
||||
#Some real-life cases that are common in printers.
|
||||
(2.85, 3),
|
||||
(1.75, 2),
|
||||
(3.0, 3),
|
||||
(2.0, 2),
|
||||
#Exceptional cases.
|
||||
(0, 0),
|
||||
(-10.1, -10),
|
||||
(-1, -1)
|
||||
])
|
||||
def test_approximateMaterialDiameter(diameter, approximate_diameter, global_stack):
|
||||
global_stack.definition = DefinitionContainer(container_id = "TestDefinition")
|
||||
global_stack.definition._metadata["material_diameter"] = str(diameter)
|
||||
assert float(global_stack.approximateMaterialDiameter) == approximate_diameter
|
||||
|
||||
## Tests getting the material diameter when there is no material diameter.
|
||||
def test_approximateMaterialDiameterNoDiameter(global_stack):
|
||||
global_stack.definition = DefinitionContainer(container_id = "TestDefinition")
|
||||
assert global_stack.approximateMaterialDiameter == "-1"
|
||||
|
||||
#Tests setting user changes profiles to invalid containers.
|
||||
@pytest.mark.parametrize("container", [
|
||||
getInstanceContainer(container_type = "wrong container type"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user