mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-15 15:38:02 +08:00
Adds way to convert user settings into quality settings
CURA-1585
This commit is contained in:
parent
4fc565711d
commit
d29cc37d6b
@ -8,6 +8,7 @@ from UM.Logger import Logger
|
|||||||
|
|
||||||
import UM.Settings
|
import UM.Settings
|
||||||
from UM.Settings.Validator import ValidatorState
|
from UM.Settings.Validator import ValidatorState
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
|
||||||
class MachineManagerModel(QObject):
|
class MachineManagerModel(QObject):
|
||||||
@ -80,7 +81,7 @@ class MachineManagerModel(QObject):
|
|||||||
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id=definition_id)
|
definitions = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id=definition_id)
|
||||||
if definitions:
|
if definitions:
|
||||||
definition = definitions[0]
|
definition = definitions[0]
|
||||||
name = self._uniqueMachineName(name, definition.getName())
|
name = self._createUniqueStackName(name, definition.getName())
|
||||||
|
|
||||||
new_global_stack = UM.Settings.ContainerStack(name)
|
new_global_stack = UM.Settings.ContainerStack(name)
|
||||||
new_global_stack.addMetaDataEntry("type", "machine")
|
new_global_stack.addMetaDataEntry("type", "machine")
|
||||||
@ -150,7 +151,7 @@ class MachineManagerModel(QObject):
|
|||||||
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
||||||
|
|
||||||
# Create a name that is not empty and unique
|
# Create a name that is not empty and unique
|
||||||
def _uniqueMachineName(self, name, fallback_name):
|
def _createUniqueStackName(self, name, fallback_name):
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||||
if(num_check):
|
if(num_check):
|
||||||
@ -160,10 +161,10 @@ class MachineManagerModel(QObject):
|
|||||||
unique_name = name
|
unique_name = name
|
||||||
i = 1
|
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
|
# Check both the id and the name, because they may not be the same and it is better if they are both unique
|
||||||
while UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = unique_name) or \
|
while UM.Settings.ContainerRegistry.getInstance().findContainers(None, id = unique_name) or \
|
||||||
UM.Settings.ContainerRegistry.getInstance().findContainers(None, name = unique_name):
|
UM.Settings.ContainerRegistry.getInstance().findContainers(None, name = unique_name):
|
||||||
i = i + 1
|
i += 1
|
||||||
unique_name = "%s #%d" % (name, i)
|
unique_name = "%s #%d" % (name, i)
|
||||||
|
|
||||||
return unique_name
|
return unique_name
|
||||||
@ -254,6 +255,27 @@ class MachineManagerModel(QObject):
|
|||||||
return True
|
return True
|
||||||
return containers[0].getMetaDataEntry("read_only", False) == "True"
|
return containers[0].getMetaDataEntry("read_only", False) == "True"
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def convertUserContainerToQuality(self):
|
||||||
|
if not self._global_container_stack:
|
||||||
|
return
|
||||||
|
|
||||||
|
name = self._createUniqueStackName("Custom profile", "")
|
||||||
|
user_settings = self._global_container_stack.getTop()
|
||||||
|
new_quality_container = InstanceContainer("")
|
||||||
|
|
||||||
|
## Copy all values
|
||||||
|
new_quality_container.deserialize(user_settings.serialize())
|
||||||
|
|
||||||
|
## Change type / id / name
|
||||||
|
new_quality_container.setMetaDataEntry("type","quality")
|
||||||
|
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.setActiveQuality(name)
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveMaterial(self, material_id):
|
def setActiveMaterial(self, material_id):
|
||||||
@ -319,7 +341,7 @@ class MachineManagerModel(QObject):
|
|||||||
def renameMachine(self, machine_id, new_name):
|
def renameMachine(self, machine_id, new_name):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||||
if containers:
|
if containers:
|
||||||
new_name = self._uniqueMachineName(new_name, containers[0].getBottom().getName())
|
new_name = self._createUniqueStackName(new_name, containers[0].getBottom().getName())
|
||||||
containers[0].setName(new_name)
|
containers[0].setName(new_name)
|
||||||
self.globalContainerChanged.emit()
|
self.globalContainerChanged.emit()
|
||||||
|
|
||||||
|
@ -580,7 +580,7 @@ UM.MainWindow
|
|||||||
target: Cura.Actions.addProfile
|
target: Cura.Actions.addProfile
|
||||||
onTriggered:
|
onTriggered:
|
||||||
{
|
{
|
||||||
UM.MachineManager.createProfile();
|
Cura.MachineManager.convertUserContainerToQuality();
|
||||||
preferences.setPage(5);
|
preferences.setPage(5);
|
||||||
preferences.show();
|
preferences.show();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user