Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only onine printers in print via cloud #16460

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions cura/Machines/Models/CompatibleMachineModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from UM.Qt.ListModel import ListModel
from UM.i18n import i18nCatalog


class CompatibleMachineModel(ListModel):
NameRole = Qt.ItemDataRole.UserRole + 1
UniqueIdRole = Qt.ItemDataRole.UserRole + 2
Expand Down Expand Up @@ -47,37 +46,36 @@ def _makeMaterial(brand, name, color):
from cura.CuraApplication import CuraApplication
machine_manager = CuraApplication.getInstance().getMachineManager()

online_printers = machine_manager.checkOnlinePrinters()
# Loop over the output-devices, not the stacks; need all applicable configurations, not just the current loaded one.
for output_device in machine_manager.printerOutputDevices:
for printer in output_device.printers:
extruder_configs = dict()

# initialize & add current active material:
for extruder in printer.extruders:
if not extruder.activeMaterial:
for printer in online_printers:
extruder_configs = dict()
# initialize & add current active material:
for extruder in printer.extruders:
if not extruder.activeMaterial:
continue
materials = [_makeMaterial(
extruder.activeMaterial.brand, extruder.activeMaterial.name, extruder.activeMaterial.color)]
extruder_configs[extruder.getPosition()] = {
"position": extruder.getPosition(),
"core": extruder.hotendID,
"materials": materials
}

# add currently inactive, but possible materials:
for configuration in printer.availableConfigurations:
for extruder in configuration.extruderConfigurations:
if not extruder.position in extruder_configs:
Logger.log("w", f"No active extruder for position {extruder.position}.")
continue
materials = [_makeMaterial(
extruder.activeMaterial.brand, extruder.activeMaterial.name, extruder.activeMaterial.color)]
extruder_configs[extruder.getPosition()] = {
"position": extruder.getPosition(),
"core": extruder.hotendID,
"materials": materials
}

# add currently inactive, but possible materials:
for configuration in printer.availableConfigurations:
for extruder in configuration.extruderConfigurations:
if not extruder.position in extruder_configs:
Logger.log("w", f"No active extruder for position {extruder.position}.")
continue

entry = _makeMaterial(extruder.material.brand, extruder.material.name, extruder.material.color)
if entry not in extruder_configs[extruder.position]["materials"]:
extruder_configs[extruder.position]["materials"].append(entry)

if any([len(extruder["materials"]) > 0 for extruder in extruder_configs.values()]):
self.appendItem({
"name": printer.name,
"unique_id": printer.name, # <- Can assume the cloud doesn't have duplicate names?
"extruders": list(extruder_configs.values())
})

entry = _makeMaterial(extruder.material.brand, extruder.material.name, extruder.material.color)
if entry not in extruder_configs[extruder.position]["materials"]:
extruder_configs[extruder.position]["materials"].append(entry)

if any([len(extruder["materials"]) > 0 for extruder in extruder_configs.values()]):
self.appendItem({
"name": printer.name,
"unique_id": printer.name, # <- Can assume the cloud doesn't have duplicate names?
"extruders": list(extruder_configs.values())
})
11 changes: 11 additions & 0 deletions cura/PrinterOutput/Models/PrinterOutputModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PrinterOutputModel(QObject):
cameraUrlChanged = pyqtSignal()
configurationChanged = pyqtSignal()
canUpdateFirmwareChanged = pyqtSignal()
isOnlineChanged =pyqtSignal()

def __init__(self, output_controller: "PrinterOutputController", number_of_extruders: int = 1, parent=None, firmware_version = "") -> None:
super().__init__(parent)
Expand All @@ -47,6 +48,7 @@ def __init__(self, output_controller: "PrinterOutputController", number_of_extru
self._is_preheating = False
self._printer_type = ""
self._buildplate = ""
self._is_online = False
self._peripherals = [] # type: List[Peripheral]

self._active_printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
Expand Down Expand Up @@ -78,6 +80,15 @@ def updateIsPreheating(self, pre_heating: bool) -> None:
def isPreheating(self) -> bool:
return self._is_preheating

def printerIsOnline(self, is_online: bool) -> None:
if self._is_online != is_online:
self._is_online = is_online
self.isOnlineChanged.emit()

@pyqtProperty(bool, notify=isOnlineChanged)
def isOnline(self) -> bool:
return self._is_online

@pyqtProperty(str, notify = typeChanged)
def type(self) -> str:
return self._printer_type
Expand Down
17 changes: 17 additions & 0 deletions cura/Settings/MachineManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ def getMachinesWithDefinition(self, definition_id: str, online_only=False) -> Li

return list(machines)

def checkOnlinePrinters(self):

from cura.CuraApplication import CuraApplication # In function to avoid circular import
application = CuraApplication.getInstance()
registry = application.getContainerRegistry()
machines_online = []
for n in self._printer_output_devices:
for machine in n.printers:
machine_ = registry.findContainerStacks(id=machine.name)
if parseBool(machine_[0].getMetaDataEntry("is_online")):
machine.printerIsOnline(True)
machines_online.append(machine)
else:
machine.printerIsOnline(False)

return machines_online

@pyqtProperty(QObject, notify = currentConfigurationChanged)
def currentConfiguration(self) -> PrinterConfigurationModel:
return self._current_printer_configuration
Expand Down
Loading