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",
|
||||
MachineManagerModel.createMachineManagerModel)
|
||||
qmlRegisterSingletonType(ExtruderManager.ExtruderManager, "Cura", 1, 0, "ExtruderManager",
|
||||
ExtruderManager.createExtruderManager)
|
||||
|
||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||
@ -386,6 +384,9 @@ class CuraApplication(QtApplication):
|
||||
def getPrintInformation(self):
|
||||
return self._print_information
|
||||
|
||||
## Registers objects for the QML engine to use.
|
||||
#
|
||||
# \param engine The QML engine.
|
||||
def registerObjects(self, engine):
|
||||
engine.rootContext().setContextProperty("Printer", self)
|
||||
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")
|
||||
|
||||
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())
|
||||
|
||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||
if type_name in ("Cura", "Actions"):
|
||||
|
@ -61,6 +61,38 @@ class ExtruderManager(QObject):
|
||||
self._active_extruder_index = index
|
||||
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.
|
||||
def _repopulate(self):
|
||||
self._extruder_trains = { }
|
||||
@ -78,13 +110,14 @@ class ExtruderManager(QObject):
|
||||
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train.getId()
|
||||
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()
|
||||
|
||||
#Create a container stack for this extruder.
|
||||
name = self._uniqueName(extruder_id)
|
||||
container_stack = UM.Settings.ContainerStack(name)
|
||||
container_stack = UM.Settings.ContainerStack(extruder_train_id)
|
||||
container_stack.addMetaDataEntry("type", "extruder_train")
|
||||
container_stack.addMetaDataEntry("machine", machine_definition.getId())
|
||||
container_stack.addMetaDataEntry("position", position)
|
||||
container_stack.addContainer(extruder_definition)
|
||||
|
||||
"""
|
||||
@ -133,7 +166,7 @@ class ExtruderManager(QObject):
|
||||
"""
|
||||
|
||||
#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.setDefinition(machine_definition)
|
||||
container_stack.addContainer(user_profile)
|
||||
@ -143,11 +176,18 @@ class ExtruderManager(QObject):
|
||||
|
||||
container_registry.addContainer(container_stack)
|
||||
|
||||
|
||||
def _uniqueName(self, extruder):
|
||||
## Creates a new unique name for a container that doesn't exist yet.
|
||||
#
|
||||
# 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()
|
||||
|
||||
name = extruder.strip()
|
||||
name = original.strip()
|
||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||
if num_check: # There is a number in the name.
|
||||
name = num_check.group(1) # Filter out the number.
|
||||
@ -156,12 +196,7 @@ class ExtruderManager(QObject):
|
||||
unique_name = name
|
||||
|
||||
i = 1
|
||||
while container_registry.findContainers(id=unique_name) or container_registry.findContainers(
|
||||
name=unique_name): # A container already has this name.
|
||||
while container_registry.findContainers(id = unique_name) or container_registry.findContainers(name = unique_name): # A container already has this name.
|
||||
i += 1 # Try next numbering.
|
||||
unique_name = "%s #%d" % (name, i) # Fill name like this: "Extruder #2".
|
||||
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(current_settings_instance_container)
|
||||
|
||||
for position, extruder_train_id in definition.getMetaDataEntry("machine_extruder_trains", default = {}).items():
|
||||
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)
|
||||
ExtruderManager.ExtruderManager.getInstance().addMachineExtruders(definition)
|
||||
|
||||
Application.getInstance().setGlobalContainerStack(new_global_stack)
|
||||
|
||||
@ -304,6 +297,7 @@ class MachineManagerModel(QObject):
|
||||
## Copy all values
|
||||
new_container.deserialize(containers[0].serialize())
|
||||
|
||||
new_container.setMetaDataEntry("read_only", False)
|
||||
new_container.setName(new_name)
|
||||
new_container._id = new_name
|
||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
|
||||
@ -312,6 +306,15 @@ class MachineManagerModel(QObject):
|
||||
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)
|
||||
def removeQualityContainer(self, container_id):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||
|
@ -91,20 +91,14 @@ UM.ManagementPage
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
Row {
|
||||
id: currentSettingsActions
|
||||
visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.top: profileName.bottom
|
||||
anchors.topMargin: UM.Theme.getSize("default_margin").height
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
Column
|
||||
{
|
||||
spacing: UM.Theme.getSize("default_margin").height
|
||||
|
||||
Row
|
||||
{
|
||||
visible: base.currentItem.id == -1 || currentItem.id == Cura.MachineManager.activeQualityId
|
||||
Button
|
||||
{
|
||||
text: {
|
||||
@ -124,37 +118,36 @@ UM.ManagementPage
|
||||
}
|
||||
}
|
||||
|
||||
Grid
|
||||
{
|
||||
id: containerGrid
|
||||
columns: 2
|
||||
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.bottom: parent.bottom
|
||||
|
||||
ListView {
|
||||
model: base.currentItem ? base.currentItem.settings: null
|
||||
delegate: Row {
|
||||
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")
|
||||
text: model.label
|
||||
elide: Text.ElideMiddle
|
||||
width: scrollView.width / 100 * 40
|
||||
}
|
||||
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")
|
||||
text: model.value.toString()
|
||||
}
|
||||
|
||||
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(); }
|
||||
text: model.unit
|
||||
}
|
||||
}
|
||||
section.property: "category"
|
||||
section.criteria: ViewSection.FullString
|
||||
section.delegate: Label {
|
||||
text: section
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,19 +177,19 @@ UM.ManagementPage
|
||||
|
||||
UM.ConfirmRemoveDialog
|
||||
{
|
||||
id: confirmDialog;
|
||||
object: base.currentItem != null ? base.currentItem.name : "";
|
||||
onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id);
|
||||
id: confirmDialog
|
||||
object: base.currentItem != null ? base.currentItem.name : ""
|
||||
onYes: Cura.MachineManager.removeQualityContainer(base.currentItem.id)
|
||||
}
|
||||
UM.RenameDialog
|
||||
{
|
||||
id: renameDialog;
|
||||
object: base.currentItem != null ? base.currentItem.name : "";
|
||||
property bool removeWhenRejected: false;
|
||||
onAccepted: base.model.rename(base.currentItem.id, newName.trim());
|
||||
object: base.currentItem != null ? base.currentItem.name : ""
|
||||
property bool removeWhenRejected: false
|
||||
onAccepted: Cura.MachineManager.renameQualityContainer(base.currentItem.id, newName)
|
||||
onRejected: {
|
||||
if(removeWhenRejected) {
|
||||
base.model.removeProfile(base.currentItem.name)
|
||||
Cura.MachineManager.removeQualityContainer(base.currentItem.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ ScrollView
|
||||
{
|
||||
id: contents
|
||||
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 {
|
||||
id: definitionsModel;
|
||||
@ -80,7 +80,7 @@ ScrollView
|
||||
{
|
||||
id: provider
|
||||
|
||||
containerStackId: Cura.ExtruderManager.activeExtruderStackId ? Cura.ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
||||
containerStackId: ExtruderManager.activeExtruderStackId ? ExtruderManager.activeExtruderStackId : Cura.MachineManager.activeMachineId
|
||||
key: model.key
|
||||
watchedProperties: [ "value", "enabled", "state", "validationState" ]
|
||||
storeIndex: 0
|
||||
|
@ -111,7 +111,7 @@ Item
|
||||
onClicked:
|
||||
{
|
||||
base.currentExtruderIndex = index
|
||||
Cura.ExtruderManager.setActiveExtruderIndex(index)
|
||||
ExtruderManager.setActiveExtruderIndex(index)
|
||||
}
|
||||
|
||||
style: ButtonStyle {
|
||||
|
Loading…
x
Reference in New Issue
Block a user