mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
selected printer is active printer in UCP
CURA-11403
This commit is contained in:
parent
f19320cad8
commit
c879809836
4 changed files with 44 additions and 19 deletions
|
@ -5,7 +5,7 @@
|
||||||
# online cloud connected printers are represented within this ListModel. Additional information such as the number of
|
# online cloud connected printers are represented within this ListModel. Additional information such as the number of
|
||||||
# connected printers for each printer type is gathered.
|
# connected printers for each printer type is gathered.
|
||||||
|
|
||||||
from typing import Optional, List, cast
|
from typing import Optional, List, cast, Dict, Any
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
|
|
||||||
|
@ -159,3 +159,8 @@ class MachineListModel(ListModel):
|
||||||
"machineCount": machine_count,
|
"machineCount": machine_count,
|
||||||
"catergory": "connected" if is_online else "other",
|
"catergory": "connected" if is_online else "other",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def getItems(self) -> Dict[str, Any]:
|
||||||
|
if self.count > 0:
|
||||||
|
return self.items
|
||||||
|
return {}
|
|
@ -144,14 +144,12 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
self._old_new_materials: Dict[str, str] = {}
|
self._old_new_materials: Dict[str, str] = {}
|
||||||
self._machine_info = None
|
self._machine_info = None
|
||||||
|
|
||||||
self._load_profile = False
|
|
||||||
self._user_settings: Dict[str, Dict[str, Any]] = {}
|
self._user_settings: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
def _clearState(self):
|
def _clearState(self):
|
||||||
self._id_mapping = {}
|
self._id_mapping = {}
|
||||||
self._old_new_materials = {}
|
self._old_new_materials = {}
|
||||||
self._machine_info = None
|
self._machine_info = None
|
||||||
self._load_profile = False
|
|
||||||
self._user_settings = {}
|
self._user_settings = {}
|
||||||
|
|
||||||
def setOpenAsUcp(self, openAsUcp: bool):
|
def setOpenAsUcp(self, openAsUcp: bool):
|
||||||
|
@ -212,11 +210,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
return global_stack_file_list[0], extruder_stack_file_list
|
return global_stack_file_list[0], extruder_stack_file_list
|
||||||
|
|
||||||
def preRead(self, file_name, show_dialog=True, *args, **kwargs):
|
def preRead(self, file_name, show_dialog=True, *args, **kwargs):
|
||||||
result = self._preRead(file_name, show_dialog)
|
|
||||||
self._is_ucp = False
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _preRead(self, file_name, show_dialog=True):
|
|
||||||
"""Read some info so we can make decisions
|
"""Read some info so we can make decisions
|
||||||
|
|
||||||
:param file_name:
|
:param file_name:
|
||||||
|
@ -618,11 +611,13 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
|
|
||||||
# Load the user specifically exported settings
|
# Load the user specifically exported settings
|
||||||
self._dialog.exportedSettingModel.clear()
|
self._dialog.exportedSettingModel.clear()
|
||||||
|
self._dialog.setCurrentMachineName("")
|
||||||
if self._is_ucp:
|
if self._is_ucp:
|
||||||
try:
|
try:
|
||||||
self._user_settings = json.loads(archive.open("Cura/user-settings.json").read().decode("utf-8"))
|
self._user_settings = json.loads(archive.open("Cura/user-settings.json").read().decode("utf-8"))
|
||||||
any_extruder_stack = ExtruderManager.getInstance().getExtruderStack(0)
|
any_extruder_stack = ExtruderManager.getInstance().getExtruderStack(0)
|
||||||
actual_global_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
actual_global_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
|
self._dialog.setCurrentMachineName(actual_global_stack.id)
|
||||||
|
|
||||||
for stack_name, settings in self._user_settings.items():
|
for stack_name, settings in self._user_settings.items():
|
||||||
if stack_name == 'global':
|
if stack_name == 'global':
|
||||||
|
@ -675,7 +670,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# Choosing the initially selected printer in MachineSelector
|
# Choosing the initially selected printer in MachineSelector
|
||||||
is_networked_machine = False
|
is_networked_machine = False
|
||||||
is_abstract_machine = False
|
is_abstract_machine = False
|
||||||
if global_stack and isinstance(global_stack, GlobalStack):
|
if global_stack and isinstance(global_stack, GlobalStack) and not self._is_ucp:
|
||||||
# The machine included in the project file exists locally already, no need to change selected printers.
|
# The machine included in the project file exists locally already, no need to change selected printers.
|
||||||
is_networked_machine = global_stack.hasNetworkedConnection()
|
is_networked_machine = global_stack.hasNetworkedConnection()
|
||||||
is_abstract_machine = parseBool(existing_global_stack.getMetaDataEntry("is_abstract_machine", False))
|
is_abstract_machine = parseBool(existing_global_stack.getMetaDataEntry("is_abstract_machine", False))
|
||||||
|
@ -684,7 +679,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
elif self._dialog.updatableMachinesModel.count > 0:
|
elif self._dialog.updatableMachinesModel.count > 0:
|
||||||
# The machine included in the project file does not exist. There is another machine of the same type.
|
# The machine included in the project file does not exist. There is another machine of the same type.
|
||||||
# This will always default to an abstract machine first.
|
# This will always default to an abstract machine first.
|
||||||
machine = self._dialog.updatableMachinesModel.getItem(0)
|
machine = self._dialog.updatableMachinesModel.getItem(self._dialog.currentMachinePositionIndex)
|
||||||
machine_name = machine["name"]
|
machine_name = machine["name"]
|
||||||
is_networked_machine = machine["isNetworked"]
|
is_networked_machine = machine["isNetworked"]
|
||||||
is_abstract_machine = machine["isAbstractMachine"]
|
is_abstract_machine = machine["isAbstractMachine"]
|
||||||
|
@ -709,8 +704,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
if self._dialog.getResult() == {}:
|
if self._dialog.getResult() == {}:
|
||||||
return WorkspaceReader.PreReadResult.cancelled
|
return WorkspaceReader.PreReadResult.cancelled
|
||||||
|
|
||||||
self._load_profile = not self._is_ucp
|
|
||||||
|
|
||||||
self._resolve_strategies = self._dialog.getResult()
|
self._resolve_strategies = self._dialog.getResult()
|
||||||
#
|
#
|
||||||
# There can be 3 resolve strategies coming from the dialog:
|
# There can be 3 resolve strategies coming from the dialog:
|
||||||
|
@ -832,7 +825,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
for stack in extruder_stacks:
|
for stack in extruder_stacks:
|
||||||
stack.setNextStack(global_stack, connect_signals = False)
|
stack.setNextStack(global_stack, connect_signals = False)
|
||||||
|
|
||||||
if self._load_profile:
|
if not self._is_ucp:
|
||||||
Logger.log("d", "Workspace loading is checking definitions...")
|
Logger.log("d", "Workspace loading is checking definitions...")
|
||||||
# Get all the definition files & check if they exist. If not, add them.
|
# Get all the definition files & check if they exist. If not, add them.
|
||||||
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
|
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
|
||||||
|
@ -906,7 +899,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
|
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
|
||||||
|
|
||||||
if global_stack:
|
if global_stack:
|
||||||
if self._load_profile:
|
if not self._is_ucp:
|
||||||
# Handle quality changes if any
|
# Handle quality changes if any
|
||||||
self._processQualityChanges(global_stack)
|
self._processQualityChanges(global_stack)
|
||||||
|
|
||||||
|
@ -914,7 +907,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
self._applyChangesToMachine(global_stack, extruder_stack_dict)
|
self._applyChangesToMachine(global_stack, extruder_stack_dict)
|
||||||
else:
|
else:
|
||||||
# Just clear the settings now, so that we can change the active machine without conflicts
|
# Just clear the settings now, so that we can change the active machine without conflicts
|
||||||
self._clearMachineSettings(global_stack, extruder_stack_dict)
|
self._clearMachineSettings(global_stack, {})
|
||||||
|
|
||||||
|
|
||||||
Logger.log("d", "Workspace loading is notifying rest of the code of changes...")
|
Logger.log("d", "Workspace loading is notifying rest of the code of changes...")
|
||||||
# Actually change the active machine.
|
# Actually change the active machine.
|
||||||
|
@ -924,9 +918,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# function is running on the main thread (Qt thread), although those "changed" signals have been emitted, but
|
# function is running on the main thread (Qt thread), although those "changed" signals have been emitted, but
|
||||||
# they won't take effect until this function is done.
|
# they won't take effect until this function is done.
|
||||||
# To solve this, we schedule _updateActiveMachine() for later so it will have the latest data.
|
# To solve this, we schedule _updateActiveMachine() for later so it will have the latest data.
|
||||||
|
|
||||||
self._updateActiveMachine(global_stack)
|
self._updateActiveMachine(global_stack)
|
||||||
|
|
||||||
if not self._load_profile:
|
if self._is_ucp:
|
||||||
# Now we have switched, apply the user settings
|
# Now we have switched, apply the user settings
|
||||||
self._applyUserSettings(global_stack, extruder_stack_dict, self._user_settings)
|
self._applyUserSettings(global_stack, extruder_stack_dict, self._user_settings)
|
||||||
|
|
||||||
|
@ -938,6 +933,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
base_file_name = os.path.basename(file_name)
|
base_file_name = os.path.basename(file_name)
|
||||||
self.setWorkspaceName(base_file_name)
|
self.setWorkspaceName(base_file_name)
|
||||||
|
|
||||||
|
self._is_ucp = False
|
||||||
return nodes, self._loadMetadata(file_name)
|
return nodes, self._loadMetadata(file_name)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1320,7 +1316,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
if key not in global_stack.getMetaData() and key not in _ignored_machine_network_metadata:
|
if key not in global_stack.getMetaData() and key not in _ignored_machine_network_metadata:
|
||||||
global_stack.setMetaDataEntry(key, value)
|
global_stack.setMetaDataEntry(key, value)
|
||||||
|
|
||||||
if self._quality_changes_to_apply:
|
if self._quality_changes_to_apply !=None:
|
||||||
quality_changes_group_list = container_tree.getCurrentQualityChangesGroups()
|
quality_changes_group_list = container_tree.getCurrentQualityChangesGroups()
|
||||||
quality_changes_group = next((qcg for qcg in quality_changes_group_list if qcg.name == self._quality_changes_to_apply), None)
|
quality_changes_group = next((qcg for qcg in quality_changes_group_list if qcg.name == self._quality_changes_to_apply), None)
|
||||||
if not quality_changes_group:
|
if not quality_changes_group:
|
||||||
|
|
|
@ -63,6 +63,7 @@ class WorkspaceDialog(QObject):
|
||||||
self._machine_name = ""
|
self._machine_name = ""
|
||||||
self._machine_type = ""
|
self._machine_type = ""
|
||||||
self._variant_type = ""
|
self._variant_type = ""
|
||||||
|
self._current_machine_name = ""
|
||||||
self._material_labels = []
|
self._material_labels = []
|
||||||
self._extruders = []
|
self._extruders = []
|
||||||
self._objects_on_plate = False
|
self._objects_on_plate = False
|
||||||
|
@ -76,6 +77,7 @@ class WorkspaceDialog(QObject):
|
||||||
self._is_compatible_machine = False
|
self._is_compatible_machine = False
|
||||||
self._allow_create_machine = True
|
self._allow_create_machine = True
|
||||||
self._exported_settings_model = SpecificSettingsModel()
|
self._exported_settings_model = SpecificSettingsModel()
|
||||||
|
self._current_machine_pos_index = 0
|
||||||
self._is_ucp = False
|
self._is_ucp = False
|
||||||
|
|
||||||
machineConflictChanged = pyqtSignal()
|
machineConflictChanged = pyqtSignal()
|
||||||
|
@ -174,11 +176,33 @@ class WorkspaceDialog(QObject):
|
||||||
self._machine_name = machine_name
|
self._machine_name = machine_name
|
||||||
self.machineNameChanged.emit()
|
self.machineNameChanged.emit()
|
||||||
|
|
||||||
|
def setCurrentMachineName(self, machine: str) -> None:
|
||||||
|
self._current_machine_name = machine
|
||||||
|
|
||||||
|
@pyqtProperty(str, notify = machineNameChanged)
|
||||||
|
def currentMachineName(self) -> str:
|
||||||
|
return self._current_machine_name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getIndexOfCurrentMachine(list_of_dicts, key, value):
|
||||||
|
for i, d in enumerate(list_of_dicts):
|
||||||
|
if d.get(key) == value: # found the dictionary
|
||||||
|
return i;
|
||||||
|
return 0
|
||||||
|
|
||||||
|
@pyqtProperty(int, notify = machineNameChanged)
|
||||||
|
def currentMachinePositionIndex(self):
|
||||||
|
return self._current_machine_pos_index
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify = updatableMachinesChanged)
|
@pyqtProperty(QObject, notify = updatableMachinesChanged)
|
||||||
def updatableMachinesModel(self) -> MachineListModel:
|
def updatableMachinesModel(self) -> MachineListModel:
|
||||||
|
if self._current_machine_name != "":
|
||||||
|
self._current_machine_pos_index = self.getIndexOfCurrentMachine(self._updatable_machines_model.getItems(), "id", self._current_machine_name)
|
||||||
|
else:
|
||||||
|
self._current_machine_pos_index = 0
|
||||||
return cast(MachineListModel, self._updatable_machines_model)
|
return cast(MachineListModel, self._updatable_machines_model)
|
||||||
|
|
||||||
def setUpdatableMachines(self, updatable_machines: List[GlobalStack]) -> None:
|
def setUpdatableMachines(self, updatable_machines: List[GlobalStack], current_machine=None) -> None:
|
||||||
self._updatable_machines_model.set_machines_filter(updatable_machines)
|
self._updatable_machines_model.set_machines_filter(updatable_machines)
|
||||||
self.updatableMachinesChanged.emit()
|
self.updatableMachinesChanged.emit()
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ UM.Dialog
|
||||||
WorkspaceRow
|
WorkspaceRow
|
||||||
{
|
{
|
||||||
leftLabelText: catalog.i18nc("@action:label", manager.isPrinterGroup ? "Printer Group" : "Printer Name")
|
leftLabelText: catalog.i18nc("@action:label", manager.isPrinterGroup ? "Printer Group" : "Printer Name")
|
||||||
rightLabelText: manager.machineName == catalog.i18nc("@button", "Create new") ? "" : manager.machineName
|
rightLabelText: manager.isUcp? manager.machineType: manager.machineName == catalog.i18nc("@button", "Create new") ? "" : manager.machineName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue