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
|
## 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.
|
# \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):
|
def duplicateMaterial(self, material_node, new_base_id = None, new_metadata = None):
|
||||||
root_material_id = material_node.metadata["base_file"]
|
root_material_id = material_node.metadata["base_file"]
|
||||||
|
|
||||||
|
@ -509,6 +509,7 @@ class ContainerManager(QObject):
|
||||||
for container_to_add in new_containers:
|
for container_to_add in new_containers:
|
||||||
container_to_add.setDirty(True)
|
container_to_add.setDirty(True)
|
||||||
ContainerRegistry.getInstance().addContainer(container_to_add)
|
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
|
## 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 hasCurrentItem: materialListView.currentItem != null
|
||||||
|
|
||||||
property var currentItem: {
|
property var currentItem: { // is soon to be overwritten
|
||||||
var current_index = materialListView.currentIndex;
|
var current_index = materialListView.currentIndex;
|
||||||
return materialsModel.getItem(current_index);
|
return materialsModel.getItem(current_index);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ Item
|
||||||
onClicked: {
|
onClicked: {
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.createMaterial();
|
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.createMaterial();
|
||||||
|
base.toActivateNewMaterial = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +89,8 @@ Item
|
||||||
enabled: base.hasCurrentItem
|
enabled: base.hasCurrentItem
|
||||||
onClicked: {
|
onClicked: {
|
||||||
forceActiveFocus();
|
forceActiveFocus();
|
||||||
base.newRootMaterialIdToSwitchTo = base.currentItem.root_material_id;
|
base.newRootMaterialIdToSwitchTo = Cura.ContainerManager.duplicateMaterial(base.currentItem.container_node);
|
||||||
Cura.ContainerManager.duplicateMaterial(base.currentItem.container_node);
|
base.toActivateNewMaterial = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,27 +129,43 @@ Item
|
||||||
}
|
}
|
||||||
|
|
||||||
property string newRootMaterialIdToSwitchTo: ""
|
property string newRootMaterialIdToSwitchTo: ""
|
||||||
|
property bool toActivateNewMaterial: false
|
||||||
|
|
||||||
// This connection makes sure that we will switch to the new
|
// This connection makes sure that we will switch to the new
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: materialsModel
|
target: materialsModel
|
||||||
onItemsChanged: {
|
onItemsChanged: {
|
||||||
var currentItemName = base.currentItem == null ? "" : base.currentItem.name;
|
var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id;
|
||||||
var position = Cura.ExtruderManager.activeExtruderIndex;
|
var position = Cura.ExtruderManager.activeExtruderIndex;
|
||||||
|
|
||||||
if (base.newRootMaterialIdToSwitchTo != "") {
|
// try to pick the currently selected item; it may have been moved
|
||||||
for (var idx = 0; idx < materialsModel.rowCount(); ++idx) {
|
if (base.newRootMaterialIdToSwitchTo == "") {
|
||||||
var item = materialsModel.getItem(idx);
|
base.newRootMaterialIdToSwitchTo = currentItemId;
|
||||||
if (item.root_material_id == base.newRootMaterialIdToSwitchTo) {
|
}
|
||||||
// Switch to the newly created profile if needed
|
|
||||||
materialListView.currentIndex = idx;
|
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);
|
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:
|
onYes:
|
||||||
{
|
{
|
||||||
Cura.ContainerManager.removeMaterial(base.currentItem.container_node);
|
Cura.ContainerManager.removeMaterial(base.currentItem.container_node);
|
||||||
// reset current item to the first if available
|
|
||||||
materialListView.currentIndex = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,15 +389,20 @@ Item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onCurrentIndexChanged:
|
function activateDetailsWithIndex(index) {
|
||||||
{
|
var model = materialsModel.getItem(index);
|
||||||
forceActiveFocus(); // causes the changed fields to be saved
|
base.currentItem = model;
|
||||||
var model = materialsModel.getItem(currentIndex);
|
|
||||||
materialDetailsView.containerId = model.container_id;
|
materialDetailsView.containerId = model.container_id;
|
||||||
materialDetailsView.currentMaterialNode = model.container_node;
|
materialDetailsView.currentMaterialNode = model.container_node;
|
||||||
|
|
||||||
detailsPanel.updateMaterialPropertiesObject();
|
detailsPanel.updateMaterialPropertiesObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCurrentIndexChanged:
|
||||||
|
{
|
||||||
|
forceActiveFocus(); // causes the changed fields to be saved
|
||||||
|
activateDetailsWithIndex(currentIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue