mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Rewrite code style of _getScaleFromUnit
It should be much more readable now. Discovered while investigating #3847.
This commit is contained in:
parent
eca855c8c2
commit
0cb6e506d2
1 changed files with 20 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import os.path
|
import os.path
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
@ -168,6 +169,8 @@ class ThreeMFReader(MeshReader):
|
||||||
archive = zipfile.ZipFile(file_name, "r")
|
archive = zipfile.ZipFile(file_name, "r")
|
||||||
self._base_name = os.path.basename(file_name)
|
self._base_name = os.path.basename(file_name)
|
||||||
parser = Savitar.ThreeMFParser()
|
parser = Savitar.ThreeMFParser()
|
||||||
|
with open("/tmp/test.xml", "wb") as f:
|
||||||
|
f.write(archive.open("3D/3dmodel.model").read())
|
||||||
scene_3mf = parser.parse(archive.open("3D/3dmodel.model").read())
|
scene_3mf = parser.parse(archive.open("3D/3dmodel.model").read())
|
||||||
self._unit = scene_3mf.getUnit()
|
self._unit = scene_3mf.getUnit()
|
||||||
for node in scene_3mf.getSceneNodes():
|
for node in scene_3mf.getSceneNodes():
|
||||||
|
@ -198,9 +201,9 @@ class ThreeMFReader(MeshReader):
|
||||||
# Second step: 3MF defines the left corner of the machine as center, whereas cura uses the center of the
|
# Second step: 3MF defines the left corner of the machine as center, whereas cura uses the center of the
|
||||||
# build volume.
|
# build volume.
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
translation_vector = Vector(x=-global_container_stack.getProperty("machine_width", "value") / 2,
|
translation_vector = Vector(x = -global_container_stack.getProperty("machine_width", "value") / 2,
|
||||||
y=-global_container_stack.getProperty("machine_depth", "value") / 2,
|
y = -global_container_stack.getProperty("machine_depth", "value") / 2,
|
||||||
z=0)
|
z = 0)
|
||||||
translation_matrix = Matrix()
|
translation_matrix = Matrix()
|
||||||
translation_matrix.setByTranslation(translation_vector)
|
translation_matrix.setByTranslation(translation_vector)
|
||||||
transformation_matrix.multiply(translation_matrix)
|
transformation_matrix.multiply(translation_matrix)
|
||||||
|
@ -236,23 +239,20 @@ class ThreeMFReader(MeshReader):
|
||||||
# * inch
|
# * inch
|
||||||
# * foot
|
# * foot
|
||||||
# * meter
|
# * meter
|
||||||
def _getScaleFromUnit(self, unit):
|
def _getScaleFromUnit(self, unit: Optional[str]) -> Vector:
|
||||||
|
conversion_to_mm = {
|
||||||
|
"micron": 0.001,
|
||||||
|
"millimeter": 1,
|
||||||
|
"centimeter": 10,
|
||||||
|
"meter": 1000,
|
||||||
|
"inch": 25.4,
|
||||||
|
"foot": 304.8
|
||||||
|
}
|
||||||
if unit is None:
|
if unit is None:
|
||||||
unit = "millimeter"
|
unit = "millimeter"
|
||||||
if unit == "micron":
|
elif unit not in conversion_to_mm:
|
||||||
scale = 0.001
|
Logger.log("w", "Unrecognised unit {unit} used. Assuming mm instead.".format(unit = unit))
|
||||||
elif unit == "millimeter":
|
unit = "millimeter"
|
||||||
scale = 1
|
|
||||||
elif unit == "centimeter":
|
|
||||||
scale = 10
|
|
||||||
elif unit == "inch":
|
|
||||||
scale = 25.4
|
|
||||||
elif unit == "foot":
|
|
||||||
scale = 304.8
|
|
||||||
elif unit == "meter":
|
|
||||||
scale = 1000
|
|
||||||
else:
|
|
||||||
Logger.log("w", "Unrecognised unit %s used. Assuming mm instead", unit)
|
|
||||||
scale = 1
|
|
||||||
|
|
||||||
|
scale = conversion_to_mm[unit]
|
||||||
return Vector(scale, scale, scale)
|
return Vector(scale, scale, scale)
|
Loading…
Add table
Add a link
Reference in a new issue