Convert doxygen to rst for CuraEngineBackend

This commit is contained in:
Nino van Hooff 2020-05-08 15:23:51 +02:00
parent 8f3827d5ae
commit 797d6ed438
3 changed files with 220 additions and 143 deletions

View file

@ -40,8 +40,9 @@ class StartJobResult(IntEnum):
ObjectsWithDisabledExtruder = 8
## Formatter class that handles token expansion in start/end gcode
class GcodeStartEndFormatter(Formatter):
"""Formatter class that handles token expansion in start/end gcode"""
def __init__(self, default_extruder_nr: int = -1) -> None:
super().__init__()
self._default_extruder_nr = default_extruder_nr
@ -82,8 +83,9 @@ class GcodeStartEndFormatter(Formatter):
return value
## Job class that builds up the message of scene data to send to CuraEngine.
class StartSliceJob(Job):
"""Job class that builds up the message of scene data to send to CuraEngine."""
def __init__(self, slice_message: Arcus.PythonMessage) -> None:
super().__init__()
@ -100,9 +102,11 @@ class StartSliceJob(Job):
def setBuildPlate(self, build_plate_number: int) -> None:
self._build_plate_number = build_plate_number
## Check if a stack has any errors.
## returns true if it has errors, false otherwise.
def _checkStackForErrors(self, stack: ContainerStack) -> bool:
"""Check if a stack has any errors."""
"""returns true if it has errors, false otherwise."""
if stack is None:
return False
@ -119,8 +123,9 @@ class StartSliceJob(Job):
Job.yieldThread()
return False
## Runs the job that initiates the slicing.
def run(self) -> None:
"""Runs the job that initiates the slicing."""
if self._build_plate_number is None:
self.setResult(StartJobResult.Error)
return
@ -323,14 +328,14 @@ class StartSliceJob(Job):
def setIsCancelled(self, value: bool):
self._is_cancelled = value
## Creates a dictionary of tokens to replace in g-code pieces.
#
# This indicates what should be replaced in the start and end g-codes.
# \param stack The stack to get the settings from to replace the tokens
# with.
# \return A dictionary of replacement tokens to the values they should be
# replaced with.
def _buildReplacementTokens(self, stack: ContainerStack) -> Dict[str, Any]:
"""Creates a dictionary of tokens to replace in g-code pieces.
This indicates what should be replaced in the start and end g-codes.
:param stack: The stack to get the settings from to replace the tokens with.
:return: A dictionary of replacement tokens to the values they should be replaced with.
"""
result = {}
for key in stack.getAllKeys():
value = stack.getProperty(key, "value")
@ -358,10 +363,12 @@ class StartSliceJob(Job):
extruder_nr = extruder_stack.getProperty("extruder_nr", "value")
self._all_extruders_settings[str(extruder_nr)] = self._buildReplacementTokens(extruder_stack)
## Replace setting tokens in a piece of g-code.
# \param value A piece of g-code to replace tokens in.
# \param default_extruder_nr Stack nr to use when no stack nr is specified, defaults to the global stack
def _expandGcodeTokens(self, value: str, default_extruder_nr: int = -1) -> str:
"""Replace setting tokens in a piece of g-code.
:param value: A piece of g-code to replace tokens in.
:param default_extruder_nr: Stack nr to use when no stack nr is specified, defaults to the global stack
"""
if not self._all_extruders_settings:
self._cacheAllExtruderSettings()
@ -377,8 +384,9 @@ class StartSliceJob(Job):
Logger.logException("w", "Unable to do token replacement on start/end g-code")
return str(value)
## Create extruder message from stack
def _buildExtruderMessage(self, stack: ContainerStack) -> None:
"""Create extruder message from stack"""
message = self._slice_message.addRepeatedMessage("extruders")
message.id = int(stack.getMetaDataEntry("position"))
if not self._all_extruders_settings:
@ -407,11 +415,13 @@ class StartSliceJob(Job):
setting.value = str(value).encode("utf-8")
Job.yieldThread()
## Sends all global settings to the engine.
#
# The settings are taken from the global stack. This does not include any
# per-extruder settings or per-object settings.
def _buildGlobalSettingsMessage(self, stack: ContainerStack) -> None:
"""Sends all global settings to the engine.
The settings are taken from the global stack. This does not include any
per-extruder settings or per-object settings.
"""
if not self._all_extruders_settings:
self._cacheAllExtruderSettings()
@ -445,15 +455,16 @@ class StartSliceJob(Job):
setting_message.value = str(value).encode("utf-8")
Job.yieldThread()
## Sends for some settings which extruder they should fallback to if not
# set.
#
# This is only set for settings that have the limit_to_extruder
# property.
#
# \param stack The global stack with all settings, from which to read the
# limit_to_extruder property.
def _buildGlobalInheritsStackMessage(self, stack: ContainerStack) -> None:
"""Sends for some settings which extruder they should fallback to if not set.
This is only set for settings that have the limit_to_extruder
property.
:param stack: The global stack with all settings, from which to read the
limit_to_extruder property.
"""
for key in stack.getAllKeys():
extruder_position = int(round(float(stack.getProperty(key, "limit_to_extruder"))))
if extruder_position >= 0: # Set to a specific extruder.
@ -462,10 +473,13 @@ class StartSliceJob(Job):
setting_extruder.extruder = extruder_position
Job.yieldThread()
## Check if a node has per object settings and ensure that they are set correctly in the message
# \param node Node to check.
# \param message object_lists message to put the per object settings in
def _handlePerObjectSettings(self, node: CuraSceneNode, message: Arcus.PythonMessage):
"""Check if a node has per object settings and ensure that they are set correctly in the message
:param node: Node to check.
:param message: object_lists message to put the per object settings in
"""
stack = node.callDecoration("getStack")
# Check if the node has a stack attached to it and the stack has any settings in the top container.
@ -501,10 +515,13 @@ class StartSliceJob(Job):
Job.yieldThread()
## Recursive function to put all settings that require each other for value changes in a list
# \param relations_set Set of keys of settings that are influenced
# \param relations list of relation objects that need to be checked.
def _addRelations(self, relations_set: Set[str], relations: List[SettingRelation]):
"""Recursive function to put all settings that require each other for value changes in a list
:param relations_set: Set of keys of settings that are influenced
:param relations: list of relation objects that need to be checked.
"""
for relation in filter(lambda r: r.role == "value" or r.role == "limit_to_extruder", relations):
if relation.type == RelationType.RequiresTarget:
continue