Add typing for lists that it can't auto-detect

Contributes to issue CURA-6739.
This commit is contained in:
Ghostkeeper 2019-08-29 16:22:18 +02:00
parent 5f94657d2c
commit b734d34af3
No known key found for this signature in database
GPG Key ID: 86BEF881AE2CF276

View File

@ -3,7 +3,7 @@
# The _toMeshData function is taken from the AMFReader class which was built by fieldOfView. # The _toMeshData function is taken from the AMFReader class which was built by fieldOfView.
from typing import List, Union, TYPE_CHECKING from typing import Any, List, Union, TYPE_CHECKING
import numpy # To create the mesh data. import numpy # To create the mesh data.
import os.path # To create the mesh name for the resulting mesh. import os.path # To create the mesh name for the resulting mesh.
import trimesh # To load the files into a Trimesh. import trimesh # To load the files into a Trimesh.
@ -85,14 +85,14 @@ class TrimeshReader(MeshReader):
# \return A scene node that contains the file's contents. # \return A scene node that contains the file's contents.
def _read(self, file_name: str) -> Union["SceneNode", List["SceneNode"]]: def _read(self, file_name: str) -> Union["SceneNode", List["SceneNode"]]:
mesh_or_scene = trimesh.load(file_name) mesh_or_scene = trimesh.load(file_name)
meshes = [] meshes = [] # type: List[Union[trimesh.Trimesh, trimesh.Scene, Any]]
if isinstance(mesh_or_scene, trimesh.Trimesh): if isinstance(mesh_or_scene, trimesh.Trimesh):
meshes = [mesh_or_scene] meshes = [mesh_or_scene]
elif isinstance(mesh_or_scene, trimesh.Scene): elif isinstance(mesh_or_scene, trimesh.Scene):
meshes = [mesh for mesh in mesh_or_scene.geometry.values()] meshes = [mesh for mesh in mesh_or_scene.geometry.values()]
active_build_plate = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate active_build_plate = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
nodes = [] nodes = [] # type: List[SceneNode]
for mesh in meshes: for mesh in meshes:
if not isinstance(mesh, trimesh.Trimesh): # Trimesh can also receive point clouds, 2D paths, 3D paths or metadata. Skip those. if not isinstance(mesh, trimesh.Trimesh): # Trimesh can also receive point clouds, 2D paths, 3D paths or metadata. Skip those.
continue continue