Convert doxygen to rst for UM3NetworkPrinting

This commit is contained in:
Nino van Hooff 2020-05-15 15:05:38 +02:00
parent de82406782
commit 5eb5ffd916
38 changed files with 797 additions and 487 deletions

View file

@ -16,8 +16,9 @@ from cura.CuraApplication import CuraApplication
I18N_CATALOG = i18nCatalog("cura")
## This class is responsible for choosing the formats used by the connected clusters.
class MeshFormatHandler:
"""This class is responsible for choosing the formats used by the connected clusters."""
def __init__(self, file_handler: Optional[FileHandler], firmware_version: str) -> None:
self._file_handler = file_handler or CuraApplication.getInstance().getMeshFileHandler()
@ -28,42 +29,50 @@ class MeshFormatHandler:
def is_valid(self) -> bool:
return bool(self._writer)
## Chooses the preferred file format.
# \return A dict with the file format details, with the following keys:
# {id: str, extension: str, description: str, mime_type: str, mode: int, hide_in_file_dialog: bool}
@property
def preferred_format(self) -> Dict[str, Union[str, int, bool]]:
"""Chooses the preferred file format.
:return: A dict with the file format details, with the following keys:
{id: str, extension: str, description: str, mime_type: str, mode: int, hide_in_file_dialog: bool}
"""
return self._preferred_format
## Gets the file writer for the given file handler and mime type.
# \return A file writer.
@property
def writer(self) -> Optional[FileWriter]:
"""Gets the file writer for the given file handler and mime type.
:return: A file writer.
"""
return self._writer
@property
def mime_type(self) -> str:
return cast(str, self._preferred_format["mime_type"])
## Gets the file mode (FileWriter.OutputMode.TextMode or FileWriter.OutputMode.BinaryMode)
@property
def file_mode(self) -> int:
"""Gets the file mode (FileWriter.OutputMode.TextMode or FileWriter.OutputMode.BinaryMode)"""
return cast(int, self._preferred_format["mode"])
## Gets the file extension
@property
def file_extension(self) -> str:
"""Gets the file extension"""
return cast(str, self._preferred_format["extension"])
## Creates the right kind of stream based on the preferred format.
def createStream(self) -> Union[io.BytesIO, io.StringIO]:
"""Creates the right kind of stream based on the preferred format."""
if self.file_mode == FileWriter.OutputMode.TextMode:
return io.StringIO()
else:
return io.BytesIO()
## Writes the mesh and returns its value.
def getBytes(self, nodes: List[SceneNode]) -> bytes:
"""Writes the mesh and returns its value."""
if self.writer is None:
raise ValueError("There is no writer for the mesh format handler.")
stream = self.createStream()
@ -73,10 +82,12 @@ class MeshFormatHandler:
value = value.encode()
return value
## Chooses the preferred file format for the given file handler.
# \param firmware_version: The version of the firmware.
# \return A dict with the file format details.
def _getPreferredFormat(self, firmware_version: str) -> Dict[str, Union[str, int, bool]]:
"""Chooses the preferred file format for the given file handler.
:param firmware_version: The version of the firmware.
:return: A dict with the file format details.
"""
# Formats supported by this application (file types that we can actually write).
application = CuraApplication.getInstance()
@ -108,9 +119,11 @@ class MeshFormatHandler:
)
return file_formats[0]
## Gets the file writer for the given file handler and mime type.
# \param mime_type: The mine type.
# \return A file writer.
def _getWriter(self, mime_type: str) -> Optional[FileWriter]:
"""Gets the file writer for the given file handler and mime type.
:param mime_type: The mine type.
:return: A file writer.
"""
# Just take the first file format available.
return self._file_handler.getWriterByMimeType(mime_type)