Browse Source

Made backend available in qml, calling forceSlice and stopSlicing directly. CURA-3214

Jack Ha 8 years ago
parent
commit
464bf73f85

+ 6 - 0
cura/CuraApplication.py

@@ -670,6 +670,12 @@ class CuraApplication(QtApplication):
 
 
             qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
             qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
 
 
+    ##  Get the backend of the application (the program that does the heavy lifting).
+    #   \returns Backend \type{Backend}
+    @pyqtSlot(result = "QObject*")
+    def getBackend(self):
+        return self._backend
+
     def onSelectionChanged(self):
     def onSelectionChanged(self):
         if Selection.hasSelection():
         if Selection.hasSelection():
             if self.getController().getActiveTool():
             if self.getController().getActiveTool():

+ 12 - 9
plugins/CuraEngineBackend/CuraEngineBackend.py

@@ -13,6 +13,7 @@ from UM.Resources import Resources
 from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then.
 from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then.
 from UM.Platform import Platform
 from UM.Platform import Platform
 from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
 from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
+from PyQt5.QtCore import QObject, pyqtSlot
 
 
 
 
 from cura.Settings.ExtruderManager import ExtruderManager
 from cura.Settings.ExtruderManager import ExtruderManager
@@ -30,7 +31,7 @@ import Arcus
 from UM.i18n import i18nCatalog
 from UM.i18n import i18nCatalog
 catalog = i18nCatalog("cura")
 catalog = i18nCatalog("cura")
 
 
-class CuraEngineBackend(Backend):
+class CuraEngineBackend(QObject, Backend):
     ##  Starts the back-end plug-in.
     ##  Starts the back-end plug-in.
     #
     #
     #   This registers all the signal listeners and prepares for communication
     #   This registers all the signal listeners and prepares for communication
@@ -146,6 +147,7 @@ class CuraEngineBackend(Backend):
     ##  Emitted when the slicing process is aborted forcefully.
     ##  Emitted when the slicing process is aborted forcefully.
     slicingCancelled = Signal()
     slicingCancelled = Signal()
 
 
+    @pyqtSlot()
     def stopSlicing(self):
     def stopSlicing(self):
         self.backendStateChange.emit(BackendState.NotStarted)
         self.backendStateChange.emit(BackendState.NotStarted)
         if self._slicing:  # We were already slicing. Stop the old job.
         if self._slicing:  # We were already slicing. Stop the old job.
@@ -159,6 +161,14 @@ class CuraEngineBackend(Backend):
         if self._error_message:
         if self._error_message:
             self._error_message.hide()
             self._error_message.hide()
 
 
+    ##  Manually triggers a reslice
+    @pyqtSlot()
+    def forceSlice(self):
+        if self._use_timer:
+            self._change_timer.start()
+        else:
+            self.slice()
+
     ##  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...")
@@ -449,13 +459,6 @@ class CuraEngineBackend(Backend):
     def _createSocket(self):
     def _createSocket(self):
         super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")))
         super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")))
 
 
-    ##  Manually triggers a reslice
-    def forceSlice(self):
-        if self._use_timer:
-            self._change_timer.start()
-        else:
-            self.slice()
-
     ##  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.
@@ -578,4 +581,4 @@ class CuraEngineBackend(Backend):
             return
             return
         auto_slice = self.determineAutoSlicing()
         auto_slice = self.determineAutoSlicing()
         if auto_slice:
         if auto_slice:
-            self._change_timer.start()
+            self._change_timer.start()

+ 3 - 4
resources/qml/SaveButton.qml

@@ -133,12 +133,11 @@ Item {
             text: [1, 5].indexOf(UM.Backend.state) != -1 ? catalog.i18nc("@label:Printjob", "Prepare") : catalog.i18nc("@label:Printjob", "Cancel")
             text: [1, 5].indexOf(UM.Backend.state) != -1 ? catalog.i18nc("@label:Printjob", "Prepare") : catalog.i18nc("@label:Printjob", "Cancel")
             onClicked:
             onClicked:
             {
             {
+                var backend = CuraApplication.getBackend()
                 if ([1, 5].indexOf(UM.Backend.state) != -1) {
                 if ([1, 5].indexOf(UM.Backend.state) != -1) {
-                    CuraApplication.log("Prepare....");
-                    CuraApplication.slice();
+                    backend.forceSlice();
                 } else {
                 } else {
-                    CuraApplication.log("Cancel....");
-                    CuraApplication.sliceStop();
+                    backend.stopSlicing();
                 }
                 }
             }
             }