T466: Fixed Nothing to slice bug

This commit is contained in:
Victor Larchenko 2016-11-09 14:53:23 +06:00 committed by Youness Alaoui
parent 2b2eec5643
commit be3a945fb0
3 changed files with 33 additions and 43 deletions

View file

@ -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()
break
if not file.isValid():
return

View file

@ -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,6 +397,7 @@ class CuraEngineBackend(Backend):
## Manually triggers a reslice
def forceSlice(self):
if not self._pauseSlicing:
self._change_timer.start()
## Called when anything has changed to the stuff that needs to be sliced.

View file

@ -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,24 +63,15 @@ 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
def onParentChanged(self, node):
backend = Application.getInstance().getBackend()
if not isAny:
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
backend.backendStateChange.emit(3)
Application.getInstance().getPrintInformation().setPreSliced(True)
Application.getInstance().setHideSettings(True)
@ -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