mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-10 08:17:49 -06:00
Merge branch 'master' of github.com:Ultimaker/Cura
Conflicts: cura/MachineManagerModel.py
This commit is contained in:
commit
bcf7e0459b
3 changed files with 45 additions and 15 deletions
|
@ -10,6 +10,8 @@ import UM.Settings
|
|||
from UM.Settings.Validator import ValidatorState
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from . import ExtruderManager
|
||||
from UM.i18n import i18nCatalog
|
||||
catalog = i18nCatalog("cura")
|
||||
|
||||
class MachineManagerModel(QObject):
|
||||
def __init__(self, parent = None):
|
||||
|
@ -107,7 +109,7 @@ class MachineManagerModel(QObject):
|
|||
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id=definition_id)
|
||||
if definitions:
|
||||
definition = definitions[0]
|
||||
name = self._createUniqueStackName(name, definition.getName())
|
||||
name = self._createUniqueName("machine", name, definition.getName())
|
||||
|
||||
new_global_stack = UM.Settings.ContainerStack(name)
|
||||
new_global_stack.addMetaDataEntry("type", "machine")
|
||||
|
@ -145,7 +147,7 @@ class MachineManagerModel(QObject):
|
|||
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
||||
|
||||
# Create a name that is not empty and unique
|
||||
def _createUniqueStackName(self, name, fallback_name):
|
||||
def _createUniqueName(self, object_type, name, fallback_name):
|
||||
name = name.strip()
|
||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||
if(num_check):
|
||||
|
@ -156,10 +158,16 @@ class MachineManagerModel(QObject):
|
|||
i = 1
|
||||
|
||||
# Check both the id and the name, because they may not be the same and it is better if they are both unique
|
||||
if object_type == "machine":
|
||||
while UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = unique_name, type = "machine") or \
|
||||
UM.Settings.ContainerRegistry.getInstance().findContainerStacks(name = unique_name, type = "machine"):
|
||||
i += 1
|
||||
unique_name = "%s #%d" % (name, i)
|
||||
else:
|
||||
while UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = unique_name, type = object_type) or \
|
||||
UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(name = unique_name, type = object_type):
|
||||
i += 1
|
||||
unique_name = "%s #%d" % (name, i)
|
||||
|
||||
return unique_name
|
||||
|
||||
|
@ -259,7 +267,7 @@ class MachineManagerModel(QObject):
|
|||
if not self._global_container_stack:
|
||||
return
|
||||
|
||||
name = self._createUniqueStackName("Custom profile", "")
|
||||
name = self._createUniqueName("quality", self.activeQualityName, catalog.i18nc("@label", "Custom profile"))
|
||||
user_settings = self._global_container_stack.getTop()
|
||||
new_quality_container = InstanceContainer("")
|
||||
|
||||
|
@ -274,11 +282,12 @@ class MachineManagerModel(QObject):
|
|||
|
||||
## Change type / id / name
|
||||
new_quality_container.setMetaDataEntry("type", "quality")
|
||||
new_quality_container.setMetaDataEntry("read_only", False)
|
||||
new_quality_container.setName(name)
|
||||
new_quality_container._id = name
|
||||
|
||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_quality_container)
|
||||
self.clearUserSettings() # As all users settings are noq a quality, remove them.
|
||||
self.clearUserSettings() # As all users settings are now transfered to the new quality profile, remove them.
|
||||
self.setActiveQuality(name)
|
||||
return name
|
||||
|
||||
|
@ -288,7 +297,7 @@ class MachineManagerModel(QObject):
|
|||
return
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=container_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueStackName(containers[0].getName(), "")
|
||||
new_name = self._createUniqueName("quality", containers[0].getName(), catalog.i18nc("@label", "Custom profile"))
|
||||
|
||||
new_container = InstanceContainer("")
|
||||
|
||||
|
@ -302,6 +311,26 @@ class MachineManagerModel(QObject):
|
|||
|
||||
return ""
|
||||
|
||||
|
||||
@pyqtSlot(str)
|
||||
def removeQualityContainer(self, container_id):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||
if not containers or not self._global_container_stack:
|
||||
return
|
||||
|
||||
# If the container that is being removed is the currently active container, set another machine as the active container
|
||||
activate_new_container = container_id == self.activeQualityId
|
||||
|
||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(container_id)
|
||||
|
||||
if activate_new_container:
|
||||
old_container = self._global_container_stack.findInstanceContainers({"type": "quality"})
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = container_type)
|
||||
if containers and old_container:
|
||||
container_index = self._global_container_stack.getContainerIndex(old_container)
|
||||
self._global_container_stack.replaceContainer(container_index, containers[0])
|
||||
|
||||
|
||||
@pyqtSlot()
|
||||
def updateUserContainerToQuality(self):
|
||||
if not self._global_container_stack:
|
||||
|
@ -381,7 +410,7 @@ class MachineManagerModel(QObject):
|
|||
def renameMachine(self, machine_id, new_name):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||
if containers:
|
||||
new_name = self._createUniqueStackName(new_name, containers[0].getBottom().getName())
|
||||
new_name = self._createUniqueName("machine", new_name, containers[0].getBottom().getName())
|
||||
containers[0].setName(new_name)
|
||||
self.globalContainerChanged.emit()
|
||||
|
||||
|
|
|
@ -66,8 +66,8 @@ UM.ManagementPage
|
|||
|
||||
activateEnabled: currentItem != null ? currentItem.id != Cura.MachineManager.activeQualityId : false;
|
||||
addEnabled: currentItem != null;
|
||||
removeEnabled: currentItem != null ? !currentItem.readOnly : false;
|
||||
renameEnabled: currentItem != null ? !currentItem.readOnly : false;
|
||||
removeEnabled: currentItem != null ? !currentItem.metadata.read_only : false;
|
||||
renameEnabled: currentItem != null ? !currentItem.metadata.read_only : false;
|
||||
|
||||
scrollviewCaption: catalog.i18nc("@label %1 is printer name","Printer: %1").arg(Cura.MachineManager.activeMachineName)
|
||||
|
||||
|
@ -137,7 +137,7 @@ UM.ManagementPage
|
|||
Label {
|
||||
text: base.currentItem == null ? "" :
|
||||
base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName:
|
||||
base.currentItem.readOnly ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
|
||||
base.currentItem.metadata.read_only ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
|
||||
}
|
||||
|
||||
Column {
|
||||
|
@ -186,7 +186,7 @@ UM.ManagementPage
|
|||
{
|
||||
id: confirmDialog;
|
||||
object: base.currentItem != null ? base.currentItem.name : "";
|
||||
onYes: base.model.removeProfile(base.currentItem.name);
|
||||
onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id);
|
||||
}
|
||||
UM.RenameDialog
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ ScrollView
|
|||
{
|
||||
id: contents
|
||||
spacing: UM.Theme.getSize("default_lining").height;
|
||||
cacheBuffer: 1000000; // A huge to cache to effectively cache everything.
|
||||
|
||||
model: UM.SettingDefinitionsModel {
|
||||
id: definitionsModel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue