mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Merge branch 'master' of github.com:Ultimaker/Cura
This commit is contained in:
commit
51ea6779df
@ -353,8 +353,6 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
qmlRegisterSingletonType(MachineManagerModel.MachineManagerModel, "Cura", 1, 0, "MachineManager",
|
qmlRegisterSingletonType(MachineManagerModel.MachineManagerModel, "Cura", 1, 0, "MachineManager",
|
||||||
MachineManagerModel.createMachineManagerModel)
|
MachineManagerModel.createMachineManagerModel)
|
||||||
qmlRegisterSingletonType(ExtruderManager.ExtruderManager, "Cura", 1, 0, "ExtruderManager",
|
|
||||||
ExtruderManager.createExtruderManager)
|
|
||||||
|
|
||||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||||
@ -386,6 +384,9 @@ class CuraApplication(QtApplication):
|
|||||||
def getPrintInformation(self):
|
def getPrintInformation(self):
|
||||||
return self._print_information
|
return self._print_information
|
||||||
|
|
||||||
|
## Registers objects for the QML engine to use.
|
||||||
|
#
|
||||||
|
# \param engine The QML engine.
|
||||||
def registerObjects(self, engine):
|
def registerObjects(self, engine):
|
||||||
engine.rootContext().setContextProperty("Printer", self)
|
engine.rootContext().setContextProperty("Printer", self)
|
||||||
self._print_information = PrintInformation.PrintInformation()
|
self._print_information = PrintInformation.PrintInformation()
|
||||||
@ -399,6 +400,8 @@ class CuraApplication(QtApplication):
|
|||||||
|
|
||||||
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions")
|
||||||
|
|
||||||
|
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())
|
||||||
|
|
||||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||||
if type_name in ("Cura", "Actions"):
|
if type_name in ("Cura", "Actions"):
|
||||||
|
@ -61,6 +61,38 @@ class ExtruderManager(QObject):
|
|||||||
self._active_extruder_index = index
|
self._active_extruder_index = index
|
||||||
self.activeExtruderChanged.emit()
|
self.activeExtruderChanged.emit()
|
||||||
|
|
||||||
|
## Adds all extruders of a specific machine definition to the extruder
|
||||||
|
# manager.
|
||||||
|
#
|
||||||
|
# \param machine_definition The machine to add the extruders for.
|
||||||
|
def addMachineExtruders(self, machine_definition):
|
||||||
|
machine_id = machine_definition.getId()
|
||||||
|
if not self._extruder_trains[machine_id]:
|
||||||
|
self._extruder_trains[machine_id] = { }
|
||||||
|
|
||||||
|
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||||
|
if not container_registry: #Then we shouldn't have any machine definition either. In any case, there are no extruder trains then so bye bye.
|
||||||
|
return
|
||||||
|
|
||||||
|
#Add the extruder trains that don't exist yet.
|
||||||
|
for position, extruder_definition_id in machine_definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
|
||||||
|
extruder_definition = container_registry.findDefinitionContainers(machine = machine_definition.getId())
|
||||||
|
if extruder_definition:
|
||||||
|
extruder_definition = extruder_definition[0]
|
||||||
|
else:
|
||||||
|
Logger.log("w", "Machine %s references an extruder with ID %s, which doesn't exist.", machine_definition.getName(), extruder_definition_id)
|
||||||
|
continue
|
||||||
|
name = self._uniqueName(extruder_definition_id) #Make a name based on the ID of the definition.
|
||||||
|
if not container_registry.findContainerStacks(id = name): #Doesn't exist yet.
|
||||||
|
self.createExtruderTrain(extruder_definition, machine_definition, name, position)
|
||||||
|
|
||||||
|
#Gets the extruder trains that we just created as well as any that still existed.
|
||||||
|
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = machine_definition.getId())
|
||||||
|
for extruder_train in extruder_trains:
|
||||||
|
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train.getId()
|
||||||
|
if extruder_trains:
|
||||||
|
self.extrudersChanged.emit()
|
||||||
|
|
||||||
## (Re)populates the collections of extruders by machine.
|
## (Re)populates the collections of extruders by machine.
|
||||||
def _repopulate(self):
|
def _repopulate(self):
|
||||||
self._extruder_trains = { }
|
self._extruder_trains = { }
|
||||||
@ -78,13 +110,14 @@ class ExtruderManager(QObject):
|
|||||||
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train.getId()
|
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train.getId()
|
||||||
self.extrudersChanged.emit()
|
self.extrudersChanged.emit()
|
||||||
|
|
||||||
def createExtruderTrain(self, extruder_definition, machine_definition, extruder_id):
|
def createExtruderTrain(self, extruder_definition, machine_definition, extruder_train_id, position):
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||||
|
|
||||||
#Create a container stack for this extruder.
|
#Create a container stack for this extruder.
|
||||||
name = self._uniqueName(extruder_id)
|
container_stack = UM.Settings.ContainerStack(extruder_train_id)
|
||||||
container_stack = UM.Settings.ContainerStack(name)
|
|
||||||
container_stack.addMetaDataEntry("type", "extruder_train")
|
container_stack.addMetaDataEntry("type", "extruder_train")
|
||||||
|
container_stack.addMetaDataEntry("machine", machine_definition.getId())
|
||||||
|
container_stack.addMetaDataEntry("position", position)
|
||||||
container_stack.addContainer(extruder_definition)
|
container_stack.addContainer(extruder_definition)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -133,7 +166,7 @@ class ExtruderManager(QObject):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
#Add an empty user profile.
|
#Add an empty user profile.
|
||||||
user_profile = UM.Settings.InstanceContainer(name + "_current_settings")
|
user_profile = UM.Settings.InstanceContainer(extruder_train_id + "_current_settings")
|
||||||
user_profile.addMetaDataEntry("type", "user")
|
user_profile.addMetaDataEntry("type", "user")
|
||||||
user_profile.setDefinition(machine_definition)
|
user_profile.setDefinition(machine_definition)
|
||||||
container_stack.addContainer(user_profile)
|
container_stack.addContainer(user_profile)
|
||||||
@ -143,11 +176,18 @@ class ExtruderManager(QObject):
|
|||||||
|
|
||||||
container_registry.addContainer(container_stack)
|
container_registry.addContainer(container_stack)
|
||||||
|
|
||||||
|
## Creates a new unique name for a container that doesn't exist yet.
|
||||||
def _uniqueName(self, extruder):
|
#
|
||||||
|
# It tries if the original name you provide exists, and if it doesn't
|
||||||
|
# it'll add a " #1" or " #2" after the name to make it unique.
|
||||||
|
#
|
||||||
|
# \param original The original name that may not be unique.
|
||||||
|
# \return A unique name that looks a lot like the original but may have
|
||||||
|
# a number behind it to make it unique.
|
||||||
|
def _uniqueName(self, original):
|
||||||
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
container_registry = UM.Settings.ContainerRegistry.getInstance()
|
||||||
|
|
||||||
name = extruder.strip()
|
name = original.strip()
|
||||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||||
if num_check: # There is a number in the name.
|
if num_check: # There is a number in the name.
|
||||||
name = num_check.group(1) # Filter out the number.
|
name = num_check.group(1) # Filter out the number.
|
||||||
@ -156,12 +196,7 @@ class ExtruderManager(QObject):
|
|||||||
unique_name = name
|
unique_name = name
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
while container_registry.findContainers(id=unique_name) or container_registry.findContainers(
|
while container_registry.findContainers(id = unique_name) or container_registry.findContainers(name = unique_name): # A container already has this name.
|
||||||
name=unique_name): # A container already has this name.
|
|
||||||
i += 1 # Try next numbering.
|
i += 1 # Try next numbering.
|
||||||
unique_name = "%s #%d" % (name, i) # Fill name like this: "Extruder #2".
|
unique_name = "%s #%d" % (name, i) # Fill name like this: "Extruder #2".
|
||||||
return unique_name
|
return unique_name
|
||||||
|
|
||||||
|
|
||||||
def createExtruderManager(engine, script_engine):
|
|
||||||
return ExtruderManager()
|
|
@ -135,14 +135,7 @@ class MachineManagerModel(QObject):
|
|||||||
new_global_stack.addContainer(quality_instance_container)
|
new_global_stack.addContainer(quality_instance_container)
|
||||||
new_global_stack.addContainer(current_settings_instance_container)
|
new_global_stack.addContainer(current_settings_instance_container)
|
||||||
|
|
||||||
for position, extruder_train_id in definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
|
ExtruderManager.ExtruderManager.getInstance().addMachineExtruders(definition)
|
||||||
extruder_definition = UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = extruder_train_id)
|
|
||||||
if extruder_definition:
|
|
||||||
extruder_definition = extruder_definition[0]
|
|
||||||
else:
|
|
||||||
Logger.log("w", "Machine %s references an extruder with ID %s, which doesn't exist.", definition.getName(), extruder_train_id)
|
|
||||||
continue
|
|
||||||
ExtruderManager.ExtruderManager.getInstance().createExtruderTrain(extruder_definition, definition, extruder_train_id)
|
|
||||||
|
|
||||||
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
||||||
|
|
||||||
@ -304,6 +297,7 @@ class MachineManagerModel(QObject):
|
|||||||
## Copy all values
|
## Copy all values
|
||||||
new_container.deserialize(containers[0].serialize())
|
new_container.deserialize(containers[0].serialize())
|
||||||
|
|
||||||
|
new_container.setMetaDataEntry("read_only", False)
|
||||||
new_container.setName(new_name)
|
new_container.setName(new_name)
|
||||||
new_container._id = new_name
|
new_container._id = new_name
|
||||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
|
UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
|
||||||
@ -312,6 +306,15 @@ class MachineManagerModel(QObject):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
@pyqtSlot(str, str)
|
||||||
|
def renameQualityContainer(self, container_id, new_name):
|
||||||
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id, type = "quality")
|
||||||
|
if containers:
|
||||||
|
new_name = self._createUniqueName("machine", new_name, catalog.i18nc("@label", "Custom profile"))
|
||||||
|
containers[0].setName(new_name)
|
||||||
|
UM.Settings.ContainerRegistry.getInstance().containerChanged.emit(containers[0])
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def removeQualityContainer(self, container_id):
|
def removeQualityContainer(self, container_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||||
|
@ -91,70 +91,63 @@ UM.ManagementPage
|
|||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
Row {
|
||||||
|
id: currentSettingsActions
|
||||||
|
visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
|
||||||
|
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.top: profileName.bottom
|
anchors.top: profileName.bottom
|
||||||
anchors.topMargin: UM.Theme.getSize("default_margin").height
|
anchors.topMargin: UM.Theme.getSize("default_margin").height
|
||||||
|
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
var profileName = Cura.MachineManager.activeQualityName;
|
||||||
|
profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
|
||||||
|
return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
|
||||||
|
}
|
||||||
|
enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
|
||||||
|
onClicked: Cura.MachineManager.updateUserContainerToQuality()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button
|
||||||
|
{
|
||||||
|
text: catalog.i18nc("@action:button", "Discard changes");
|
||||||
|
enabled: Cura.MachineManager.hasUserSettings
|
||||||
|
onClicked: Cura.MachineManager.clearUserSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollView {
|
||||||
|
id: scrollView
|
||||||
|
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.top: currentSettingsActions.visible ? currentSettingsActions.bottom : profileName.bottom
|
||||||
|
anchors.topMargin: UM.Theme.getSize("default_margin").height
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
Column
|
ListView {
|
||||||
{
|
model: base.currentItem ? base.currentItem.settings: null
|
||||||
spacing: UM.Theme.getSize("default_margin").height
|
delegate: Row {
|
||||||
|
spacing: UM.Theme.getSize("default_margin").width
|
||||||
Row
|
Label {
|
||||||
{
|
text: model.label
|
||||||
visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
|
elide: Text.ElideMiddle
|
||||||
Button
|
width: scrollView.width / 100 * 40
|
||||||
{
|
|
||||||
text: {
|
|
||||||
var profileName = Cura.MachineManager.activeQualityName;
|
|
||||||
profileName = (profileName.length > 20) ? profileName.substring(0, 20) + '...' : profileName;
|
|
||||||
return catalog.i18nc("@action:button", "Update \"%1\"".arg(profileName));
|
|
||||||
}
|
|
||||||
enabled: Cura.MachineManager.hasUserSettings && !Cura.MachineManager.isReadOnly(Cura.MachineManager.activeQualityId)
|
|
||||||
onClicked: Cura.MachineManager.updateUserContainerToQuality()
|
|
||||||
}
|
}
|
||||||
|
Label {
|
||||||
Button
|
text: model.value.toString()
|
||||||
{
|
}
|
||||||
text: catalog.i18nc("@action:button", "Discard changes");
|
Label {
|
||||||
enabled: Cura.MachineManager.hasUserSettings
|
text: model.unit
|
||||||
onClicked: Cura.MachineManager.clearUserSettings();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
section.property: "category"
|
||||||
Grid
|
section.criteria: ViewSection.FullString
|
||||||
{
|
section.delegate: Label {
|
||||||
id: containerGrid
|
text: section
|
||||||
columns: 2
|
font.bold: true
|
||||||
spacing: UM.Theme.getSize("default_margin").width
|
|
||||||
|
|
||||||
Label {
|
|
||||||
text: base.currentItem == null ? "" :
|
|
||||||
base.currentItem.id == -1 ? catalog.i18nc("@label", "Based on") : catalog.i18nc("@label", "Profile type")
|
|
||||||
}
|
|
||||||
Label {
|
|
||||||
text: base.currentItem == null ? "" :
|
|
||||||
base.currentItem.id == -1 ? Cura.MachineManager.activeQualityName:
|
|
||||||
base.currentItem.metadata.read_only ? catalog.i18nc("@label", "Protected profile") : catalog.i18nc("@label", "Custom profile")
|
|
||||||
}
|
|
||||||
|
|
||||||
Column {
|
|
||||||
Repeater {
|
|
||||||
model: base.currentItem ? base.currentItem.settings : null
|
|
||||||
Label {
|
|
||||||
text: modelData.label
|
|
||||||
elide: Text.ElideMiddle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Column {
|
|
||||||
Repeater {
|
|
||||||
model: base.currentItem ? base.currentItem.settings : null
|
|
||||||
Label { text: modelData.value.toString(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,19 +177,19 @@ UM.ManagementPage
|
|||||||
|
|
||||||
UM.ConfirmRemoveDialog
|
UM.ConfirmRemoveDialog
|
||||||
{
|
{
|
||||||
id: confirmDialog;
|
id: confirmDialog
|
||||||
object: base.currentItem != null ? base.currentItem.name : "";
|
object: base.currentItem != null ? base.currentItem.name : ""
|
||||||
onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id);
|
onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id)
|
||||||
}
|
}
|
||||||
UM.RenameDialog
|
UM.RenameDialog
|
||||||
{
|
{
|
||||||
id: renameDialog;
|
id: renameDialog;
|
||||||
object: base.currentItem != null ? base.currentItem.name : "";
|
object: base.currentItem != null ? base.currentItem.name : ""
|
||||||
property bool removeWhenRejected: false;
|
property bool removeWhenRejected: false
|
||||||
onAccepted: base.model.rename(base.currentItem.id, newName.trim());
|
onAccepted: Cura.MachineManager.renameQualityContainer(base.currentItem.id, newName)
|
||||||
onRejected: {
|
onRejected: {
|
||||||
if(removeWhenRejected) {
|
if(removeWhenRejected) {
|
||||||
base.model.removeProfile(base.currentItem.name)
|
Cura.MachineManager.removeQualityContainer(base.currentItem.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ ScrollView
|
|||||||
{
|
{
|
||||||
id: contents
|
id: contents
|
||||||
spacing: UM.Theme.getSize("default_lining").height;
|
spacing: UM.Theme.getSize("default_lining").height;
|
||||||
cacheBuffer: 1000000; // A huge to cache to effectively cache everything.
|
cacheBuffer: 1000000; // Set a large cache to effectively just cache every list item.
|
||||||
|
|
||||||
model: UM.SettingDefinitionsModel {
|
model: UM.SettingDefinitionsModel {
|
||||||
id: definitionsModel;
|
id: definitionsModel;
|
||||||
@ -80,7 +80,7 @@ ScrollView
|
|||||||
{
|
{
|
||||||
id: provider
|
id: provider
|
||||||
|
|
||||||
containerStackId: Cura.ExtruderManager.activeExtruderStackId ? Cura.ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
containerStackId: ExtruderManager.activeExtruderStackId ? ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
||||||
key: model.key
|
key: model.key
|
||||||
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
||||||
storeIndex: 0
|
storeIndex: 0
|
||||||
|
@ -111,7 +111,7 @@ Item
|
|||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
base.currentExtruderIndex = index
|
base.currentExtruderIndex = index
|
||||||
Cura.ExtruderManager.setActiveExtruderIndex(index)
|
ExtruderManager.setActiveExtruderIndex(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
style: ButtonStyle {
|
style: ButtonStyle {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user