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): def updatePlatformActivity(self, node = None):
count = 0 count = 0
scene_bounding_box = None scene_bounding_box = None
should_pause = False
for node in DepthFirstIterator(self.getController().getScene().getRoot()): 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 continue
if node.callDecoration("shouldBlockSlicing"):
should_pause = True
count += 1 count += 1
if not scene_bounding_box: if not scene_bounding_box:
@ -605,6 +608,16 @@ class CuraApplication(QtApplication):
if other_bb is not None: if other_bb is not None:
scene_bounding_box = scene_bounding_box + node.getBoundingBox() 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: if not scene_bounding_box:
scene_bounding_box = AxisAlignedBox.Null scene_bounding_box = AxisAlignedBox.Null
@ -725,7 +738,7 @@ class CuraApplication(QtApplication):
for node in DepthFirstIterator(self.getController().getScene().getRoot()): for node in DepthFirstIterator(self.getController().getScene().getRoot()):
if type(node) is not SceneNode: if type(node) is not SceneNode:
continue 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. continue # Node that doesnt have a mesh and is not a group.
if node.getParent() and node.getParent().callDecoration("isGroup"): if node.getParent() and node.getParent().callDecoration("isGroup"):
continue # Grouped nodes don't need resetting as their parent (the group) is resetted) 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 UM.Application import Application
from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.ExtruderManager import ExtruderManager
from cura.QualityManager import QualityManager from cura.QualityManager import QualityManager
from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator
import os.path import os.path
import zipfile import zipfile
@ -234,6 +235,8 @@ class ThreeMFReader(MeshReader):
except Exception as e: except Exception as e:
Logger.log("e", "An exception occurred in 3mf reader: %s", e) Logger.log("e", "An exception occurred in 3mf reader: %s", e)
sliceable_decorator = SliceableObjectDecorator()
result.addDecorator(sliceable_decorator)
return result return result
## Create a scale vector based on a unit string. ## 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.start()
self._start_slice_job.finished.connect(self._onStartSliceCompleted) self._start_slice_job.finished.connect(self._onStartSliceCompleted)
_last_state = BackendState.NotStarted
def pauseSlicing(self): def pauseSlicing(self):
self.close() self.close()
self.backendStateChange.emit(BackendState.SlicingDisabled) self.backendStateChange.emit(BackendState.SlicingDisabled)
def continueSlicing(self): def continueSlicing(self):
self.backendStateChange.emit(BackendState.NotStarted) if self._last_state == BackendState.SlicingDisabled:
self.backendStateChange.emit(BackendState.NotStarted)
def _onBackendStateChanged(self, state): def _onBackendStateChanged(self, state):
self._last_state = state
if state == BackendState.SlicingDisabled: if state == BackendState.SlicingDisabled:
self._pause_slicing = True self._pause_slicing = True
else: else:

View file

@ -60,6 +60,7 @@ class ProcessSlicedLayersJob(Job):
for node in DepthFirstIterator(self._scene.getRoot()): for node in DepthFirstIterator(self._scene.getRoot()):
if node.callDecoration("getLayerData"): if node.callDecoration("getLayerData"):
node.getParent().removeChild(node) node.getParent().removeChild(node)
break
if self._abort_requested: if self._abort_requested:
if self._progress: if self._progress:
self._progress.hide() self._progress.hide()

View file

@ -19,6 +19,7 @@ catalog = i18nCatalog("cura")
from cura import LayerDataBuilder from cura import LayerDataBuilder
from cura import LayerDataDecorator from cura import LayerDataDecorator
from cura.LayerPolygon import LayerPolygon from cura.LayerPolygon import LayerPolygon
from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator
import numpy import numpy
import math import math
@ -34,8 +35,6 @@ class GCodeReader(MeshReader):
self._cancelled = False self._cancelled = False
self._message = None self._message = None
self._scene_node = None
@staticmethod @staticmethod
def _getValue(line, code): def _getValue(line, code):
n = line.find(code) + len(code) n = line.find(code) + len(code)
@ -69,13 +68,6 @@ class GCodeReader(MeshReader):
if message == self._message: if message == self._message:
self._cancelled = True 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 @staticmethod
def _getNullBoundingBox(): def _getNullBoundingBox():
return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10)) 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) Logger.log("d", "Preparing to load %s" % file_name)
self._cancelled = False self._cancelled = False
self._scene_node = SceneNode() scene_node = SceneNode()
self._scene_node.getBoundingBox = self._getNullBoundingBox # Manually set bounding box, because mesh doesn't have mesh data 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()
glist = [] glist = []
Application.getInstance().getController().getScene().gcode_list = glist Application.getInstance().getController().getScene().gcode_list = glist
@ -257,9 +245,12 @@ class GCodeReader(MeshReader):
layer_mesh = layer_data_builder.build() layer_mesh = layer_data_builder.build()
decorator = LayerDataDecorator.LayerDataDecorator() decorator = LayerDataDecorator.LayerDataDecorator()
decorator.setLayerData(layer_mesh) decorator.setLayerData(layer_mesh)
scene_node.addDecorator(decorator)
self._scene_node.removeDecorator("LayerDataDecorator") sliceable_decorator = SliceableObjectDecorator()
self._scene_node.addDecorator(decorator) sliceable_decorator.setBlockSlicing(True)
sliceable_decorator.setSliceable(False)
scene_node.addDecorator(sliceable_decorator)
Logger.log("d", "Finished parsing %s" % file_name) Logger.log("d", "Finished parsing %s" % file_name)
self._message.hide() self._message.hide()
@ -267,15 +258,12 @@ class GCodeReader(MeshReader):
if current_layer == 0: if current_layer == 0:
Logger.log("w", "File %s doesn't contain any valid layers" % file_name) 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() settings = Application.getInstance().getGlobalContainerStack()
machine_width = settings.getProperty("machine_width", "value") machine_width = settings.getProperty("machine_width", "value")
machine_depth = settings.getProperty("machine_depth", "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) 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): if isinstance(node, ToolHandle):
tool_handle_batch.addItem(node.getWorldTransformation(), mesh = node.getSolidMesh()) 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") layer_data = node.callDecoration("getLayerData")
if not layer_data: if not layer_data:
continue continue

View file

@ -10,6 +10,7 @@ from UM.Scene.SceneNode import SceneNode
from UM.Job import Job from UM.Job import Job
from math import pi, sin, cos, sqrt from math import pi, sin, cos, sqrt
import numpy import numpy
from UM.Scene.SliceableObjectDecorator import SliceableObjectDecorator
try: try:
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
@ -96,6 +97,8 @@ class X3DReader(MeshReader):
Logger.logException("e", "Exception in X3D reader") Logger.logException("e", "Exception in X3D reader")
return None return None
sliceable_decorator = SliceableObjectDecorator()
node.addDecorator(sliceable_decorator)
return node return node
# ------------------------- XML tree traversal # ------------------------- XML tree traversal