Ensure we're showing configurations when no available configurations in other extruder

This commit is contained in:
ChrisTerBeke 2019-08-28 23:19:23 +02:00
parent 189d873fc1
commit 7b45100dd0

View File

@ -13,6 +13,7 @@ from .ClusterBuildPlate import ClusterBuildPlate
from .ClusterPrintCoreConfiguration import ClusterPrintCoreConfiguration from .ClusterPrintCoreConfiguration import ClusterPrintCoreConfiguration
from .ClusterPrinterMaterialStation import ClusterPrinterMaterialStation from .ClusterPrinterMaterialStation import ClusterPrinterMaterialStation
from .ClusterPrinterMaterialStationSlot import ClusterPrinterMaterialStationSlot from .ClusterPrinterMaterialStationSlot import ClusterPrinterMaterialStationSlot
from .ClusterPrinterConfigurationMaterial import ClusterPrinterConfigurationMaterial
from ..BaseModel import BaseModel from ..BaseModel import BaseModel
@ -92,31 +93,34 @@ class ClusterPrinterStatus(BaseModel):
configuration.updateConfigurationModel(extruder_config) configuration.updateConfigurationModel(extruder_config)
def _updateAvailableConfigurations(self, model: PrinterOutputModel) -> None: def _updateAvailableConfigurations(self, model: PrinterOutputModel) -> None:
# Generate a list of configurations for the left extruder.
left_configurations = [slot for slot in self.material_station.material_slots if self._isSupportedConfiguration(
slot = slot,
extruder_index = 0
)]
# Generate a list of configurations for the right extruder.
right_configurations = [slot for slot in self.material_station.material_slots if self._isSupportedConfiguration(
slot = slot,
extruder_index = 1
)]
# Create a list of all available combinations between both print cores.
available_configurations = [self._createAvailableConfigurationFromPrinterConfiguration( available_configurations = [self._createAvailableConfigurationFromPrinterConfiguration(
left_slot = left_slot, left_slot = left_slot,
right_slot = right_slot, right_slot = right_slot,
printer_configuration = model.printerConfiguration printer_configuration = model.printerConfiguration
) for left_slot, right_slot in product(left_configurations, right_configurations)] ) for left_slot, right_slot in product(self._getSlotsForExtruder(0), self._getSlotsForExtruder(1))]
# Let Cura know which available configurations there are.
model.setAvailableConfigurations(available_configurations) model.setAvailableConfigurations(available_configurations)
## Create a list of Material Station slots for the given extruder index.
# Returns a list with a single empty material slot if none are found to ensure we don't miss configurations.
def _getSlotsForExtruder(self, extruder_index: int) -> List[ClusterPrinterMaterialStationSlot]:
slots = [slot for slot in self.material_station.material_slots if self._isSupportedConfiguration(
slot = slot,
extruder_index = extruder_index
)]
return slots or [self._createEmptyMaterialSlot(extruder_index)]
## Check if a configuration is supported in order to make it selectable by the user. ## Check if a configuration is supported in order to make it selectable by the user.
# We filter out any slot that is not supported by the extruder index, print core type or if the material is empty. # We filter out any slot that is not supported by the extruder index, print core type or if the material is empty.
@staticmethod @staticmethod
def _isSupportedConfiguration(slot: ClusterPrinterMaterialStationSlot, extruder_index: int) -> bool: def _isSupportedConfiguration(slot: ClusterPrinterMaterialStationSlot, extruder_index: int) -> bool:
return slot.extruder_index == extruder_index and slot.compatible and slot.material and \ return slot.extruder_index == extruder_index and slot.compatible and slot.material
slot.material_remaining != 0
## Create an empty material slot with a fake empty material.
@staticmethod
def _createEmptyMaterialSlot(extruder_index: int) -> ClusterPrinterMaterialStationSlot:
empty_material = ClusterPrinterConfigurationMaterial(guid = "", material = "empty", brand = "", color = "")
return ClusterPrinterMaterialStationSlot(slot_index = 0, extruder_index = extruder_index,
compatible = True, material_remaining = 0, material = empty_material)
@staticmethod @staticmethod
def _createAvailableConfigurationFromPrinterConfiguration(left_slot: ClusterPrinterMaterialStationSlot, def _createAvailableConfigurationFromPrinterConfiguration(left_slot: ClusterPrinterMaterialStationSlot,