D5: Added decorator

This commit is contained in:
Victor Larchenko 2016-11-27 14:05:25 +06:00 committed by Youness Alaoui
parent 002b3139e6
commit 4aa59950ca
7 changed files with 39 additions and 27 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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:

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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