Expose approximateMaterialDiameter of the definition

This way we can request that from QML.

Contributes to issue CURA-2822.
This commit is contained in:
Ghostkeeper 2017-06-22 11:17:34 +02:00
parent 503aa00137
commit fc96dfec4e
No known key found for this signature in database
GPG Key ID: C5F96EE2BC0F7E75
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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"),