This commit is contained in:
fieldOfView 2016-07-29 17:36:20 +02:00
commit a1885fc4fe
3 changed files with 54 additions and 43 deletions

View File

@ -42,7 +42,8 @@ class CuraEngineBackend(Backend):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# Find out where the engine is located, and how it is called. This depends on how Cura is packaged and which OS we are running on. # Find out where the engine is located, and how it is called.
# This depends on how Cura is packaged and which OS we are running on.
default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine") default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine")
if hasattr(sys, "frozen"): if hasattr(sys, "frozen"):
default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine") default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine")
@ -121,7 +122,8 @@ class CuraEngineBackend(Backend):
json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json") json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""] return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""]
## Emitted when we get a message containing print duration and material amount. This also implies the slicing has finished. ## Emitted when we get a message containing print duration and material amount.
# This also implies the slicing has finished.
# \param time The amount of time the print will take. # \param time The amount of time the print will take.
# \param material_amount The amount of material the print will use. # \param material_amount The amount of material the print will use.
printDurationMessage = Signal() printDurationMessage = Signal()
@ -206,7 +208,7 @@ class CuraEngineBackend(Backend):
if job.getResult() == StartSliceJob.StartJobResult.SettingError: if job.getResult() == StartSliceJob.StartJobResult.SettingError:
if Application.getInstance().getPlatformActivity: if Application.getInstance().getPlatformActivity:
self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."), lifetime = 10) self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. Please check your setting values for errors."))
self._error_message.show() self._error_message.show()
self.backendStateChange.emit(BackendState.Error) self.backendStateChange.emit(BackendState.Error)
else: else:
@ -215,7 +217,7 @@ class CuraEngineBackend(Backend):
if job.getResult() == StartSliceJob.StartJobResult.NothingToSlice: if job.getResult() == StartSliceJob.StartJobResult.NothingToSlice:
if Application.getInstance().getPlatformActivity: if Application.getInstance().getPlatformActivity:
self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. No suitable objects found."), lifetime = 10) self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice. No suitable objects found."))
self._error_message.show() self._error_message.show()
self.backendStateChange.emit(BackendState.Error) self.backendStateChange.emit(BackendState.Error)
else: else:
@ -318,7 +320,7 @@ class CuraEngineBackend(Backend):
## Called when a print time message is received from the engine. ## Called when a print time message is received from the engine.
# #
# \param message The protobuf message containing the print time and # \param message The protobuff message containing the print time and
# material amount per extruder # material amount per extruder
def _onPrintTimeMaterialEstimates(self, message): def _onPrintTimeMaterialEstimates(self, message):
material_amounts = [] material_amounts = []

View File

@ -56,10 +56,9 @@ class ProcessSlicedLayersJob(Job):
## Remove old layer data (if any) ## Remove old layer data (if any)
for node in DepthFirstIterator(self._scene.getRoot()): for node in DepthFirstIterator(self._scene.getRoot()):
if type(node) is SceneNode and node.getMeshData():
if node.callDecoration("getLayerData"): if node.callDecoration("getLayerData"):
self._scene.getRoot().removeChild(node) node.getParent().removeChild(node)
Job.yieldThread() break
if self._abort_requested: if self._abort_requested:
if self._progress: if self._progress:
self._progress.hide() self._progress.hide()
@ -74,7 +73,7 @@ class ProcessSlicedLayersJob(Job):
# instead simply offset all other layers so the lowest layer is always 0. # instead simply offset all other layers so the lowest layer is always 0.
min_layer_number = 0 min_layer_number = 0
for layer in self._layers: for layer in self._layers:
if(layer.id < min_layer_number): if layer.id < min_layer_number:
min_layer_number = layer.id min_layer_number = layer.id
current_layer = 0 current_layer = 0
@ -117,7 +116,6 @@ class ProcessSlicedLayersJob(Job):
new_points[:, 1] = points[:, 2] new_points[:, 1] = points[:, 2]
new_points[:, 2] = -points[:, 1] new_points[:, 2] = -points[:, 1]
this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths) this_poly = LayerPolygon.LayerPolygon(layer_data, extruder, line_types, new_points, line_widths)
this_poly.buildCache() this_poly.buildCache()
@ -185,4 +183,3 @@ class ProcessSlicedLayersJob(Job):
else: else:
if self._progress: if self._progress:
self._progress.hide() self._progress.hide()

View File

@ -25,6 +25,7 @@ class StartJobResult(IntEnum):
SettingError = 3 SettingError = 3
NothingToSlice = 4 NothingToSlice = 4
## Formatter class that handles token expansion in start/end gcod ## Formatter class that handles token expansion in start/end gcod
class GcodeStartEndFormatter(Formatter): class GcodeStartEndFormatter(Formatter):
def get_value(self, key, args, kwargs): # [CodeStyle: get_value is an overridden function from the Formatter class] def get_value(self, key, args, kwargs): # [CodeStyle: get_value is an overridden function from the Formatter class]
@ -38,6 +39,7 @@ class GcodeStartEndFormatter(Formatter):
Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end gcode", key) Logger.log("w", "Incorrectly formatted placeholder '%s' in start/end gcode", key)
return "{" + str(key) + "}" return "{" + str(key) + "}"
## Job class that builds up the message of scene data to send to CuraEngine. ## Job class that builds up the message of scene data to send to CuraEngine.
class StartSliceJob(Job): class StartSliceJob(Job):
def __init__(self, slice_message): def __init__(self, slice_message):
@ -124,6 +126,9 @@ class StartSliceJob(Job):
if temp_list: if temp_list:
object_groups.append(temp_list) object_groups.append(temp_list)
# There are cases when there is nothing to slice. This can happen due to one at a time slicing not being
# able to find a possible sequence or because there are no objects on the build plate (or they are outside
# the build volume)
if not object_groups: if not object_groups:
self.setResult(StartJobResult.NothingToSlice) self.setResult(StartJobResult.NothingToSlice)
return return
@ -172,6 +177,7 @@ class StartSliceJob(Job):
Logger.logException("w", "Unable to do token replacement on start/end gcode") Logger.logException("w", "Unable to do token replacement on start/end gcode")
return str(value).encode("utf-8") return str(value).encode("utf-8")
## Create extruder message from stack
def _buildExtruderMessage(self, stack): def _buildExtruderMessage(self, stack):
message = self._slice_message.addRepeatedMessage("extruders") message = self._slice_message.addRepeatedMessage("extruders")
message.id = int(stack.getMetaDataEntry("position")) message.id = int(stack.getMetaDataEntry("position"))
@ -210,6 +216,9 @@ class StartSliceJob(Job):
else: else:
setting_message.value = str(value).encode("utf-8") setting_message.value = str(value).encode("utf-8")
## Check if a node has per object settings and ensure that they are set correctly in the message
# \param node \type{SceneNode} Node to check.
# \param message object_lists message to put the per object settings in
def _handlePerObjectSettings(self, node, message): def _handlePerObjectSettings(self, node, message):
stack = node.callDecoration("getStack") stack = node.callDecoration("getStack")
# Check if the node has a stack attached to it and the stack has any settings in the top container. # Check if the node has a stack attached to it and the stack has any settings in the top container.
@ -231,6 +240,9 @@ class StartSliceJob(Job):
setting.value = str(stack.getProperty(key, "value")).encode("utf-8") setting.value = str(stack.getProperty(key, "value")).encode("utf-8")
Job.yieldThread() Job.yieldThread()
## Recursive function to put all settings that require eachother for value changes in a list
# \param relations_set \type{set} Set of keys (strings) of settings that are influenced
# \param relations list of relation objects that need to be checked.
def _addRelations(self, relations_set, relations): def _addRelations(self, relations_set, relations):
for relation in filter(lambda r: r.role == "value", relations): for relation in filter(lambda r: r.role == "value", relations):
if relation.type == RelationType.RequiresTarget: if relation.type == RelationType.RequiresTarget: