diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 44a1f4d8a0..4e611cf680 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -593,9 +593,12 @@ class CuraApplication(QtApplication): def updatePlatformActivity(self, node = None): count = 0 scene_bounding_box = None + should_pause = False for node in DepthFirstIterator(self.getController().getScene().getRoot()): - if type(node) is not SceneNode or (not node.getMeshData() and not hasattr(node, "gcode")): + if type(node) is not SceneNode or (not node.getMeshData() and not node.callDecoration("shouldBlockSlicing")): continue + if node.callDecoration("shouldBlockSlicing"): + should_pause = True count += 1 if not scene_bounding_box: @@ -605,6 +608,16 @@ class CuraApplication(QtApplication): if other_bb is not None: scene_bounding_box = scene_bounding_box + node.getBoundingBox() + if not should_pause: + self.getBackend().continueSlicing() + self.setHideSettings(False) + if self.getPrintInformation(): + self.getPrintInformation().setPreSliced(False) + else: + self.getBackend().pauseSlicing() + self.setHideSettings(True) + self.getPrintInformation().setPreSliced(True) + if not scene_bounding_box: scene_bounding_box = AxisAlignedBox.Null @@ -725,7 +738,7 @@ class CuraApplication(QtApplication): for node in DepthFirstIterator(self.getController().getScene().getRoot()): if type(node) is not SceneNode: continue - if (not node.getMeshData() and not hasattr(node, "gcode")) and not node.callDecoration("isGroup"): + if (not node.getMeshData() and node.callDecoration("isSliceable")) and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) diff --git a/plugins/3MFReader/ThreeMFReader.py b/plugins/3MFReader/ThreeMFReader.py index 397a63c194..97134bf676 100644 --- a/plugins/3MFReader/ThreeMFReader.py +++ b/plugins/3MFReader/ThreeMFReader.py @@ -14,6 +14,7 @@ from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator from UM.Application import Application from cura.Settings.ExtruderManager import ExtruderManager from cura.QualityManager import QualityManager +from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator import os.path import zipfile @@ -234,6 +235,8 @@ class ThreeMFReader(MeshReader): except Exception as e: Logger.log("e", "An exception occurred in 3mf reader: %s", e) + sliceable_decorator = SliceableObjectDecorator() + result.addDecorator(sliceable_decorator) return result ## Create a scale vector based on a unit string. @@ -263,4 +266,4 @@ class ThreeMFReader(MeshReader): Logger.log("w", "Unrecognised unit %s used. Assuming mm instead", unit) scale = 1 - return Vector(scale, scale, scale) \ No newline at end of file + return Vector(scale, scale, scale) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 31e35aa778..b77b5da5bd 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -188,14 +188,18 @@ class CuraEngineBackend(Backend): self._start_slice_job.start() self._start_slice_job.finished.connect(self._onStartSliceCompleted) + _last_state = BackendState.NotStarted + def pauseSlicing(self): self.close() self.backendStateChange.emit(BackendState.SlicingDisabled) def continueSlicing(self): - self.backendStateChange.emit(BackendState.NotStarted) + if self._last_state == BackendState.SlicingDisabled: + self.backendStateChange.emit(BackendState.NotStarted) def _onBackendStateChanged(self, state): + self._last_state = state if state == BackendState.SlicingDisabled: self._pause_slicing = True else: diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index 490690bd27..c4e9554b2c 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -60,6 +60,7 @@ class ProcessSlicedLayersJob(Job): for node in DepthFirstIterator(self._scene.getRoot()): if node.callDecoration("getLayerData"): node.getParent().removeChild(node) + break if self._abort_requested: if self._progress: self._progress.hide() diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index af3536c6f1..461f4f70b3 100644 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -19,6 +19,7 @@ catalog = i18nCatalog("cura") from cura import LayerDataBuilder from cura import LayerDataDecorator from cura.LayerPolygon import LayerPolygon +from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator import numpy import math @@ -34,8 +35,6 @@ class GCodeReader(MeshReader): self._cancelled = False self._message = None - self._scene_node = None - @staticmethod def _getValue(line, code): n = line.find(code) + len(code) @@ -69,13 +68,6 @@ class GCodeReader(MeshReader): if message == self._message: self._cancelled = True - def _onParentChanged(self, node): - if self._scene_node is not None and self._scene_node.getParent() is None: - self._scene_node = None - Application.getInstance().getBackend().continueSlicing() - Application.getInstance().setHideSettings(False) - Application.getInstance().getPrintInformation().setPreSliced(False) - @staticmethod def _getNullBoundingBox(): return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10)) @@ -120,12 +112,8 @@ class GCodeReader(MeshReader): Logger.log("d", "Preparing to load %s" % file_name) self._cancelled = False - self._scene_node = SceneNode() - self._scene_node.getBoundingBox = self._getNullBoundingBox # Manually set bounding box, because mesh doesn't have mesh data - self._scene_node.gcode = True - self._scene_node.parentChanged.connect(self._onParentChanged) - - Application.getInstance().getBackend().pauseSlicing() + scene_node = SceneNode() + scene_node.getBoundingBox = self._getNullBoundingBox # Manually set bounding box, because mesh doesn't have mesh data glist = [] Application.getInstance().getController().getScene().gcode_list = glist @@ -257,9 +245,12 @@ class GCodeReader(MeshReader): layer_mesh = layer_data_builder.build() decorator = LayerDataDecorator.LayerDataDecorator() decorator.setLayerData(layer_mesh) + scene_node.addDecorator(decorator) - self._scene_node.removeDecorator("LayerDataDecorator") - self._scene_node.addDecorator(decorator) + sliceable_decorator = SliceableObjectDecorator() + sliceable_decorator.setBlockSlicing(True) + sliceable_decorator.setSliceable(False) + scene_node.addDecorator(sliceable_decorator) Logger.log("d", "Finished parsing %s" % file_name) self._message.hide() @@ -267,15 +258,12 @@ class GCodeReader(MeshReader): if current_layer == 0: Logger.log("w", "File %s doesn't contain any valid layers" % file_name) - Application.getInstance().getPrintInformation().setPreSliced(True) - Application.getInstance().setHideSettings(True) - settings = Application.getInstance().getGlobalContainerStack() machine_width = settings.getProperty("machine_width", "value") machine_depth = settings.getProperty("machine_depth", "value") - self._scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2)) + scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2)) Logger.log("d", "Loaded %s" % file_name) - return self._scene_node + return scene_node diff --git a/plugins/LayerView/LayerPass.py b/plugins/LayerView/LayerPass.py index 9e610b68d2..ca895619a3 100644 --- a/plugins/LayerView/LayerPass.py +++ b/plugins/LayerView/LayerPass.py @@ -49,7 +49,7 @@ class LayerPass(RenderPass): if isinstance(node, ToolHandle): tool_handle_batch.addItem(node.getWorldTransformation(), mesh = node.getSolidMesh()) - elif isinstance(node, SceneNode) and (node.getMeshData() or hasattr(node, "gcode")) and node.isVisible(): + elif isinstance(node, SceneNode) and (node.getMeshData() or not node.callDecoration("isSliceable")) and node.isVisible(): layer_data = node.callDecoration("getLayerData") if not layer_data: continue diff --git a/plugins/X3DReader/X3DReader.py b/plugins/X3DReader/X3DReader.py index ba31c9ea86..16b8a6a5ae 100644 --- a/plugins/X3DReader/X3DReader.py +++ b/plugins/X3DReader/X3DReader.py @@ -10,6 +10,7 @@ from UM.Scene.SceneNode import SceneNode from UM.Job import Job from math import pi, sin, cos, sqrt import numpy +from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator try: import xml.etree.cElementTree as ET @@ -96,6 +97,8 @@ class X3DReader(MeshReader): Logger.logException("e", "Exception in X3D reader") return None + sliceable_decorator = SliceableObjectDecorator() + node.addDecorator(sliceable_decorator) return node # ------------------------- XML tree traversal