UFPReader.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import TYPE_CHECKING
  4. from Charon.VirtualFile import VirtualFile
  5. from UM.Mesh.MeshReader import MeshReader
  6. from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
  7. from UM.PluginRegistry import PluginRegistry
  8. if TYPE_CHECKING:
  9. from cura.Scene.CuraSceneNode import CuraSceneNode
  10. class UFPReader(MeshReader):
  11. def __init__(self) -> None:
  12. super().__init__()
  13. MimeTypeDatabase.addMimeType(
  14. MimeType(
  15. name = "application/x-ufp",
  16. comment = "UltiMaker Format Package",
  17. suffixes = ["ufp"]
  18. )
  19. )
  20. self._supported_extensions = [".ufp"]
  21. def _read(self, file_name: str) -> "CuraSceneNode":
  22. # Open the file
  23. archive = VirtualFile()
  24. archive.open(file_name)
  25. # Get the gcode data from the file
  26. gcode_data = archive.getData("/3D/model.gcode")
  27. # Convert the bytes stream to string
  28. gcode_stream = gcode_data["/3D/model.gcode"].decode("utf-8")
  29. # Open the GCodeReader to parse the data
  30. gcode_reader = PluginRegistry.getInstance().getPluginObject("GCodeReader") # type: ignore
  31. gcode_reader.preReadFromStream(gcode_stream) # type: ignore
  32. return gcode_reader.readFromStream(gcode_stream, file_name) # type: ignore