D6: Changed decorator and swapping to LayerView

This commit is contained in:
Victor Larchenko 2016-12-13 13:39:09 +06:00 committed by Youness Alaoui
parent 647c2f15ba
commit 67ab0cab41
7 changed files with 50 additions and 41 deletions

View file

@ -0,0 +1,9 @@
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
class BlockSlicingDecorator(SceneNodeDecorator):
def __init__(self):
super().__init__()
def isBlockSlicing(self):
return True

View file

@ -29,6 +29,7 @@ from UM.Operations.SetTransformOperation import SetTransformOperation
from UM.Operations.TranslateOperation import TranslateOperation from UM.Operations.TranslateOperation import TranslateOperation
from cura.SetParentOperation import SetParentOperation from cura.SetParentOperation import SetParentOperation
from cura.SliceableObjectDecorator import SliceableObjectDecorator from cura.SliceableObjectDecorator import SliceableObjectDecorator
from cura.BlockSlicingDecorator import BlockSlicingDecorator
from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyType from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyType
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
@ -136,6 +137,9 @@ class CuraApplication(QtApplication):
} }
) )
self._currently_loading_files = []
self._non_sliceable_extensions = []
self._machine_action_manager = MachineActionManager.MachineActionManager() self._machine_action_manager = MachineActionManager.MachineActionManager()
self._machine_manager = None # This is initialized on demand. self._machine_manager = None # This is initialized on demand.
self._setting_inheritance_manager = None self._setting_inheritance_manager = None
@ -290,8 +294,6 @@ class CuraApplication(QtApplication):
self._recent_files.append(QUrl.fromLocalFile(f)) self._recent_files.append(QUrl.fromLocalFile(f))
self.changeLayerViewSignal.connect(self.changeToLayerView)
def _onEngineCreated(self): def _onEngineCreated(self):
self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
@ -538,15 +540,6 @@ class CuraApplication(QtApplication):
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name) qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
changeLayerViewSignal = pyqtSignal()
def changeToLayerView(self):
self.getController().setActiveView("LayerView")
view = self.getController().getActiveView()
view.resetLayerData()
view.setLayer(999999)
view.calculateMaxLayers()
def onSelectionChanged(self): def onSelectionChanged(self):
if Selection.hasSelection(): if Selection.hasSelection():
if self.getController().getActiveTool(): if self.getController().getActiveTool():
@ -594,11 +587,11 @@ class CuraApplication(QtApplication):
scene_bounding_box = None scene_bounding_box = None
should_pause = False 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 node.callDecoration("isSliceable") is None): if type(node) is not SceneNode or (not node.getMeshData() and not node.callDecoration("isBlockSlicing")):
continue continue
if node.callDecoration("isSliceable") is False: if node.callDecoration("isBlockSlicing"):
should_pause = True should_pause = True
gcode_list = node.callDecoration("gCodeList") gcode_list = node.callDecoration("getGCodeList")
if gcode_list is not None: if gcode_list is not None:
self.getController().getScene().gcode_list = gcode_list self.getController().getScene().gcode_list = gcode_list
@ -740,7 +733,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 node.callDecoration("isSliceable") is None) and not node.callDecoration("isGroup"): if (not node.getMeshData() and not node.callDecoration("isBlockSlicing")) 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)
@ -1036,9 +1029,6 @@ class CuraApplication(QtApplication):
def log(self, msg): def log(self, msg):
Logger.log("d", msg) Logger.log("d", msg)
_loading_files = []
non_sliceable_extensions = []
@pyqtSlot(QUrl) @pyqtSlot(QUrl)
def readLocalFile(self, file): def readLocalFile(self, file):
if not file.isValid(): if not file.isValid():
@ -1047,16 +1037,16 @@ class CuraApplication(QtApplication):
scene = self.getController().getScene() scene = self.getController().getScene()
for node in DepthFirstIterator(scene.getRoot()): for node in DepthFirstIterator(scene.getRoot()):
if node.callDecoration("isSliceable") is False: if node.callDecoration("isBlockSlicing"):
self.deleteAll() self.deleteAll()
break break
f = file.toLocalFile() f = file.toLocalFile()
extension = os.path.splitext(f)[1] extension = os.path.splitext(f)[1]
filename = os.path.basename(f) filename = os.path.basename(f)
if len(self._loading_files) > 0: if len(self._currently_loading_files) > 0:
# If a non-slicable file is already being loaded, we prevent loading of any further non-slicable files # If a non-slicable file is already being loaded, we prevent loading of any further non-slicable files
if extension.lower() in self.non_sliceable_extensions: if extension.lower() in self._non_sliceable_extensions:
message = Message( message = Message(
self._i18n_catalog.i18nc("@info:status", self._i18n_catalog.i18nc("@info:status",
"Only one G-code file can be loaded at a time. Skipped importing {0}", "Only one G-code file can be loaded at a time. Skipped importing {0}",
@ -1064,8 +1054,8 @@ class CuraApplication(QtApplication):
message.show() message.show()
return return
# If file being loaded is non-slicable file, then prevent loading of any other files # If file being loaded is non-slicable file, then prevent loading of any other files
extension = os.path.splitext(self._loading_files[0])[1] extension = os.path.splitext(self._currently_loading_files[0])[1]
if extension.lower() in self.non_sliceable_extensions: if extension.lower() in self._non_sliceable_extensions:
message = Message( message = Message(
self._i18n_catalog.i18nc("@info:status", self._i18n_catalog.i18nc("@info:status",
"Can't open any other file if G-code is loading. Skipped importing {0}", "Can't open any other file if G-code is loading. Skipped importing {0}",
@ -1073,8 +1063,8 @@ class CuraApplication(QtApplication):
message.show() message.show()
return return
self._loading_files.append(f) self._currently_loading_files.append(f)
if extension in self.non_sliceable_extensions: if extension in self._non_sliceable_extensions:
self.deleteAll() self.deleteAll()
job = ReadMeshJob(f) job = ReadMeshJob(f)
@ -1084,18 +1074,22 @@ class CuraApplication(QtApplication):
def _readMeshFinished(self, job): def _readMeshFinished(self, job):
node = job.getResult() node = job.getResult()
filename = job.getFileName() filename = job.getFileName()
self._loading_files.remove(filename) self._currently_loading_files.remove(filename)
if node != None: if node != None:
node.setSelectable(True) node.setSelectable(True)
node.setName(os.path.basename(filename)) node.setName(os.path.basename(filename))
extension = os.path.splitext(filename)[1] extension = os.path.splitext(filename)[1]
if extension.lower() in self.non_sliceable_extensions: if extension.lower() in self._non_sliceable_extensions:
self.changeLayerViewSignal.emit() self.getController().setActiveView("LayerView")
sliceable_decorator = SliceableObjectDecorator() view = self.getController().getActiveView()
sliceable_decorator.setSliceable(False) view.resetLayerData()
node.addDecorator(sliceable_decorator) view.setLayer(9999999)
view.calculateMaxLayers()
block_slicing_decorator = BlockSlicingDecorator()
node.addDecorator(block_slicing_decorator)
else: else:
sliceable_decorator = SliceableObjectDecorator() sliceable_decorator = SliceableObjectDecorator()
node.addDecorator(sliceable_decorator) node.addDecorator(sliceable_decorator)
@ -1107,3 +1101,5 @@ class CuraApplication(QtApplication):
scene.sceneChanged.emit(node) scene.sceneChanged.emit(node)
def addNonSliceableExtension(self, extension):
self._non_sliceable_extensions.append(extension)

View file

@ -6,7 +6,7 @@ class GCodeListDecorator(SceneNodeDecorator):
super().__init__() super().__init__()
self._gcode_list = [] self._gcode_list = []
def gCodeList(self): def getGCodeList(self):
return self._gcode_list return self._gcode_list
def setGCodeList(self, list): def setGCodeList(self, list):

View file

@ -0,0 +1,9 @@
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
class NonSliceableObjectDecorator(SceneNodeDecorator):
def __init__(self):
super().__init__()
def isNonSliceable(self):
return True

View file

@ -1,14 +1,9 @@
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
## Simple decorator to indicate a scene node is sliceable or not.
class SliceableObjectDecorator(SceneNodeDecorator): class SliceableObjectDecorator(SceneNodeDecorator):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._sliceable = True
def isSliceable(self): def isSliceable(self):
return self._sliceable return True
def setSliceable(self, sliceable):
self._sliceable = sliceable

View file

@ -28,6 +28,6 @@ def getMetaData():
} }
def register(app): def register(app):
app.non_sliceable_extensions.append(".gcode") app.addNonSliceableExtension(".gcode")
app.non_sliceable_extensions.append(".g") app.addNonSliceableExtension(".g")
return { "mesh_reader": GCodeReader.GCodeReader() } return { "mesh_reader": GCodeReader.GCodeReader() }

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 node.callDecoration("isSliceable") is False) and node.isVisible(): elif isinstance(node, SceneNode) and (node.getMeshData() or node.callDecoration("isBlockSlicing")) and node.isVisible():
layer_data = node.callDecoration("getLayerData") layer_data = node.callDecoration("getLayerData")
if not layer_data: if not layer_data:
continue continue