mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-23 22:54:01 -06:00
D5: Refactoring
This commit is contained in:
parent
ce9251b5a6
commit
1631045d7a
10 changed files with 69 additions and 43 deletions
|
@ -19,6 +19,7 @@ from UM.SaveFile import SaveFile
|
|||
from UM.Scene.Selection import Selection
|
||||
from UM.Scene.GroupDecorator import GroupDecorator
|
||||
from UM.Settings.Validator import Validator
|
||||
from UM.Message import Message
|
||||
|
||||
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
||||
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
|
||||
|
@ -32,6 +33,7 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
|
|||
from UM.Settings.SettingFunction import SettingFunction
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
from . import PlatformPhysics
|
||||
from . import BuildVolume
|
||||
|
@ -289,6 +291,8 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self._recent_files.append(QUrl.fromLocalFile(f))
|
||||
|
||||
self.changeLayerViewSignal.connect(self.changeToLayerView)
|
||||
|
||||
def _onEngineCreated(self):
|
||||
self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider())
|
||||
|
||||
|
@ -536,31 +540,45 @@ class CuraApplication(QtApplication):
|
|||
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
|
||||
|
||||
loadingFiles = []
|
||||
non_sliceable_extensions = [".gcode", ".g"]
|
||||
|
||||
changeLayerViewSignal = pyqtSignal()
|
||||
|
||||
def changeToLayerView(self):
|
||||
self.getController().setActiveView("LayerView")
|
||||
|
||||
@pyqtSlot(QUrl)
|
||||
def loadFile(self, file):
|
||||
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():
|
||||
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()
|
||||
extension = os.path.splitext(f)[1]
|
||||
filename = os.path.basename(f)
|
||||
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
|
||||
# If file being loaded is non-slicable file, then prevent loading of any other files
|
||||
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
|
||||
elif extension.lower() in supported_extensions:
|
||||
self.getController().setActiveView("LayerView")
|
||||
|
||||
self.loadingFiles.append(f)
|
||||
|
||||
|
@ -570,12 +588,17 @@ class CuraApplication(QtApplication):
|
|||
|
||||
def _readMeshFinished(self, job):
|
||||
node = job.getResult()
|
||||
if node != None:
|
||||
filename = job.getFileName()
|
||||
node.setSelectable(True)
|
||||
node.setName(filename)
|
||||
self.loadingFiles.remove(filename)
|
||||
|
||||
if node != None:
|
||||
node.setSelectable(True)
|
||||
node.setName(os.path.basename(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.push()
|
||||
|
||||
|
@ -1056,14 +1079,14 @@ class CuraApplication(QtApplication):
|
|||
|
||||
_hide_settings = False
|
||||
|
||||
HideSettingsChanged = pyqtSignal(bool)
|
||||
hideSettingsChanged = pyqtSignal(bool)
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def setHideSettings(self, 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):
|
||||
return self._hide_settings
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@ import math
|
|||
import os.path
|
||||
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
|
||||
#
|
||||
# This class contains all the logic relating to calculation and slicing for the
|
||||
|
@ -66,7 +69,7 @@ class PrintInformation(QObject):
|
|||
preSlicedChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(bool, notify=preSlicedChanged)
|
||||
def isPreSliced(self):
|
||||
def preSliced(self):
|
||||
return self._pre_sliced
|
||||
|
||||
def setPreSliced(self, pre_sliced):
|
||||
|
@ -134,10 +137,8 @@ class PrintInformation(QObject):
|
|||
def createJobName(self, base_name):
|
||||
base_name = self._stripAccents(base_name)
|
||||
self._setAbbreviatedMachineName()
|
||||
if len(base_name) > 100:
|
||||
base_name = "%s..." % base_name[:100]
|
||||
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"):
|
||||
return self._abbr_machine + "_" + base_name
|
||||
else:
|
||||
|
|
|
@ -69,7 +69,7 @@ class CuraEngineBackend(Backend):
|
|||
self._scene = Application.getInstance().getController().getScene()
|
||||
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.
|
||||
self._layer_view_active = False
|
||||
|
@ -116,6 +116,7 @@ class CuraEngineBackend(Backend):
|
|||
|
||||
self.backendQuit.connect(self._onBackendQuit)
|
||||
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.
|
||||
Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
|
||||
|
@ -152,7 +153,7 @@ class CuraEngineBackend(Backend):
|
|||
## Perform a slice of the scene.
|
||||
def slice(self):
|
||||
Logger.log("d", "Starting slice job...")
|
||||
if self._pauseSlicing:
|
||||
if self._pause_slicing:
|
||||
return
|
||||
self._slice_start_time = time()
|
||||
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.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.
|
||||
def _terminate(self):
|
||||
self._slicing = False
|
||||
|
@ -397,14 +404,12 @@ 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.
|
||||
#
|
||||
# This indicates that we should probably re-slice soon.
|
||||
def _onChanged(self, *args, **kwargs):
|
||||
if not self._pauseSlicing:
|
||||
self._change_timer.start()
|
||||
|
||||
## Called when the back-end connects to the front-end.
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -10,6 +10,7 @@ from UM.Math.AxisAlignedBox import AxisAlignedBox
|
|||
from UM.Application import Application
|
||||
from UM.Message import Message
|
||||
from UM.Logger import Logger
|
||||
from UM.Backend.Backend import BackendState
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
@ -67,11 +68,11 @@ class GCodeReader(MeshReader):
|
|||
backend = Application.getInstance().getBackend()
|
||||
if self.scene_node is not None and self.scene_node.getParent() is None:
|
||||
self.scene_node = None
|
||||
backend._pauseSlicing = False
|
||||
backend.backendStateChange.emit(BackendState.NotStarted)
|
||||
Application.getInstance().setHideSettings(False)
|
||||
Application.getInstance().getPrintInformation().setPreSliced(False)
|
||||
else:
|
||||
backend._pauseSlicing = True
|
||||
backend.backendStateChange.emit(BackendState.SlicingDisabled)
|
||||
Application.getInstance().getPrintInformation().setPreSliced(True)
|
||||
Application.getInstance().setHideSettings(True)
|
||||
|
||||
|
@ -135,9 +136,8 @@ class GCodeReader(MeshReader):
|
|||
self.scene_node.parentChanged.connect(self.onParentChanged)
|
||||
|
||||
backend = Application.getInstance().getBackend()
|
||||
backend._pauseSlicing = True
|
||||
backend.close()
|
||||
backend.backendStateChange.emit(3)
|
||||
backend.backendStateChange.emit(BackendState.SlicingDisabled)
|
||||
|
||||
glist = getattr(Application.getInstance().getController().getScene(), "gcode_list")
|
||||
glist.clear()
|
||||
|
|
|
@ -4,21 +4,21 @@
|
|||
from . import GCodeReader
|
||||
|
||||
from UM.i18n import i18nCatalog
|
||||
i18n_catalog = i18nCatalog("uranium")
|
||||
i18n_catalog = i18nCatalog("cura")
|
||||
|
||||
def getMetaData():
|
||||
return {
|
||||
"plugin": {
|
||||
"name": i18n_catalog.i18nc("@label", "GCODE Reader"),
|
||||
"name": i18n_catalog.i18nc("@label", "G-code Reader"),
|
||||
"author": "Victor Larchenko",
|
||||
"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
|
||||
},
|
||||
"mesh_reader": [
|
||||
{
|
||||
"extension": "gcode",
|
||||
"description": i18n_catalog.i18nc("@item:inlistbox", "GCODE File")
|
||||
"description": i18n_catalog.i18nc("@item:inlistbox", "G-code File")
|
||||
},
|
||||
{
|
||||
"extension": "g",
|
||||
|
|
|
@ -412,7 +412,7 @@ UM.MainWindow
|
|||
|
||||
style: UM.Theme.styles.tool_button;
|
||||
tooltip: "";
|
||||
enabled: !PrintInformation.isPreSliced
|
||||
enabled: !PrintInformation.preSliced
|
||||
menu: ViewMenu { }
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Menu
|
|||
{
|
||||
title: catalog.i18nc("@title:menu menubar:toplevel", "&View");
|
||||
id: menu
|
||||
enabled: !PrintInformation.isPreSliced
|
||||
enabled: !PrintInformation.preSliced
|
||||
Instantiator
|
||||
{
|
||||
model: UM.ViewModel { }
|
||||
|
|
|
@ -14,7 +14,6 @@ Rectangle {
|
|||
|
||||
property real progress: UM.Backend.progress;
|
||||
property int backendState: UM.Backend.state;
|
||||
property bool backendPaused: UM.Backend.paused;
|
||||
property bool activity: Printer.getPlatformActivity;
|
||||
property int totalHeight: childrenRect.height + UM.Theme.getSize("default_margin").height
|
||||
property string fileBaseName
|
||||
|
@ -25,11 +24,6 @@ Rectangle {
|
|||
return catalog.i18nc("@label:PrintjobStatus", "Please load a 3d model");
|
||||
}
|
||||
|
||||
if (backendPaused)
|
||||
{
|
||||
return catalog.i18nc("@label:PrintjobStatus", "Slicing temporary disabled");
|
||||
}
|
||||
|
||||
switch(base.backendState)
|
||||
{
|
||||
case 1:
|
||||
|
@ -40,6 +34,8 @@ Rectangle {
|
|||
return catalog.i18nc("@label:PrintjobStatus %1 is target operation","Ready to %1").arg(UM.OutputDeviceManager.activeDeviceShortDescription);
|
||||
case 4:
|
||||
return catalog.i18nc("@label:PrintjobStatus", "Unable to Slice");
|
||||
case 5:
|
||||
return catalog.i18nc("@label:PrintjobStatus", "Slicing unavailable");
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ Rectangle
|
|||
|
||||
Label {
|
||||
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.leftMargin: UM.Theme.getSize("default_margin").width;
|
||||
anchors.top: headerSeparator.bottom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue