mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
No longer use sceneLock for startSliceJob
This commit is contained in:
parent
fa3a985404
commit
ab6effb712
1 changed files with 123 additions and 124 deletions
|
@ -171,146 +171,145 @@ class StartSliceJob(Job):
|
||||||
self.setResult(StartJobResult.ObjectSettingError)
|
self.setResult(StartJobResult.ObjectSettingError)
|
||||||
return
|
return
|
||||||
|
|
||||||
with self._scene.getSceneLock():
|
# Remove old layer data.
|
||||||
# Remove old layer data.
|
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
if node.callDecoration("getLayerData") and node.callDecoration("getBuildPlateNumber") == self._build_plate_number:
|
||||||
if node.callDecoration("getLayerData") and node.callDecoration("getBuildPlateNumber") == self._build_plate_number:
|
# Singe we walk through all nodes in the scene, they always have a parent.
|
||||||
# Singe we walk through all nodes in the scene, they always have a parent.
|
cast(SceneNode, node.getParent()).removeChild(node)
|
||||||
cast(SceneNode, node.getParent()).removeChild(node)
|
break
|
||||||
break
|
|
||||||
|
|
||||||
# Get the objects in their groups to print.
|
# Get the objects in their groups to print.
|
||||||
object_groups = []
|
object_groups = []
|
||||||
if stack.getProperty("print_sequence", "value") == "one_at_a_time":
|
if stack.getProperty("print_sequence", "value") == "one_at_a_time":
|
||||||
for node in OneAtATimeIterator(self._scene.getRoot()):
|
for node in OneAtATimeIterator(self._scene.getRoot()):
|
||||||
temp_list = []
|
|
||||||
|
|
||||||
# Node can't be printed, so don't bother sending it.
|
|
||||||
if getattr(node, "_outside_buildarea", False):
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Filter on current build plate
|
|
||||||
build_plate_number = node.callDecoration("getBuildPlateNumber")
|
|
||||||
if build_plate_number is not None and build_plate_number != self._build_plate_number:
|
|
||||||
continue
|
|
||||||
|
|
||||||
children = node.getAllChildren()
|
|
||||||
children.append(node)
|
|
||||||
for child_node in children:
|
|
||||||
mesh_data = child_node.getMeshData()
|
|
||||||
if mesh_data and mesh_data.getVertices() is not None:
|
|
||||||
temp_list.append(child_node)
|
|
||||||
|
|
||||||
if temp_list:
|
|
||||||
object_groups.append(temp_list)
|
|
||||||
Job.yieldThread()
|
|
||||||
if len(object_groups) == 0:
|
|
||||||
Logger.log("w", "No objects suitable for one at a time found, or no correct order found")
|
|
||||||
else:
|
|
||||||
temp_list = []
|
temp_list = []
|
||||||
has_printing_mesh = False
|
|
||||||
for node in DepthFirstIterator(self._scene.getRoot()):
|
|
||||||
mesh_data = node.getMeshData()
|
|
||||||
if node.callDecoration("isSliceable") and mesh_data and mesh_data.getVertices() is not None:
|
|
||||||
is_non_printing_mesh = bool(node.callDecoration("isNonPrintingMesh"))
|
|
||||||
|
|
||||||
# Find a reason not to add the node
|
# Node can't be printed, so don't bother sending it.
|
||||||
if node.callDecoration("getBuildPlateNumber") != self._build_plate_number:
|
if getattr(node, "_outside_buildarea", False):
|
||||||
continue
|
continue
|
||||||
if getattr(node, "_outside_buildarea", False) and not is_non_printing_mesh:
|
|
||||||
continue
|
|
||||||
|
|
||||||
temp_list.append(node)
|
# Filter on current build plate
|
||||||
if not is_non_printing_mesh:
|
build_plate_number = node.callDecoration("getBuildPlateNumber")
|
||||||
has_printing_mesh = True
|
if build_plate_number is not None and build_plate_number != self._build_plate_number:
|
||||||
|
continue
|
||||||
|
|
||||||
Job.yieldThread()
|
children = node.getAllChildren()
|
||||||
|
children.append(node)
|
||||||
# If the list doesn't have any model with suitable settings then clean the list
|
for child_node in children:
|
||||||
# otherwise CuraEngine will crash
|
mesh_data = child_node.getMeshData()
|
||||||
if not has_printing_mesh:
|
if mesh_data and mesh_data.getVertices() is not None:
|
||||||
temp_list.clear()
|
temp_list.append(child_node)
|
||||||
|
|
||||||
if temp_list:
|
if temp_list:
|
||||||
object_groups.append(temp_list)
|
object_groups.append(temp_list)
|
||||||
|
Job.yieldThread()
|
||||||
|
if len(object_groups) == 0:
|
||||||
|
Logger.log("w", "No objects suitable for one at a time found, or no correct order found")
|
||||||
|
else:
|
||||||
|
temp_list = []
|
||||||
|
has_printing_mesh = False
|
||||||
|
for node in DepthFirstIterator(self._scene.getRoot()):
|
||||||
|
mesh_data = node.getMeshData()
|
||||||
|
if node.callDecoration("isSliceable") and mesh_data and mesh_data.getVertices() is not None:
|
||||||
|
is_non_printing_mesh = bool(node.callDecoration("isNonPrintingMesh"))
|
||||||
|
|
||||||
global_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
# Find a reason not to add the node
|
||||||
if not global_stack:
|
if node.callDecoration("getBuildPlateNumber") != self._build_plate_number:
|
||||||
return
|
continue
|
||||||
extruders_enabled = {position: stack.isEnabled for position, stack in global_stack.extruders.items()}
|
if getattr(node, "_outside_buildarea", False) and not is_non_printing_mesh:
|
||||||
filtered_object_groups = []
|
|
||||||
has_model_with_disabled_extruders = False
|
|
||||||
associated_disabled_extruders = set()
|
|
||||||
for group in object_groups:
|
|
||||||
stack = global_stack
|
|
||||||
skip_group = False
|
|
||||||
for node in group:
|
|
||||||
# Only check if the printing extruder is enabled for printing meshes
|
|
||||||
is_non_printing_mesh = node.callDecoration("evaluateIsNonPrintingMesh")
|
|
||||||
extruder_position = node.callDecoration("getActiveExtruderPosition")
|
|
||||||
if not is_non_printing_mesh and not extruders_enabled[extruder_position]:
|
|
||||||
skip_group = True
|
|
||||||
has_model_with_disabled_extruders = True
|
|
||||||
associated_disabled_extruders.add(extruder_position)
|
|
||||||
if not skip_group:
|
|
||||||
filtered_object_groups.append(group)
|
|
||||||
|
|
||||||
if has_model_with_disabled_extruders:
|
|
||||||
self.setResult(StartJobResult.ObjectsWithDisabledExtruder)
|
|
||||||
associated_disabled_extruders = {str(c) for c in sorted([int(p) + 1 for p in associated_disabled_extruders])}
|
|
||||||
self.setMessage(", ".join(associated_disabled_extruders))
|
|
||||||
return
|
|
||||||
|
|
||||||
# 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 filtered_object_groups:
|
|
||||||
self.setResult(StartJobResult.NothingToSlice)
|
|
||||||
return
|
|
||||||
|
|
||||||
self._buildGlobalSettingsMessage(stack)
|
|
||||||
self._buildGlobalInheritsStackMessage(stack)
|
|
||||||
|
|
||||||
# Build messages for extruder stacks
|
|
||||||
for extruder_stack in global_stack.extruderList:
|
|
||||||
self._buildExtruderMessage(extruder_stack)
|
|
||||||
|
|
||||||
for group in filtered_object_groups:
|
|
||||||
group_message = self._slice_message.addRepeatedMessage("object_lists")
|
|
||||||
parent = group[0].getParent()
|
|
||||||
if parent is not None and parent.callDecoration("isGroup"):
|
|
||||||
self._handlePerObjectSettings(cast(CuraSceneNode, parent), group_message)
|
|
||||||
|
|
||||||
for object in group:
|
|
||||||
mesh_data = object.getMeshData()
|
|
||||||
if mesh_data is None:
|
|
||||||
continue
|
continue
|
||||||
rot_scale = object.getWorldTransformation().getTransposed().getData()[0:3, 0:3]
|
|
||||||
translate = object.getWorldTransformation().getData()[:3, 3]
|
|
||||||
|
|
||||||
# This effectively performs a limited form of MeshData.getTransformed that ignores normals.
|
temp_list.append(node)
|
||||||
verts = mesh_data.getVertices()
|
if not is_non_printing_mesh:
|
||||||
verts = verts.dot(rot_scale)
|
has_printing_mesh = True
|
||||||
verts += translate
|
|
||||||
|
|
||||||
# Convert from Y up axes to Z up axes. Equals a 90 degree rotation.
|
Job.yieldThread()
|
||||||
verts[:, [1, 2]] = verts[:, [2, 1]]
|
|
||||||
verts[:, 1] *= -1
|
|
||||||
|
|
||||||
obj = group_message.addRepeatedMessage("objects")
|
# If the list doesn't have any model with suitable settings then clean the list
|
||||||
obj.id = id(object)
|
# otherwise CuraEngine will crash
|
||||||
obj.name = object.getName()
|
if not has_printing_mesh:
|
||||||
indices = mesh_data.getIndices()
|
temp_list.clear()
|
||||||
if indices is not None:
|
|
||||||
flat_verts = numpy.take(verts, indices.flatten(), axis=0)
|
|
||||||
else:
|
|
||||||
flat_verts = numpy.array(verts)
|
|
||||||
|
|
||||||
obj.vertices = flat_verts
|
if temp_list:
|
||||||
|
object_groups.append(temp_list)
|
||||||
|
|
||||||
self._handlePerObjectSettings(cast(CuraSceneNode, object), obj)
|
global_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
|
if not global_stack:
|
||||||
|
return
|
||||||
|
extruders_enabled = {position: stack.isEnabled for position, stack in global_stack.extruders.items()}
|
||||||
|
filtered_object_groups = []
|
||||||
|
has_model_with_disabled_extruders = False
|
||||||
|
associated_disabled_extruders = set()
|
||||||
|
for group in object_groups:
|
||||||
|
stack = global_stack
|
||||||
|
skip_group = False
|
||||||
|
for node in group:
|
||||||
|
# Only check if the printing extruder is enabled for printing meshes
|
||||||
|
is_non_printing_mesh = node.callDecoration("evaluateIsNonPrintingMesh")
|
||||||
|
extruder_position = node.callDecoration("getActiveExtruderPosition")
|
||||||
|
if not is_non_printing_mesh and not extruders_enabled[extruder_position]:
|
||||||
|
skip_group = True
|
||||||
|
has_model_with_disabled_extruders = True
|
||||||
|
associated_disabled_extruders.add(extruder_position)
|
||||||
|
if not skip_group:
|
||||||
|
filtered_object_groups.append(group)
|
||||||
|
|
||||||
Job.yieldThread()
|
if has_model_with_disabled_extruders:
|
||||||
|
self.setResult(StartJobResult.ObjectsWithDisabledExtruder)
|
||||||
|
associated_disabled_extruders = {str(c) for c in sorted([int(p) + 1 for p in associated_disabled_extruders])}
|
||||||
|
self.setMessage(", ".join(associated_disabled_extruders))
|
||||||
|
return
|
||||||
|
|
||||||
|
# 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 filtered_object_groups:
|
||||||
|
self.setResult(StartJobResult.NothingToSlice)
|
||||||
|
return
|
||||||
|
|
||||||
|
self._buildGlobalSettingsMessage(stack)
|
||||||
|
self._buildGlobalInheritsStackMessage(stack)
|
||||||
|
|
||||||
|
# Build messages for extruder stacks
|
||||||
|
for extruder_stack in global_stack.extruderList:
|
||||||
|
self._buildExtruderMessage(extruder_stack)
|
||||||
|
|
||||||
|
for group in filtered_object_groups:
|
||||||
|
group_message = self._slice_message.addRepeatedMessage("object_lists")
|
||||||
|
parent = group[0].getParent()
|
||||||
|
if parent is not None and parent.callDecoration("isGroup"):
|
||||||
|
self._handlePerObjectSettings(cast(CuraSceneNode, parent), group_message)
|
||||||
|
|
||||||
|
for object in group:
|
||||||
|
mesh_data = object.getMeshData()
|
||||||
|
if mesh_data is None:
|
||||||
|
continue
|
||||||
|
rot_scale = object.getWorldTransformation().getTransposed().getData()[0:3, 0:3]
|
||||||
|
translate = object.getWorldTransformation().getData()[:3, 3]
|
||||||
|
|
||||||
|
# This effectively performs a limited form of MeshData.getTransformed that ignores normals.
|
||||||
|
verts = mesh_data.getVertices()
|
||||||
|
verts = verts.dot(rot_scale)
|
||||||
|
verts += translate
|
||||||
|
|
||||||
|
# Convert from Y up axes to Z up axes. Equals a 90 degree rotation.
|
||||||
|
verts[:, [1, 2]] = verts[:, [2, 1]]
|
||||||
|
verts[:, 1] *= -1
|
||||||
|
|
||||||
|
obj = group_message.addRepeatedMessage("objects")
|
||||||
|
obj.id = id(object)
|
||||||
|
obj.name = object.getName()
|
||||||
|
indices = mesh_data.getIndices()
|
||||||
|
if indices is not None:
|
||||||
|
flat_verts = numpy.take(verts, indices.flatten(), axis=0)
|
||||||
|
else:
|
||||||
|
flat_verts = numpy.array(verts)
|
||||||
|
|
||||||
|
obj.vertices = flat_verts
|
||||||
|
|
||||||
|
self._handlePerObjectSettings(cast(CuraSceneNode, object), obj)
|
||||||
|
|
||||||
|
Job.yieldThread()
|
||||||
|
|
||||||
self.setResult(StartJobResult.Finished)
|
self.setResult(StartJobResult.Finished)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue