D5: Refactoring

This commit is contained in:
Victor Larchenko 2016-11-22 15:12:37 +06:00 committed by Youness Alaoui
parent ce9251b5a6
commit 1631045d7a
10 changed files with 69 additions and 43 deletions

View file

@ -19,6 +19,7 @@ from UM.SaveFile import SaveFile
from UM.Scene.Selection import Selection from UM.Scene.Selection import Selection
from UM.Scene.GroupDecorator import GroupDecorator from UM.Scene.GroupDecorator import GroupDecorator
from UM.Settings.Validator import Validator from UM.Settings.Validator import Validator
from UM.Message import Message
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
@ -32,6 +33,7 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.SettingFunction import SettingFunction from UM.Settings.SettingFunction import SettingFunction
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
from . import PlatformPhysics from . import PlatformPhysics
from . import BuildVolume from . import BuildVolume
@ -289,6 +291,8 @@ 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())
@ -536,31 +540,45 @@ class CuraApplication(QtApplication):
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name) qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
loadingFiles = [] loadingFiles = []
non_sliceable_extensions = [".gcode", ".g"]
changeLayerViewSignal = pyqtSignal()
def changeToLayerView(self):
self.getController().setActiveView("LayerView")
@pyqtSlot(QUrl) @pyqtSlot(QUrl)
def loadFile(self, file): def loadFile(self, file):
scene = self.getController().getScene() scene = self.getController().getScene()
for node1 in DepthFirstIterator(scene.getRoot()):
if hasattr(node1, "gcode") and getattr(node1, "gcode") is True:
self.deleteAll()
break
if not file.isValid(): if not file.isValid():
return return
supported_extensions = [".gcode", ".g"] for node in DepthFirstIterator(scene.getRoot()):
if hasattr(node, "gcode") and getattr(node, "gcode") is True:
self.deleteAll()
break
f = file.toLocalFile() f = file.toLocalFile()
extension = os.path.splitext(f)[1] extension = os.path.splitext(f)[1]
filename = os.path.basename(f)
if len(self.loadingFiles) > 0: if len(self.loadingFiles) > 0:
if extension.lower() in supported_extensions: # 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:
message = Message(
catalog.i18nc("@info:status", "Only one G-code file can be loaded at a time. Skipped importing {0}",
filename))
message.show()
return return
# If file being loaded is non-slicable file, then prevent loading of any other files
extension = os.path.splitext(self.loadingFiles[0])[1] extension = os.path.splitext(self.loadingFiles[0])[1]
if extension.lower() in supported_extensions: if extension.lower() in self.non_sliceable_extensions:
message = Message(
catalog.i18nc("@info:status",
"Can't open any other file if G-code is loading. Skipped importing {0}",
filename))
message.show()
return return
elif extension.lower() in supported_extensions:
self.getController().setActiveView("LayerView")
self.loadingFiles.append(f) self.loadingFiles.append(f)
@ -570,11 +588,16 @@ class CuraApplication(QtApplication):
def _readMeshFinished(self, job): def _readMeshFinished(self, job):
node = job.getResult() node = job.getResult()
filename = job.getFileName()
self.loadingFiles.remove(filename)
if node != None: if node != None:
filename = job.getFileName()
node.setSelectable(True) node.setSelectable(True)
node.setName(filename) node.setName(os.path.basename(filename))
self.loadingFiles.remove(filename)
extension = os.path.splitext(filename)[1]
if extension.lower() in self.non_sliceable_extensions:
self.changeLayerViewSignal.emit()
op = AddSceneNodeOperation(node, self.getController().getScene().getRoot()) op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
op.push() op.push()
@ -1056,14 +1079,14 @@ class CuraApplication(QtApplication):
_hide_settings = False _hide_settings = False
HideSettingsChanged = pyqtSignal(bool) hideSettingsChanged = pyqtSignal(bool)
@pyqtSlot(bool) @pyqtSlot(bool)
def setHideSettings(self, hide): def setHideSettings(self, hide):
self._hide_settings = hide self._hide_settings = hide
self.HideSettingsChanged.emit(hide) self.hideSettingsChanged.emit(hide)
@pyqtProperty(bool, notify=HideSettingsChanged) @pyqtProperty(bool, fset=setHideSettings, notify=hideSettingsChanged)
def hideSettings(self): def hideSettings(self):
return self._hide_settings return self._hide_settings

View file

@ -13,6 +13,9 @@ import math
import os.path import os.path
import unicodedata import unicodedata
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
## A class for processing and calculating minimum, current and maximum print time as well as managing the job name ## A class for processing and calculating minimum, current and maximum print time as well as managing the job name
# #
# This class contains all the logic relating to calculation and slicing for the # This class contains all the logic relating to calculation and slicing for the
@ -66,7 +69,7 @@ class PrintInformation(QObject):
preSlicedChanged = pyqtSignal() preSlicedChanged = pyqtSignal()
@pyqtProperty(bool, notify=preSlicedChanged) @pyqtProperty(bool, notify=preSlicedChanged)
def isPreSliced(self): def preSliced(self):
return self._pre_sliced return self._pre_sliced
def setPreSliced(self, pre_sliced): def setPreSliced(self, pre_sliced):
@ -134,10 +137,8 @@ class PrintInformation(QObject):
def createJobName(self, base_name): def createJobName(self, base_name):
base_name = self._stripAccents(base_name) base_name = self._stripAccents(base_name)
self._setAbbreviatedMachineName() self._setAbbreviatedMachineName()
if len(base_name) > 100:
base_name = "%s..." % base_name[:100]
if self._pre_sliced: if self._pre_sliced:
return "Pre-sliced file " + base_name return catalog.i18nc("@label", "Pre-sliced file {0}", base_name)
elif Preferences.getInstance().getValue("cura/jobname_prefix"): elif Preferences.getInstance().getValue("cura/jobname_prefix"):
return self._abbr_machine + "_" + base_name return self._abbr_machine + "_" + base_name
else: else:

View file

@ -69,7 +69,7 @@ class CuraEngineBackend(Backend):
self._scene = Application.getInstance().getController().getScene() self._scene = Application.getInstance().getController().getScene()
self._scene.sceneChanged.connect(self._onSceneChanged) self._scene.sceneChanged.connect(self._onSceneChanged)
self._pauseSlicing = False self._pause_slicing = False
# Workaround to disable layer view processing if layer view is not active. # Workaround to disable layer view processing if layer view is not active.
self._layer_view_active = False self._layer_view_active = False
@ -116,6 +116,7 @@ class CuraEngineBackend(Backend):
self.backendQuit.connect(self._onBackendQuit) self.backendQuit.connect(self._onBackendQuit)
self.backendConnected.connect(self._onBackendConnected) self.backendConnected.connect(self._onBackendConnected)
self.backendStateChange.connect(self._onBackendStateChanged)
# When a tool operation is in progress, don't slice. So we need to listen for tool operations. # When a tool operation is in progress, don't slice. So we need to listen for tool operations.
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted) Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
@ -152,7 +153,7 @@ class CuraEngineBackend(Backend):
## Perform a slice of the scene. ## Perform a slice of the scene.
def slice(self): def slice(self):
Logger.log("d", "Starting slice job...") Logger.log("d", "Starting slice job...")
if self._pauseSlicing: if self._pause_slicing:
return return
self._slice_start_time = time() self._slice_start_time = time()
if not self._enabled or not self._global_container_stack: # We shouldn't be slicing. if not self._enabled or not self._global_container_stack: # We shouldn't be slicing.
@ -187,6 +188,12 @@ 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)
def _onBackendStateChanged(self, state):
if state == BackendState.SlicingDisabled:
self._pause_slicing = True
else:
self._pause_slicing = False
## Terminate the engine process. ## Terminate the engine process.
def _terminate(self): def _terminate(self):
self._slicing = False self._slicing = False
@ -397,15 +404,13 @@ class CuraEngineBackend(Backend):
## Manually triggers a reslice ## Manually triggers a reslice
def forceSlice(self): def forceSlice(self):
if not self._pauseSlicing: self._change_timer.start()
self._change_timer.start()
## Called when anything has changed to the stuff that needs to be sliced. ## Called when anything has changed to the stuff that needs to be sliced.
# #
# This indicates that we should probably re-slice soon. # This indicates that we should probably re-slice soon.
def _onChanged(self, *args, **kwargs): def _onChanged(self, *args, **kwargs):
if not self._pauseSlicing: self._change_timer.start()
self._change_timer.start()
## Called when the back-end connects to the front-end. ## Called when the back-end connects to the front-end.
def _onBackendConnected(self): def _onBackendConnected(self):

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

@ -10,6 +10,7 @@ from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Application import Application from UM.Application import Application
from UM.Message import Message from UM.Message import Message
from UM.Logger import Logger from UM.Logger import Logger
from UM.Backend.Backend import BackendState
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
@ -67,11 +68,11 @@ class GCodeReader(MeshReader):
backend = Application.getInstance().getBackend() backend = Application.getInstance().getBackend()
if self.scene_node is not None and self.scene_node.getParent() is None: if self.scene_node is not None and self.scene_node.getParent() is None:
self.scene_node = None self.scene_node = None
backend._pauseSlicing = False backend.backendStateChange.emit(BackendState.NotStarted)
Application.getInstance().setHideSettings(False) Application.getInstance().setHideSettings(False)
Application.getInstance().getPrintInformation().setPreSliced(False) Application.getInstance().getPrintInformation().setPreSliced(False)
else: else:
backend._pauseSlicing = True backend.backendStateChange.emit(BackendState.SlicingDisabled)
Application.getInstance().getPrintInformation().setPreSliced(True) Application.getInstance().getPrintInformation().setPreSliced(True)
Application.getInstance().setHideSettings(True) Application.getInstance().setHideSettings(True)
@ -135,9 +136,8 @@ class GCodeReader(MeshReader):
self.scene_node.parentChanged.connect(self.onParentChanged) self.scene_node.parentChanged.connect(self.onParentChanged)
backend = Application.getInstance().getBackend() backend = Application.getInstance().getBackend()
backend._pauseSlicing = True
backend.close() backend.close()
backend.backendStateChange.emit(3) backend.backendStateChange.emit(BackendState.SlicingDisabled)
glist = getattr(Application.getInstance().getController().getScene(), "gcode_list") glist = getattr(Application.getInstance().getController().getScene(), "gcode_list")
glist.clear() glist.clear()

View file

@ -4,21 +4,21 @@
from . import GCodeReader from . import GCodeReader
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
i18n_catalog = i18nCatalog("uranium") i18n_catalog = i18nCatalog("cura")
def getMetaData(): def getMetaData():
return { return {
"plugin": { "plugin": {
"name": i18n_catalog.i18nc("@label", "GCODE Reader"), "name": i18n_catalog.i18nc("@label", "G-code Reader"),
"author": "Victor Larchenko", "author": "Victor Larchenko",
"version": "1.0", "version": "1.0",
"description": i18n_catalog.i18nc("@info:whatsthis", "Allows displaying GCODE files."), "description": i18n_catalog.i18nc("@info:whatsthis", "Allows loading and displaying G-code files."),
"api": 3 "api": 3
}, },
"mesh_reader": [ "mesh_reader": [
{ {
"extension": "gcode", "extension": "gcode",
"description": i18n_catalog.i18nc("@item:inlistbox", "GCODE File") "description": i18n_catalog.i18nc("@item:inlistbox", "G-code File")
}, },
{ {
"extension": "g", "extension": "g",

View file

@ -412,7 +412,7 @@ UM.MainWindow
style: UM.Theme.styles.tool_button; style: UM.Theme.styles.tool_button;
tooltip: ""; tooltip: "";
enabled: !PrintInformation.isPreSliced enabled: !PrintInformation.preSliced
menu: ViewMenu { } menu: ViewMenu { }
} }

View file

@ -11,7 +11,7 @@ Menu
{ {
title: catalog.i18nc("@title:menu menubar:toplevel", "&View"); title: catalog.i18nc("@title:menu menubar:toplevel", "&View");
id: menu id: menu
enabled: !PrintInformation.isPreSliced enabled: !PrintInformation.preSliced
Instantiator Instantiator
{ {
model: UM.ViewModel { } model: UM.ViewModel { }

View file

@ -14,7 +14,6 @@ Rectangle {
property real progress: UM.Backend.progress; property real progress: UM.Backend.progress;
property int backendState: UM.Backend.state; property int backendState: UM.Backend.state;
property bool backendPaused: UM.Backend.paused;
property bool activity: Printer.getPlatformActivity; property bool activity: Printer.getPlatformActivity;
property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
property string fileBaseName property string fileBaseName
@ -25,11 +24,6 @@ Rectangle {
return catalog.i18nc("@label:PrintjobStatus", "Please load a 3d model"); return catalog.i18nc("@label:PrintjobStatus", "Please load a 3d model");
} }
if (backendPaused)
{
return catalog.i18nc("@label:PrintjobStatus", "Slicing temporary disabled");
}
switch(base.backendState) switch(base.backendState)
{ {
case 1: case 1:
@ -40,6 +34,8 @@ Rectangle {
return catalog.i18nc("@label:PrintjobStatus %1 is target operation","Ready to %1").arg(UM.OutputDeviceManager.activeDeviceShortDescription); return catalog.i18nc("@label:PrintjobStatus %1 is target operation","Ready to %1").arg(UM.OutputDeviceManager.activeDeviceShortDescription);
case 4: case 4:
return catalog.i18nc("@label:PrintjobStatus", "Unable to Slice"); return catalog.i18nc("@label:PrintjobStatus", "Unable to Slice");
case 5:
return catalog.i18nc("@label:PrintjobStatus", "Slicing unavailable");
default: default:
return ""; return "";
} }

View file

@ -289,7 +289,7 @@ Rectangle
Label { Label {
id: settingsModeLabel id: settingsModeLabel
text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox","Not possible to modify slicing settings or re-slice\nwhile a GCODE file is open"); text: !hideSettings ? catalog.i18nc("@label:listbox", "Print Setup") : catalog.i18nc("@label:listbox","Print Setup disabled\nG-code files cannot be modified");
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width; anchors.leftMargin: UM.Theme.getSize("default_margin").width;
anchors.top: headerSeparator.bottom anchors.top: headerSeparator.bottom