Browse Source

CURA-4870 Add information of the current configuration selected in the active printer

Diego Prado Gesto 7 years ago
parent
commit
22b1c2127f
2 changed files with 30 additions and 4 deletions
  1. 2 3
      cura/PrinterOutputDevice.py
  2. 28 1
      cura/Settings/MachineManager.py

+ 2 - 3
cura/PrinterOutputDevice.py

@@ -193,9 +193,8 @@ class PrinterOutputDevice(QObject, OutputDevice):
         for printer in self._printers:
             printer.configurationChanged.connect(self._updateUniqueConfigurations)
 
-        # If at this point the list of unique configurations is empty, we force the calculation
-        if not self._unique_configurations:
-            self._updateUniqueConfigurations()
+        # At this point there may be non-updated configurations
+        self._updateUniqueConfigurations()
 
 
 ##  The current processing state of the backend.

+ 28 - 1
cura/Settings/MachineManager.py

@@ -27,9 +27,9 @@ from UM.Settings.InstanceContainer import InstanceContainer
 from UM.Settings.SettingFunction import SettingFunction
 from UM.Signal import postponeSignals, CompressTechnique
 
-
 from cura.QualityManager import QualityManager
 from cura.PrinterOutputDevice import PrinterOutputDevice
+from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
 from cura.Settings.ExtruderManager import ExtruderManager
 
 from .CuraStackBuilder import CuraStackBuilder
@@ -115,6 +115,12 @@ class MachineManager(QObject):
         # There might already be some output devices by the time the signal is connected
         self._onOutputDevicesChanged()
 
+        self._current_printer_configuration = ConfigurationModel()   # Indicates the current configuration setup in this printer
+        self.activeMaterialChanged.connect(self._onCurrentConfigurationChanged)
+        self.activeVariantChanged.connect(self._onCurrentConfigurationChanged)
+        # Force to compute the current configuration
+        self._onCurrentConfigurationChanged()
+
         if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
             # An active machine was saved, so restore it.
             self.setActiveMachine(active_machine_id)
@@ -146,6 +152,7 @@ class MachineManager(QObject):
     blurSettings = pyqtSignal()  # Emitted to force fields in the advanced sidebar to un-focus, so they update properly
 
     outputDevicesChanged = pyqtSignal()
+    currentConfigurationChanged = pyqtSignal() # Emitted every time the current configurations of the machine changes
 
     def _onOutputDevicesChanged(self) -> None:
         for printer_output_device in self._printer_output_devices:
@@ -161,6 +168,26 @@ class MachineManager(QObject):
 
         self.outputDevicesChanged.emit()
 
+    @pyqtProperty(QObject, notify = currentConfigurationChanged)
+    def currentConfiguration(self):
+        return self._current_printer_configuration
+
+    def _onCurrentConfigurationChanged(self) -> None:
+        if not self._global_container_stack:
+            return
+
+        self._printer_configuration.printerType = self._global_container_stack.definition.getName()
+        extruder_configurations = []
+        for extruder in self._global_container_stack.extruders:
+            extruder_configurations.append({
+                "position": len(extruder_configurations),
+                "material": extruder.material.getName() if extruder.material != self._empty_material_container else None,
+                "hotendID": extruder.variant.getName() if extruder.variant != self._empty_variant_container else None
+            })
+        self._printer_configuration.extruderConfigurations = extruder_configurations
+        self._printer_configuration.buildplateConfiguration = self._global_container_stack.variant.getName() if self._global_container_stack.variant is not None else None
+        self.currentConfigurationChanged.emit()
+
     @property
     def newVariant(self):
         return self._new_variant_container