mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -06:00
Simplify creating, duplicating materials in preferences, extract logic to python, code-style fixes
This commit is contained in:
parent
f9286d4bd5
commit
3de4940d69
2 changed files with 58 additions and 62 deletions
|
@ -816,6 +816,22 @@ class ContainerManager(QObject):
|
||||||
ContainerRegistry.getInstance().addContainer(container_to_add)
|
ContainerRegistry.getInstance().addContainer(container_to_add)
|
||||||
return self._getMaterialContainerIdForActiveMachine(clone_of_original)
|
return self._getMaterialContainerIdForActiveMachine(clone_of_original)
|
||||||
|
|
||||||
|
## Create a duplicate of a material or it's original entry
|
||||||
|
#
|
||||||
|
# \return \type{str} the id of the newly created container.
|
||||||
|
@pyqtSlot(str, result = str)
|
||||||
|
def duplicateOriginalMaterial(self, material_id):
|
||||||
|
|
||||||
|
# check if the given material has a base file (i.e. was shipped by default)
|
||||||
|
base_file = self.getContainerMetaDataEntry(material_id, "base_file")
|
||||||
|
|
||||||
|
if base_file == "":
|
||||||
|
# there is no base file, so duplicate by ID
|
||||||
|
return self.duplicateMaterial(material_id)
|
||||||
|
else:
|
||||||
|
# there is a base file, so duplicate the original material
|
||||||
|
return self.duplicateMaterial(base_file)
|
||||||
|
|
||||||
## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
|
## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
|
||||||
#
|
#
|
||||||
# \return \type{str} the id of the newly created container.
|
# \return \type{str} the id of the newly created container.
|
||||||
|
|
|
@ -132,93 +132,73 @@ UM.ManagementPage
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons: [
|
buttons: [
|
||||||
Button
|
|
||||||
{
|
// Activate button
|
||||||
text: catalog.i18nc("@action:button", "Activate");
|
Button {
|
||||||
|
text: catalog.i18nc("@action:button", "Activate")
|
||||||
iconName: "list-activate";
|
iconName: "list-activate";
|
||||||
enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId && Cura.MachineManager.hasMaterials
|
enabled: base.currentItem != null && base.currentItem.id != Cura.MachineManager.activeMaterialId && Cura.MachineManager.hasMaterials
|
||||||
onClicked:
|
onClicked: {
|
||||||
{
|
forceActiveFocus()
|
||||||
forceActiveFocus();
|
|
||||||
Cura.MachineManager.setActiveMaterial(base.currentItem.id)
|
Cura.MachineManager.setActiveMaterial(base.currentItem.id)
|
||||||
currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
|
currentItem = base.model.getItem(base.objectList.currentIndex) // Refresh the current item.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Button
|
|
||||||
{
|
// Create button
|
||||||
|
Button {
|
||||||
text: catalog.i18nc("@action:button", "Create")
|
text: catalog.i18nc("@action:button", "Create")
|
||||||
iconName: "list-add"
|
iconName: "list-add"
|
||||||
onClicked:
|
onClicked: {
|
||||||
{
|
forceActiveFocus()
|
||||||
forceActiveFocus();
|
Cura.ContainerManager.createMaterial()
|
||||||
var material_id = Cura.ContainerManager.createMaterial()
|
|
||||||
if(material_id == "")
|
|
||||||
{
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if(Cura.MachineManager.hasMaterials)
|
|
||||||
{
|
|
||||||
Cura.MachineManager.setActiveMaterial(material_id)
|
|
||||||
}
|
|
||||||
base.objectList.currentIndex = base.getIndexById(material_id);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Button
|
|
||||||
{
|
// Duplicate button
|
||||||
|
Button {
|
||||||
text: catalog.i18nc("@action:button", "Duplicate");
|
text: catalog.i18nc("@action:button", "Duplicate");
|
||||||
iconName: "list-add";
|
iconName: "list-add";
|
||||||
enabled: base.currentItem != null
|
enabled: base.currentItem != null
|
||||||
onClicked:
|
onClicked: {
|
||||||
{
|
forceActiveFocus()
|
||||||
forceActiveFocus();
|
Cura.ContainerManager.duplicateOriginalMaterial(base.currentItem.id)
|
||||||
var base_file = Cura.ContainerManager.getContainerMetaDataEntry(base.currentItem.id, "base_file")
|
|
||||||
// We need to copy the base container instead of the specific variant.
|
|
||||||
var material_id = base_file == "" ? Cura.ContainerManager.duplicateMaterial(base.currentItem.id): Cura.ContainerManager.duplicateMaterial(base_file)
|
|
||||||
if(material_id == "")
|
|
||||||
{
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if(Cura.MachineManager.hasMaterials)
|
|
||||||
{
|
|
||||||
Cura.MachineManager.setActiveMaterial(material_id)
|
|
||||||
}
|
|
||||||
// TODO: this doesn't work because the source is a bit delayed
|
|
||||||
base.objectList.currentIndex = base.getIndexById(material_id);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Button
|
|
||||||
{
|
// Remove button
|
||||||
text: catalog.i18nc("@action:button", "Remove");
|
Button {
|
||||||
iconName: "list-remove";
|
text: catalog.i18nc("@action:button", "Remove")
|
||||||
|
iconName: "list-remove"
|
||||||
enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
|
enabled: base.currentItem != null && !base.currentItem.readOnly && !Cura.ContainerManager.isContainerUsed(base.currentItem.id)
|
||||||
onClicked:
|
onClicked: {
|
||||||
{
|
forceActiveFocus()
|
||||||
forceActiveFocus();
|
confirmDialog.open()
|
||||||
confirmDialog.open();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Button
|
|
||||||
{
|
// Import button
|
||||||
text: catalog.i18nc("@action:button", "Import");
|
Button {
|
||||||
iconName: "document-import";
|
text: catalog.i18nc("@action:button", "Import")
|
||||||
onClicked:
|
iconName: "document-import"
|
||||||
{
|
onClicked: {
|
||||||
forceActiveFocus();
|
forceActiveFocus()
|
||||||
importDialog.open();
|
importDialog.open()
|
||||||
}
|
}
|
||||||
visible: true;
|
visible: true
|
||||||
},
|
},
|
||||||
Button
|
|
||||||
{
|
// Export button
|
||||||
|
Button {
|
||||||
text: catalog.i18nc("@action:button", "Export")
|
text: catalog.i18nc("@action:button", "Export")
|
||||||
iconName: "document-export"
|
iconName: "document-export"
|
||||||
onClicked:
|
onClicked: {
|
||||||
{
|
forceActiveFocus()
|
||||||
forceActiveFocus();
|
exportDialog.open()
|
||||||
exportDialog.open();
|
|
||||||
}
|
}
|
||||||
enabled: currentItem != null
|
enabled: currentItem != null
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue