mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 02:07:51 -06:00
CURA-4606 CURA-5003 activate duplicated material and always switch to correct material after some material change
This commit is contained in:
parent
2df9802ba5
commit
c23827cfa1
2 changed files with 40 additions and 19 deletions
|
@ -458,7 +458,7 @@ class ContainerManager(QObject):
|
|||
## Create a duplicate of a material, which has the same GUID and base_file metadata
|
||||
#
|
||||
# \return \type{str} the id of the newly created container.
|
||||
@pyqtSlot("QVariant")
|
||||
@pyqtSlot("QVariant", result = str)
|
||||
def duplicateMaterial(self, material_node, new_base_id = None, new_metadata = None):
|
||||
root_material_id = material_node.metadata["base_file"]
|
||||
|
||||
|
@ -509,6 +509,7 @@ class ContainerManager(QObject):
|
|||
for container_to_add in new_containers:
|
||||
container_to_add.setDirty(True)
|
||||
ContainerRegistry.getInstance().addContainer(container_to_add)
|
||||
return new_base_id
|
||||
|
||||
## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
|
||||
#
|
||||
|
|
|
@ -37,7 +37,7 @@ Item
|
|||
|
||||
property var hasCurrentItem: materialListView.currentItem != null
|
||||
|
||||
property var currentItem: {
|
||||
property var currentItem: { // is soon to be overwritten
|
||||
var current_index = materialListView.currentIndex;
|
||||
return materialsModel.getItem(current_index);
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ Item
|
|||
onClicked: {
|
||||
forceActiveFocus();
|
||||
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.createMaterial();
|
||||
base.toActivateNewMaterial = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +89,8 @@ Item
|
|||
enabled: base.hasCurrentItem
|
||||
onClicked: {
|
||||
forceActiveFocus();
|
||||
base.newRootMaterialIdToSwitchTo = base.currentItem.root_material_id;
|
||||
Cura.ContainerManager.duplicateMaterial(base.currentItem.container_node);
|
||||
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.duplicateMaterial(base.currentItem.container_node);
|
||||
base.toActivateNewMaterial = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,27 +129,43 @@ Item
|
|||
}
|
||||
|
||||
property string newRootMaterialIdToSwitchTo: ""
|
||||
property bool toActivateNewMaterial: false
|
||||
|
||||
// This connection makes sure that we will switch to the new
|
||||
Connections
|
||||
{
|
||||
target: materialsModel
|
||||
onItemsChanged: {
|
||||
var currentItemName = base.currentItem == null ? "" : base.currentItem.name;
|
||||
var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id;
|
||||
var position = Cura.ExtruderManager.activeExtruderIndex;
|
||||
|
||||
if (base.newRootMaterialIdToSwitchTo != "") {
|
||||
for (var idx = 0; idx < materialsModel.rowCount(); ++idx) {
|
||||
var item = materialsModel.getItem(idx);
|
||||
if (item.root_material_id == base.newRootMaterialIdToSwitchTo) {
|
||||
// Switch to the newly created profile if needed
|
||||
materialListView.currentIndex = idx;
|
||||
// try to pick the currently selected item; it may have been moved
|
||||
if (base.newRootMaterialIdToSwitchTo == "") {
|
||||
base.newRootMaterialIdToSwitchTo = currentItemId;
|
||||
}
|
||||
|
||||
for (var idx = 0; idx < materialsModel.rowCount(); ++idx) {
|
||||
var item = materialsModel.getItem(idx);
|
||||
if (item.root_material_id == base.newRootMaterialIdToSwitchTo) {
|
||||
// Switch to the newly created profile if needed
|
||||
materialListView.currentIndex = idx;
|
||||
materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
||||
if (base.toActivateNewMaterial) {
|
||||
Cura.MachineManager.setMaterial(position, item.container_node);
|
||||
base.newRootMaterialIdToSwitchTo = "";
|
||||
break;
|
||||
}
|
||||
base.newRootMaterialIdToSwitchTo = "";
|
||||
base.toActivateNewMaterial = false;
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
materialListView.currentIndex = 0;
|
||||
materialListView.activateDetailsWithIndex(materialListView.currentIndex);
|
||||
if (base.toActivateNewMaterial) {
|
||||
Cura.MachineManager.setMaterial(position, materialsModel.getItem(0).container_node);
|
||||
}
|
||||
base.newRootMaterialIdToSwitchTo = "";
|
||||
base.toActivateNewMaterial = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,8 +182,6 @@ Item
|
|||
onYes:
|
||||
{
|
||||
Cura.ContainerManager.removeMaterial(base.currentItem.container_node);
|
||||
// reset current item to the first if available
|
||||
materialListView.currentIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,15 +389,20 @@ Item
|
|||
}
|
||||
}
|
||||
|
||||
onCurrentIndexChanged:
|
||||
{
|
||||
forceActiveFocus(); // causes the changed fields to be saved
|
||||
var model = materialsModel.getItem(currentIndex);
|
||||
function activateDetailsWithIndex(index) {
|
||||
var model = materialsModel.getItem(index);
|
||||
base.currentItem = model;
|
||||
materialDetailsView.containerId = model.container_id;
|
||||
materialDetailsView.currentMaterialNode = model.container_node;
|
||||
|
||||
detailsPanel.updateMaterialPropertiesObject();
|
||||
}
|
||||
|
||||
onCurrentIndexChanged:
|
||||
{
|
||||
forceActiveFocus(); // causes the changed fields to be saved
|
||||
activateDetailsWithIndex(currentIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue