diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index dbbbb7e4f8..0a552428af 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -541,13 +541,10 @@ class CuraApplication(QtApplication): def loadFile(self, file): scene = self.getController().getScene() - def findAny(): - for node1 in DepthFirstIterator(scene.getRoot()): - if hasattr(node1, "gcode") and getattr(node1, "gcode") is True: - return True - return False - if findAny(): - self.deleteAll() + for node1 in DepthFirstIterator(scene.getRoot()): + if hasattr(node1, "gcode") and getattr(node1, "gcode") is True: + self.deleteAll() + break if not file.isValid(): return diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 4e1b2f6841..3737976175 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -152,6 +152,8 @@ class CuraEngineBackend(Backend): ## Perform a slice of the scene. def slice(self): Logger.log("d", "Starting slice job...") + if self._pauseSlicing: + return self._slice_start_time = time() if not self._enabled or not self._global_container_stack: # We shouldn't be slicing. # try again in a short time @@ -395,7 +397,8 @@ class CuraEngineBackend(Backend): ## Manually triggers a reslice def forceSlice(self): - self._change_timer.start() + if not self._pauseSlicing: + self._change_timer.start() ## Called when anything has changed to the stuff that needs to be sliced. # diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 8502c044c4..1fcd615c5e 100644 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -31,6 +31,8 @@ class GCodeReader(MeshReader): self.cancelled = False self.message = None + self.scene_node = None + @staticmethod def getInt(line, code): n = line.find(code) + 1 @@ -61,26 +63,17 @@ class GCodeReader(MeshReader): if m == self.message: self.cancelled = True - @staticmethod - def onParentChanged(node): - if node.getParent() is None: - scene = Application.getInstance().getController().getScene() - - isAny = False - for node1 in DepthFirstIterator(scene.getRoot()): - if hasattr(node1, "gcode") and getattr(node1, "gcode") is True: - isAny = True - - backend = Application.getInstance().getBackend() - if not isAny: - backend._pauseSlicing = False - Application.getInstance().setHideSettings(False) - Application.getInstance().getPrintInformation().setPreSliced(False) - else: - backend._pauseSlicing = True - backend.backendStateChange.emit(3) - Application.getInstance().getPrintInformation().setPreSliced(True) - Application.getInstance().setHideSettings(True) + def onParentChanged(self, node): + backend = Application.getInstance().getBackend() + if self.scene_node is not None and self.scene_node.getParent() is None: + self.scene_node = None + backend._pauseSlicing = False + Application.getInstance().setHideSettings(False) + Application.getInstance().getPrintInformation().setPreSliced(False) + else: + backend._pauseSlicing = True + Application.getInstance().getPrintInformation().setPreSliced(True) + Application.getInstance().setHideSettings(True) @staticmethod def getNullBoundingBox(): @@ -127,21 +120,21 @@ class GCodeReader(MeshReader): return True def read(self, file_name): - scene_node = None - extension = os.path.splitext(file_name)[1] if extension.lower() in self._supported_extensions: Logger.log("d", "Preparing to load %s" % file_name) self.cancelled = False Application.getInstance().deleteAll() - scene_node = SceneNode() - scene_node.getBoundingBox = self.getNullBoundingBox - scene_node.gcode = True + self.scene_node = SceneNode() + self.scene_node.getBoundingBox = self.getNullBoundingBox + self.scene_node.gcode = True + self.scene_node.parentChanged.connect(self.onParentChanged) + backend = Application.getInstance().getBackend() backend._pauseSlicing = True backend.close() - backend.backendStateChange.emit(1) + backend.backendStateChange.emit(3) glist = getattr(Application.getInstance().getController().getScene(), "gcode_list") glist.clear() @@ -241,7 +234,9 @@ class GCodeReader(MeshReader): layer_mesh = layer_data.build() decorator = LayerDataDecorator.LayerDataDecorator() decorator.setLayerData(layer_mesh) - scene_node.addDecorator(decorator) + + self.scene_node.removeDecorator("LayerDataDecorator") + self.scene_node.addDecorator(decorator) Logger.log("d", "Finished parsing %s" % file_name) self.message.hide() @@ -249,18 +244,13 @@ class GCodeReader(MeshReader): if current_layer == 0: Logger.log("w", "File %s doesn't contain any valid layers" % file_name) - Application.getInstance().getPrintInformation()._pre_sliced = True - - scene_node.parentChanged.connect(self.onParentChanged) - - scene_node_parent = Application.getInstance().getBuildVolume() - scene_node.setParent(scene_node_parent) + Application.getInstance().getPrintInformation().setPreSliced(True) settings = Application.getInstance().getGlobalContainerStack() machine_width = settings.getProperty("machine_width", "value") machine_depth = settings.getProperty("machine_depth", "value") - scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2)) + self.scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2)) view = Application.getInstance().getController().getActiveView() if view.getPluginId() == "LayerView": @@ -270,4 +260,4 @@ class GCodeReader(MeshReader): Logger.log("d", "Loaded %s" % file_name) - return scene_node + return self.scene_node